-
-
Save anonymous/2428913e718c68e6bc64cf4c261c12e9 to your computer and use it in GitHub Desktop.
This file contains 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 handle-registration-error [e] | |
(if (and | |
(instance? java.sql.SQLException e) | |
(-> e (.getNextException) | |
(.getMessage) | |
(.startsWith "ERROR: duplicate key value"))) | |
(response/precondition-failed | |
{:result :error | |
:message "user with the selected ID already exists"}) | |
(do | |
(log/error e) | |
(response/internal-server-error | |
{:result :error | |
:message "server error occurred while adding the user"})))) | |
(defn register! [{:keys [session]} user] | |
(if (registration-errors user) | |
(response/precondition-failed {:result :error}) | |
((try | |
(db/create-user! | |
(-> user | |
(dissoc :pass-confirm) | |
(update :pass hashers/encrypt))) | |
(-> {:result :ok} | |
(response/ok) | |
(assoc :session (assoc session :identity (:id user)))) | |
(catch Exception e | |
(handle-registration-error e)))))) | |
This file contains 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
titaniumbrella.routes.services.auth> (register! {} {:id 1 :first_name "Ping" :last_name "Pong" :email "wamblam84@gmail.com" :pass "notmypassword" :pass-confirm "notmypassword"}) | |
{:status 412, :headers {}, :body {:result :error}} |
This file contains 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
INSERT INTO users | |
(id, first_name, last_name, email, pass) | |
VALUES (:id, :first_name, :last_name, :email, :pass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment