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 ...
Get Programming Phoenix 1.4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.