aboutsummaryrefslogtreecommitdiffhomepage
path: root/site/invites.lisp
blob: dc1f31cb89b3b1543414a539a91bc4c1489db4a7 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(in-package #:vampire)

(wknd:defendpoint invites
  :using user-known
  :post :to "invites"
  :handle
  (progn
    (db:with-transaction ()
      (make-instance 'invite :maker user :uses-remaining 1))
    (wknd:endpoint-redirect 'home.html)))

(defun invite-valid-p (invite)
  (let ((uses (uses-remaining invite)))
    (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"))))