j

Clojure code posted
created at 04 May 02:02

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(defn request-email-change!
  "When the requested new-email is equal to the current email, this is still
  handled as a real change request.

  Returns:
    - nil if validations fail
    - the updated object otherwise"
  [user-id new-email]
  (let [user (find-by-id user-id)]
    ; note that in order to validate the requested new email without
    ; additional validation code, this is handled like if it were the real,
    ; current email.
    (when (valid? (merge user {:email new-email}))
          (update! user-id
                   {:new_requested_email new-email
                    :email_change_code (hexadecimalize
                                              (generate-secure-token 20))}
                   {:skip-validations true}))))
765 Bytes in 2 ms with coderay