j

Clojure code posted
created at 04 May 02:10

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(defn activate!
  "An activation_code_created_at column is used to handle expirations. 

  Returns:
    - nil if activation fails (errors can be retrieved using noir.validation)
    - the user object if activation succeeds"
 [activation-code]
  (if-let [user (find-by-activation-code activation-code)]
    ; https://github.com/seancorfield/clj-time
    ; https://github.com/seancorfield/clj-time/blob/master/src/clj_time/core.clj
    (if (> (time/in-hours (time/interval (:activation_code_created_at user)
                                         (time/now)))
           1)
        (vali/set-error :activation_code :expired-activation-code)
        (update! (:_id user) 
                 {:activation_code :$unset
                  :activation_code_created_at :$unset}
                 {:skip-validations true}))
    (vali/set-error :activation_code :activation-code-not-found)))
897 Bytes in 2 ms with coderay