Created
February 8, 2013 08:25
-
-
Save jibone/4737445 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
before_filter :authenticate_admin, :except => [:login, :login_verify] | |
before_filter :save_login_state_admin, :only => [:login, :login_verify] | |
def login | |
# login form | |
end | |
def login_verify | |
authorized_admin = Admin.authenticate(params[:admin_username], params[:admin_password]) | |
if authorized_admin | |
session[:admin_id] = authorized_admin.id | |
flash[:notice] = "Login Successful" | |
flash[:color] = "success" | |
redirect_to :action => 'dashboard' | |
else | |
flash[:notice] = "Invalid login. Please try again" | |
flash[:color] = "error" | |
render "login" | |
end | |
end | |
def logout | |
session[:admin_id] = nil | |
redirect_to :action => 'login' | |
end |
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
protected | |
def authenticate_user | |
unless session[:user_id] | |
redirect_to(:controller => 'account', :action => 'signin') | |
return false | |
else | |
@current_user = User.find session[:user_id] | |
return true | |
end | |
end | |
def save_login_state | |
if session[:user_id] | |
redirect_to(:controller => 'account', :action => 'dashboard') | |
return false | |
else | |
return true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment