Last active
August 29, 2015 14:05
-
-
Save hlship/fb0496b49088a6845e96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn validate-auth | |
"Validates the authentication data and returns vector of [error-message user-data]. On success, the error-message will | |
be nil." | |
[db-connection user-id user-password] | |
(cond | |
(str/is-blank? user-id) | |
["user-id not specified"] | |
(str/is-blank? user-password) | |
["password not specified"] | |
:else | |
(let [user-data (read-user-by-id db-connection user-id)] | |
(cond | |
(nil? user-data) | |
["user not found"] | |
(not (password/is-valid? (:password-hash user-data)) user-password) | |
["password not valid"] | |
(:is-expired user-data) | |
["user has expired"] | |
:else | |
[nil (dissoc user-data :password-hash)])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment