public
Last active

  • Download Gist
sessions_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
class SessionsController < ApplicationController
 
def new
if member = Member.find_by_password_digest(cookies[:digest])
session[:member_id] = member.id
redirect_to (session[:ref] || root_path), :notice => "Welcome back #{member.first_name}"
end
end
def create
member = Member.find_by_user_name(params[:user_name])
if member && member.authenticate(params[:password])
session[:member_id] = member.id
if params["remember_me"] == "1"
cookies[:digest] = {:value => member.password_digest, :expires => Time.now + 360000}
else
cookies[:digest] = nil
end
redirect_to (session[:ref] || root_path), :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
 
def destroy
session[:member_id] = nil
cookies[:digest] = nil
redirect_to root_url, :notice => "Logged out!"
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.