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 }
89 90 91 92 93 94 95 |
# File 'lib/simple_auth/action_controller.rb', line 89 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 }
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/simple_auth/action_controller.rb', line 58 def require_logged_user( = {}) before_filter .except(:to) do |controller| controller.instance_eval do unless current_session && current_session.valid? && if request.respond_to?(:fullpath) return_to = request.fullpath else return_to = request.request_uri end session[:return_to] = return_to if request.get? SimpleAuth::Session.destroy! redirect_to simple_auth_url_for(:login_url, controller, [:to]), :alert => t("simple_auth.sessions.need_to_be_logged") end end end end |