aboutsummaryrefslogtreecommitdiffhomepage
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
parentce470567c4421da7d073685cf845fdc4448aadc0 (diff)
[109] Add: logout action and some session endpoint refactor
-rw-r--r--seed.lisp13
-rw-r--r--site/home.lisp5
-rw-r--r--site/login.lisp20
-rw-r--r--site/session.lisp32
-rw-r--r--vampire.asd1
5 files changed, 52 insertions, 19 deletions
diff --git a/seed.lisp b/seed.lisp
new file mode 100644
index 0000000..40fc653
--- /dev/null
+++ b/seed.lisp
@@ -0,0 +1,13 @@
+(in-package :vampire)
+
+(db:with-transaction ()
+ (let ((alucard (make-instance 'user :name "alucard")))
+ (setf (user-pwhash alucard) (hash-string "password" (user-pwsalt alucard)))
+ (make-instance 'invite :maker alucard)
+ (mapcar
+ (lambda (s)
+ (make-instance
+ 'playlist
+ :title s :user alucard :editors (list alucard)
+ :cover-image "https://cicadas.surf/~shoshin/casiopeia/basement%20days/cover.png"))
+ '("One" "Two" "Three"))))
diff --git a/site/home.lisp b/site/home.lisp
index 47d0f17..5267985 100644
--- a/site/home.lisp
+++ b/site/home.lisp
@@ -9,6 +9,11 @@
(:h1 "hey " (user-name user))
(:br)
(:div
+ (:form :method "POST" :action (wknd:route-to 'session.destroy)
+ (:button :type "submit" "Logout")))
+ (:br)
+ (:br)
+ (:div
(:form :method "POST" :action (wknd:route-to 'create.invite)
(:p "Initiate an invitation...")
(:button :type "submit" "Bite Someone")))
diff --git a/site/login.lisp b/site/login.lisp
index d859e0d..7d07bb2 100644
--- a/site/login.lisp
+++ b/site/login.lisp
@@ -5,28 +5,10 @@
:returns "text/html"
:handle (login-page))
-(wknd:defendpoint login.user
- :post :route "login"
- :parameters
- (name string)
- (password string)
- :properties
- (user user)
- :authenticate (authenticate-login-user name password)
- :handle (wknd:endpoint-redirect 'home.html))
-
-(defun authenticate-login-user (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))))
-
(defun login-page ()
(page (:title "V A M P I R E ~ LOGIN")
(:div (:h1 "I vant to suck your blood")
- (:form :method "POST" :action (wknd:route-to 'login.user)
+ (:form :method "POST" :action (wknd:route-to 'session.create)
(:input :placeholder "Name" :name "name")
(:br)
(:input :placeholder "Password" :type "password" :name "password")
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)))
+
+
diff --git a/vampire.asd b/vampire.asd
index 4ac6d11..a3d5799 100644
--- a/vampire.asd
+++ b/vampire.asd
@@ -32,6 +32,7 @@
(:file "css")
(:file "html")
(:file "user-known")
+ (:file "session")
(:file "login")
(:file "invites")
(:file "home")