Skip to content

Commit 7ce7330

Browse files
committed
login: with decorator
1 parent 7acd129 commit 7ce7330

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

content/tutorial/src/session-example.lisp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,25 @@
8383

8484
;; Views.
8585
(defun loggedin-p ()
86-
(hunchentoot:session-value 'user))
86+
(hunchentoot:session-value 'name))
8787

88-
;; GET
89-
(easy-routes:defroute admin-route ("/admin/" :method :get) ()
88+
(defun @auth (next)
89+
(log:info "checking session")
9090
(if (loggedin-p)
91-
(render *template-welcome*)
91+
(funcall next)
9292
(render *template-login*)))
9393

94+
;; GET
95+
(easy-routes:defroute admin-route ("/admin/" :method :get :decorators ((@auth))) ()
96+
(render *template-welcome* :name (hunchentoot:session-value 'name)))
97+
98+
;; using @auth is equivalent to doing a check in the route body:
99+
#|
100+
(if (loggedin-p)
101+
(render *template-welcome*)
102+
(render *template-login*))
103+
|#
104+
94105
;; POST
95106
(easy-routes:defroute admin-route/POST ("/admin/" :method :post) (name password)
96107
(cond

0 commit comments

Comments
 (0)