Skip to content

Instantly share code, notes, and snippets.

@safarista
Forked from andyl/sessions_controller.rb
Created July 26, 2011 00:18
Show Gist options
  • Save safarista/1105609 to your computer and use it in GitHub Desktop.
Save safarista/1105609 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment