Skip to content

Instantly share code, notes, and snippets.

@jcuervo
Forked from carloncarpio/access_controller
Created August 15, 2012 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jcuervo/3356473 to your computer and use it in GitHub Desktop.
Save jcuervo/3356473 to your computer and use it in GitHub Desktop.
def attempt_login
authorized_user = User.authenticate(params[:username], params[:hashed_password])
unless authorized_user.eql?(false)
session[:user_id] = authorized_user.id
session[:username] = authorized_user.username
case authorized_user.account_type
when "admin"
redirect_to :action => "index"
when "it"
redirect_to :action => "it"
end
else
#flash something for the error
redirect_to root_url #or somewhere else
end
end
def self.authenticate(username="",password="")
user = User.find_by_username(username)
#can hashed_password be matched with the input password?
if user && user.hashed_password == password
user
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment