aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2024-06-19 10:49:07 -0700
committercolin <colin@cicadas.surf>2024-06-19 10:49:07 -0700
commit9dbf54efdf2a62565333e58d63bcbfb804ab9442 (patch)
tree502189d0d6f46fae9d980da3e26b6f70954d0b5d
parent6e131b7c9c57c8cdf67ed59feafc6c8b56919e8f (diff)
Fix: reorganizing code into modulesHEADmain
-rw-r--r--site/invites.lisp42
-rw-r--r--site/login.lisp39
2 files changed, 42 insertions, 39 deletions
diff --git a/site/invites.lisp b/site/invites.lisp
index b463a4d..dc1f31c 100644
--- a/site/invites.lisp
+++ b/site/invites.lisp
@@ -9,6 +9,44 @@
(make-instance 'invite :maker user :uses-remaining 1))
(wknd:endpoint-redirect 'home.html)))
-(defun invite-validp (invite)
+(defun invite-valid-p (invite)
(let ((uses (uses-remaining invite)))
- (or (< 0 uses) (null uses))))
+ (or (plusp uses) (null uses))))
+
+
+(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 (invite-validp invite)
+ :handle (progn
+ (db:with-transaction ()
+ (when (uses-remaining invite)
+ (decf (uses-remaining invite))
+ (when (zerop (uses-remaining invite))
+ (db:delete-object invite)))
+ (let ((user (make-instance 'user :name username)))
+ (setf (user-pwhash user) (hash-string password (user-pwsalt user)))))
+ (wknd:endpoint-redirect 'login.html)))
+
+(wknd:defendpoint new-account.html
+ :get :route "new-account"
+ :returns "text/html"
+ :handle (new-account-page))
+
+(defun new-account-page ()
+ (page (:title "V A M P I R E ~ JOIN")
+ (:form :method "POST" :action (wknd:route-to 'create-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"))))
diff --git a/site/login.lisp b/site/login.lisp
index 04bf643..3f7e8fa 100644
--- a/site/login.lisp
+++ b/site/login.lisp
@@ -23,38 +23,10 @@
session := (db:with-transaction () (make-instance 'session :user found-user))
(wknd:set-cookie +session-cookie+ :value (key session))))
-(wknd:defendpoint new-account.html
- :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 (invite-validp invite)
- :handle (progn
- (db:with-transaction ()
- (when (uses-remaining invite)
- (decf (uses-remaining invite))
- (when (zerop (uses-remaining invite))
- (db:delete-object invite)))
- (let ((user (make-instance 'user :name username)))
- (setf (user-pwhash user) (hash-string password (user-pwsalt user)))))
- (wknd:endpoint-redirect 'login.html)))
-
(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 "/login"
+ (:form :method "POST" :action (wknd:route-to 'login-user)
(:input :placeholder "Name" :name "name")
(:br)
(:input :placeholder "Password" :type "password" :name "password")
@@ -63,13 +35,6 @@
(:a :href (wknd:route-to 'new-account.html)
"Become Undead"))))
-(defun new-account-page ()
- (page (:title "V A M P I R E ~ JOIN")
- (: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"))))
+