blob: 14852c38389e319d60324d63d0705f1da810743e (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
(in-package #:vampire)
(wknd:defendpoint login
:get :route "login"
: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))
(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))))
(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"))))
|