Skip to content

Instantly share code, notes, and snippets.

@nmcolome
Forked from rwarbelow/authentication.markdown
Created May 23, 2017 16:12
Show Gist options
  • Save nmcolome/0e7a841b3140631ea4f86abceb01f205 to your computer and use it in GitHub Desktop.
Save nmcolome/0e7a841b3140631ea4f86abceb01f205 to your computer and use it in GitHub Desktop.

Part I: User Creation

  1. add route for new_user_path
  2. create a UsersController with new action
  3. create new.html.erb
  4. generate user model with password_digest string field
  5. uncomment gem 'bcrypt' in Gemfile and add has_secure_password in User model
  6. add create action in UsersController
  7. implement logic for creating a user
  8. set session[:user_id] in create action
  9. add route for user_path (the show action)
  10. addshow action in UsersController
  11. add show.html.erb
  12. create current_user helper method in ApplicationController

Part II: Logging in

  1. add login route
  2. create SessionsController
  3. add new action in SessionsController
  4. add new.html.erb
  5. make login form in new.html.erb
  6. add post route for login
  7. add create action in SessionsController
  8. implement create action: find user, authenticate user, set session[:user_id], and redirect

Part III: Logging Out

  1. add logout link
  2. add logout route
  3. add destroy action in SessionsController
  4. clear the session and redirect
@nmcolome
Copy link
Author

This doesn't include sad path cases:
user#create: invalid username or password -- render :new
sessions#create: invalid login, either incorrect username or password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment