Created
February 17, 2014 20:56
-
-
Save RichardJordan/9058941 to your computer and use it in GitHub Desktop.
This file contains 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 | |
expose(:login_form) { LoginForm.new } | |
def create | |
user = User.find_by_email(params[:email]) | |
if user && user.authenticate(params[:password]) | |
reset_session | |
if params[:remember_me] | |
cookies.permanent[:auth_token] = user.auth_token | |
else | |
cookies[:auth_token] = user.auth_token | |
end | |
redirect_to user, notice: "Signed in!" | |
else | |
flash[:error] = "Email or password is invalid." | |
redirect_to login_path | |
end | |
end | |
def destroy | |
cookies.delete(:auth_token) | |
redirect_to root_url, notice: "Signed out!" | |
end | |
def new; end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment