From a98270e2f8d90a9026394aff0aaa104824f045fa Mon Sep 17 00:00:00 2001
From: Grant Shangreaux <grant@unabridgedsoftware.com>
Date: Fri, 31 May 2024 15:36:21 -0500
Subject: Add: new user page

---
 site/login.lisp | 58 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/site/login.lisp b/site/login.lisp
index 66d20ff..14852c3 100644
--- a/site/login.lisp
+++ b/site/login.lisp
@@ -1,16 +1,5 @@
 (in-package #:vampire)
 
-(defun login-page ()
-  (with-html-string
-    (:div (:h1 "I vant to suck your blood")
-	  (:form :method "POST" :action "/login"
-		 (:input :placeholder "Name" :name "name")
-		 (:br)
-		 (:input :placeholder "Password" :type "password" :name "password")
-		 (:br)
-		 (:button :type "submit" "Click to Login")))
-    (:a :href "/new-account" "Come to the Dark Side")))
-
 (wknd:defendpoint login
   :get :route "login"
   :returns "text/html"
@@ -34,3 +23,50 @@
     session := (db:with-transaction () (make-instance 'session :user found-user))
     (wknd:set-cookie +session-cookie+ :value (key session))))
 
+(wknd:defendpoint new-account-page
+  :get :route "new-account"
+  :returns "text/html"
+  :handle (new-account-page))
+
+(wknd:defendpoint create-new-account
+  :post :to "new-account"
+  :parameters
+  (username string)
+  (password string)
+  (password2 string)
+  (invite-code string)
+  :properties
+  (invite invite)
+  :authenticate (and
+		 (equal password password2)
+		 (setf invite (object-with-key invite-code)))
+  :authorize (or (null (uses-remaining invite)) (plusp (uses-remaining invite)))
+  :handle (progn
+	    (db:with-transaction ()
+	      (when (uses-remaining invite)
+		(decf (uses-remaining invite)))
+	      (let ((user (make-instance 'user :name username)))
+		(setf (user-pwhash user) (hash-string password (user-pwsalt user)))))
+	    (wknd:endpoint-redirect 'login)))
+
+(defun login-page ()
+  (with-html-string
+    (:div (:h1 "I vant to suck your blood")
+	  (:form :method "POST" :action "/login"
+		 (:input :placeholder "Name" :name "name")
+		 (:br)
+		 (:input :placeholder "Password" :type "password" :name "password")
+		 (:br)
+		 (:button :type "submit" "Click to Login")))
+    (:a :href "/new-account" "Come to the Dark Side")))
+
+(defun new-account-page ()
+  (with-html-string
+    (:form :method "POST" :action "/new-account"
+	   (:input :placeholder "Invite Code" :name "invite-code")(:br)
+	   (:input :placeholder "Username" :name "username")(:br)
+	   (:input :placeholder "Password" :name "password" :type "password")(:br)
+	   (:input :placeholder "Repeat Password" :name "password2" :type "password")(:br)
+	   (:button :type "submit" "Become Undead"))))
+
+
-- 
cgit v1.2.3