Module: SimpleAuth::ActionController::ClassMethods
- Defined in:
- lib/simple_auth/action_controller.rb
Instance Method Summary collapse
-
#redirect_logged_user(options = {}) ⇒ Object
Redirect logged users to the specified
:topath. -
#require_logged_user(options = {}) ⇒ Object
Redirect unlogged users to the specified
:topath.
Instance Method Details
#redirect_logged_user(options = {}) ⇒ Object
Redirect logged users to the specified :to path
redirect_logged_user :to => proc { login_path }
redirect_logged_user :to => {:controller => "dashboard"}
redirect_logged_user :only => [:index], :to => login_path
redirect_logged_user :except => [:public], :to => login_path
You can set the logged url globally:
SimpleAuth::Config.logged_url = {:controller => "dashboard", :action => "index"}
SimpleAuth::Config.logged_url = proc { dashboard_path }
93 94 95 96 97 98 99 |
# File 'lib/simple_auth/action_controller.rb', line 93 def redirect_logged_user( = {}) before_filter .except(:to) do |controller| controller.instance_eval do redirect_to simple_auth_url_for(:logged_url, controller, [:to]) if logged_in? end end end |
#require_logged_user(options = {}) ⇒ Object
Redirect unlogged users to the specified :to path
require_logged_user :to => proc { login_path }
require_logged_user :to => {:controller => "session", :action => "new"}
require_logged_user :only => [:index], :to => login_path
require_logged_user :except => [:public], :to => login_path
You can set login url globally:
SimpleAuth::Config.login_url = {:controller => "session", :action => "new"}
SimpleAuth::Config.login_url = proc { login_path }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/simple_auth/action_controller.rb', line 66 def require_logged_user( = {}) before_filter .except(:to) do |controller| controller.instance_eval do # Already logged in, so skip validation. next if current_session.try(:valid?) && session[:return_to] = request_uri if request.get? SimpleAuth::Session.destroy! flash.alert = t("simple_auth.sessions.need_to_be_logged") redirect_to simple_auth_url_for(:login_url, controller, [:to]) end end end |