[RUBY] Rails tutorial (6th edition) Background operation of login function

table of contents

  1. Create new account
  2. ** Login (including Friendly Forwarding and permanent login) **
  3. Edit Profile
  4. Reset Password (https://qiita.com/akarin0519/items/ea873bb165ed4099a40e)
  5. Posting a micro post
  6. Follow and unfollow

2. Login

Operation screen

The operation of the login function with Friendly Forwarding and persistent login proceeds in the following two steps.

  1. Click a link that requires login (for example, edit profile) to display the login screen.
  2. Enter the required information on the login screen and press the send button to complete the login and display the link destination screen that you originally tried to access.

Background operation

The operation executed in each of the above steps is as follows.

  1. Send a GET request to a URL associated with an action that requires a login, such as the edit action in the Users controller, to see if the user is logged in, that is, if there is a session (session [: user_id]). If there is no session, store the url of the destination that tried to access in session [: forwarding_url]. Then, the redirect is made to login_url (GET request to/login path), the new action in SessionsController is executed, and the view (/sessions_controller/new.html.erb) corresponding to the new action, that is, the login screen is displayed. To log in.
  2. When the user fills in the required information in the login form and clicks the submit button, a POST request to the/login path is sent and the create action in the Sessions Controller is executed. In this create action, first, the corresponding user is searched from the DB using the email address (params [: session] [: email]) entered in the form as a clue. If the corresponding user exists, and the digest value of the password (params [: session] [: password]) received from the input form matches the password_digest registered in the DB (= authentication success), In addition, if the account is already activated, log in, that is, set up a session (session [: user_id] = user.id) and check the persistent login checkbox (logical value of remember_me key). Then, if the remember_me key is true, generate remember_token, save the digested value (remember_digest) in DB, and store the user ID and remember_token in cookies. On the other hand, if the remember_me key is false, set remember_digest to nil and delete the user ID and remember_token stored in cookies. Finally, if there is a URL that you tried to access before the login screen is displayed (session [: forwarding_url]), send a GET request to that URL and delete session [: forwarding_url]. Otherwise, a GET request will be sent to root_url.

Recommended Posts

Rails tutorial (6th edition) Background operation of login function
Rails tutorial (6th edition) Background operation of password reset function
Rails tutorial (6th edition) Background operation of profile editing
Rails tutorial (6th edition) Background operation of the posting function of the micro post
Rails tutorial (6th edition) Follow/unfollow background operation
Rails Tutorial (4th Edition) Summary
[Rails] Implementation of tutorial function
Implementation of Ruby on Rails login function (devise edition)
Rails Tutorial (4th Edition) Memo Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 7
Rails Tutorial 6th Edition Learning Summary Chapter 4
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Addition of easy and easy login function
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial 6th Edition Learning Summary Chapter 3
Rails Tutorial 6th Edition Learning Summary Chapter 8
Implementation of Ruby on Rails login function (Session)
Ruby on Rails <2021> Implementation of simple login function (form_with)
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
Addition of guest login function
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Login function implementation with rails
[Rails] Implementation of like function
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
[Rails] Implementation of image preview function
Kaminari --Added pagination function of Rails
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
Implement simple login function in Rails
[Rails] Addition of Ruby On Rails comment function
[Rails] Function restrictions in devise (login / logout)
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
Rails [For beginners] Implementation of comment function
Make a login function with Rails anyway
[Rails 6] Implementation of SNS (Twitter) sharing function
[Vue.js] Implementation of menu function Implementation version rails6
rails tutorial
rails tutorial
rails tutorial
Login function
rails tutorial
rails tutorial
rails tutorial
[Rails] Implementation of search function using gem's ransack
Validation settings for Ruby on Rails login function
[Rails 6] Implementation of inquiry function using Action Mailer
A summary of only Rails tutorial setup related
[Rails] Implementation of image enlargement function using lightbox2
Cloud9 is out of memory: Rails tutorial memorandum
Story of implementing login function using gem sorcery
[Rails] Implementation of retweet function in SNS application
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
I tried to make a message function of Rails Tutorial extension (Part 1): Create a model