Created
December 19, 2011 20:00
-
-
Save resure/1498628 to your computer and use it in GitHub Desktop.
session_controller.rb
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 new | |
authorize! :login, User.new | |
end | |
def create | |
user = User.find_by_email(params[:email].downcase) | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to root_url, :notice => "Welcome back, #{user.first_name}." | |
else | |
flash.now.alert = 'Email or password was invalid' | |
render :new | |
end | |
end | |
def destroy | |
authorize! :logout, current_user | |
session[:user_id] = nil | |
redirect_to root_url, :notice => "Logged out!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment