-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.lisp
69 lines (63 loc) · 3.02 KB
/
routes.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;;; routes.lisp
(in-package #:cu-openstack)
;;; Route definitions go here.
(hunchentoot:define-easy-handler
(redirect-to-login :uri "/") ()
"Redirects user from the base URL to the login page."
(hunchentoot:redirect "/login"))
(hunchentoot:define-easy-handler
(login-page :uri "/login") ((username :request-type :post)
(password :request-type :post))
"Login page that handles user authentication."
(case (hunchentoot:request-method*)
(:post
(if (models:verify-user-credential username password)
(progn
(hunchentoot:start-session)
(setf (hunchentoot:session-value :username) username)
(setf (hunchentoot:session-value :vm-name)
(format nil "~A-~A"
(getf (models:retrieve-user-info username) :role)
username))
(hunchentoot:redirect #U/users/{username}/vm-management))
(views:login)))
(:get
(views:login))))
(hunchentoot:define-easy-handler
(vm-management-page
:uri #'(lambda (request)
(uri-template:uri-template-bind
(#U/users/{username}/vm-management{query-fragment})
(hunchentoot:request-uri request)
(string= username (hunchentoot:session-value :username))))) ()
"Virtual machine management page."
(if (not (null hunchentoot:*session*))
(let ((username (hunchentoot:session-value :username))
(vm-name (hunchentoot:session-value :vm-name))
(user-info (models:retrieve-user-info
(hunchentoot:session-value :username)))
(config-info (models:get-config-info)))
(case (hunchentoot:request-method*)
(:get
(models:os-authenticate (first config-info)
(second config-info)
(third config-info))
(views:vm-management :username username
:vm-name vm-name
:vm-status (models:os-vm-instant-status vm-name)
:vm-image (getf user-info :image)
:vm-flavor (models:os-list-flavor-details (getf user-info :flavor))
:vm-floating-ip (models:os-get-vm-instant-floating-ip vm-name)
:page-uri (hunchentoot:request-uri*)
:realname (getf user-info :realname)))
(:post
(models:os-launch-vm-instant vm-name
(models:os-get-image-id (getf user-info :image))
(format nil "~A" (getf user-info :flavor)))
(hunchentoot:redirect #U/users/{username}/vm-management))))
(hunchentoot:redirect "/login")))
(hunchentoot:define-easy-handler
(clear-session-and-redirect :uri "/clear-and-logout") ()
"Clears session information and logout a user."
(hunchentoot:remove-session hunchentoot:*session*)
(hunchentoot:redirect "/login"))