Last active
August 29, 2015 14:05
-
-
Save hlship/0f0c3ff39843059c9ceb to your computer and use it in GitHub Desktop.
validate-auth updated with cond-let
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-let | |
(str/is-blank? user-id) | |
["user-id not specified"] | |
(str/is-blank? user-password) | |
["password not specified"] | |
[user-data (read-user-by-id db-connection user-id)] | |
(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