January 2014
Intermediate to advanced
232 pages
5h 11m
English
Login and logout actions are very simple to implement. To log in the user will submit her ID and password using a login form. These will be checked against the stored credentials, and if they match we’ll put the ID in the session.
Let’s navigate to our picture-gallery.models.db namespace. We’ve already added a function to store the users in the database, and we now need to add one to read the users based on the IDs. We’ll use the with-query-results macro to get the records and return the first item. If no record matches the supplied ID, we’ll simply get a nil value back.
| | (defn get-user [id] |
| | (sql/with-connection |
| | db |
| | (sql/with-query-results |
| | res ["select * from users where id = ?" id] (first res)))) |
Note ...
Read now
Unlock full access