aboutsummaryrefslogtreecommitdiffhomepage
path: root/site/session.lisp
blob: 7a2d105c7cf81d8fd61075671df33a3c64ebb11d (plain)
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
(in-package #:vampire)

(wknd:defendpoint create.session
  :post :to "login"
  :parameters
  (name string)
  (password string)
  :properties
  (user user)
  :authenticate (authenticate-user-login name password)
  :handle (wknd:endpoint-redirect 'home.html))

(defun authenticate-user-login (name password)
  (do>
    found-user :when= (user-with-name name)
    :when (equal (user-pwhash found-user)
		 (hash-string password (user-pwsalt found-user)))
    session := (db:with-transaction () (make-instance 'session :user found-user))
    (wknd:set-cookie +session-cookie+ :value (key session))))

(wknd:defendpoint destroy.session
  :using user-known
  :post :to "logout"
  :handle (do>
	    session := (object-with-key (wknd:get-cookie +session-cookie+))
	    (db:delete-object session)
	    (wknd:set-cookie +session-cookie+ :value nil)
	    (wknd:endpoint-redirect 'login.html)))