summaryrefslogtreecommitdiff
path: root/site/session.lisp
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2024-06-23 16:42:34 -0500
committerGrant Shangreaux <grant@unabridgedsoftware.com>2024-06-23 16:42:34 -0500
commit68d30b9c81c4e099e0111fe0bbb33715dd572e8c (patch)
treeefb4c43690494fddb47298f253a05092b2564160 /site/session.lisp
parentce470567c4421da7d073685cf845fdc4448aadc0 (diff)
[109] Add: logout action and some session endpoint refactor
Diffstat (limited to 'site/session.lisp')
-rw-r--r--site/session.lisp32
1 files changed, 32 insertions, 0 deletions
diff --git a/site/session.lisp b/site/session.lisp
new file mode 100644
index 0000000..342d6d0
--- /dev/null
+++ b/site/session.lisp
@@ -0,0 +1,32 @@
+(in-package #:vampire)
+
+(wknd:defendpoint session.create
+ :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)
+ (print found-user)
+ :when (equal (user-pwhash found-user)
+ (hash-string password (user-pwsalt found-user)))
+ session := (db:with-transaction () (make-instance 'session :user found-user))
+ (print session)
+ (wknd:set-cookie +session-cookie+ :value (key session))))
+
+(wknd:defendpoint session.destroy
+ :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)))
+
+