Account Settings

Now that we’ve learned how to modify the profile, we should add some features for managing accounts. Let’s enable users to change their passwords and delete their accounts.

Change Password

The first thing we need to do is write a SQL query to change the password, along with a function to call it.

 -- :name set-password-for-user!* :! :n
 UPDATE​ users
 SET​ ​password​ = :​password
 where​ login = :login
 (​defn​ change-password! [login old-password new-password]
  (​jdbc/with-transaction​ [t-conn db/*db*]
  (​let​ [{hashed :password} (​db/get-user-for-auth*​ t-conn {:login login})]
  (​if​ (​hashers/check​ old-password hashed)
  (​db/set-password-for-user!* ...

Get Web Development with Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.