-
Notifications
You must be signed in to change notification settings - Fork 29
Sessions generator
The sessions generator creates a sessions controller and adds the required routes and views.
rails g adauth:sessions
You can pass the name of the model you store users in but Adauth defaults to "user".
This is a pretty standard sessions controller with 3 actions new, create and destroy. The new action is empty and only exists to render the new view. Destroy sets session[:user_id]
to nil and redirects back to root_path.
The create action relies on you using Adauths UserModel, if you don't you will need to alter this code. This action calls the Adauth.authenticate method to check the username and password entered on the form if this returns an instance of Adauth::User it then calls return_and_create_with_adauth
on the User model. If your not using Adauth's user model this is the section of code you need to change.
This is the view for the new action, it is just a title and a call to the helper method adauth_form
The 2 routes created by this generator are /adauth
and /signout
. /adauth
is where the login form posts to, it maps to the sessions create action (see above). /signout
maps to the sessions destroy action and is your log out link.