Created
March 8, 2016 19:55
-
-
Save jgaskins/fb8f8498213b5580b29d to your computer and use it in GitHub Desktop.
ActiveRecord has_secure_password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails g model User email password_digest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_secure_password | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
def create | |
user = User.find_by(email: params[:email]) | |
if user && user.authenticate(params[:password]) | |
login(user) | |
redirect_to root_url, notice: 'Signed in successfully' | |
else | |
flash.alert 'Email and password do not match' | |
render :new | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment