Iteration J2: Authenticating Users

What does it mean to add login support for administrators of our store?

  • We need to provide a form that allows them to enter a username and password.

  • Once they’re logged in, we need to record that fact somehow for the rest of the session (or until they log out).

  • We need to restrict access to the administrative parts of the application, allowing only people who are logged in to administer the store.

We could put all of the logic into a single controller, but it makes more sense to split it into two—a session controller to support logging in and out and a controller to welcome administrators:

 depot>​​ ​​bin/rails​​ ​​generate​​ ​​controller​​ ​​Sessions​​ ​​new​​ ​​create​​ ​​destroy
 depot>​​ ​​ ...

Get Agile Web Development with Rails 6 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.