Implementing Login and Logout
We made great progress in the last section. We created a module plug that loads information from the session, used this information to restrict user access, and finally stored users in the session.
We’re almost done with our authentication feature. We need to implement both login and logout functionality, as well as change the layout to include links to those pages.
First things first. Before changing our controllers and views, let’s expose a function that authenticates a given username and password. We will look up a user by username in the database and securely ensure that the user’s password matches the one in the database. The Accounts context is a perfect place to define this function. Open up rumbl/accounts.ex ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access