-
Notifications
You must be signed in to change notification settings - Fork 10
/
reset_password.clj
65 lines (56 loc) · 2.2 KB
/
reset_password.clj
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
(ns bridge.person.access.reset-password
(:require [bridge.person.access.common :as access.common]
[bridge.person.data :as person.data]
[ring.util.response :as response]))
(defn reset-password-page [& [error]]
(access.common/access-page-layout
[:div.box
access.common/logo
(when (some? error)
[:div.notification.is-warning
(condp = error
:invalid-token
"Sorry! That token is invalid."
:password-too-short
"Sorry! That password is too short, it needs to be at least 8 characters."
:passwords-do-not-match
"Sorry! Those passwords do not match."
:unknown-error
"Sorry! Something went wrong.")])
[:form {:method "post"}
[:div.field
[:div.control
[:input.input.is-large
{:type "password"
:name "password"
:placeholder "Your Password"
:required "required"}]]]
[:div.field
[:div.control
[:input.input.is-large
{:type "password"
:name "confirm-password"
:placeholder "Confirm Password"
:required "required"}]]]
[:button.button.is-block.is-info.is-large.is-fullwidth "Reset Password"]]]
[:p.has-text-grey
[:a {:href "/help"} "Need Help?"]]))
(defn reset-password [{[_ token] :ataraxy/result
:keys [request-method]
{:keys [password confirm-password]} :params
:datomic/keys [conn db]}]
(or (when (= :post request-method)
(let [person-id (person.data/person-id-by-reset-password-token
db token)
password-error (person.data/valid-password? password confirm-password)]
(cond (nil? person-id)
(reset-password-page :invalid-token)
(some? password-error)
(reset-password-page password-error)
:else
(try
(person.data/reset-password! conn person-id token password)
(response/redirect (access.common/login-uri "/"))
(catch Throwable e
(reset-password-page :unknown-error))))))
(reset-password-page)))