Skip to content

Instantly share code, notes, and snippets.

@jibone
Created February 8, 2013 08:25
Show Gist options
  • Save jibone/4737445 to your computer and use it in GitHub Desktop.
Save jibone/4737445 to your computer and use it in GitHub Desktop.
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
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