Module: SimpleAuth::ActionController::ClassMethods

Defined in:
lib/simple_auth/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#redirect_logged_user(options = {}) ⇒ Object

Redirect logged users to the specified :to path

redirect_logged_user :to => proc {  }
redirect_logged_user :to => {:controller => "dashboard"}
redirect_logged_user :only => [:index], :to => 
redirect_logged_user :except => [:public], :to => 

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(options = {})
  before_filter options.except(:to) do |controller|
    controller.instance_eval do
      redirect_to simple_auth_url_for(:logged_url, controller, options[: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 {  }
require_logged_user :to => {:controller => "session", :action => "new"}
require_logged_user :only => [:index], :to => 
require_logged_user :except => [:public], :to => 

You can set login url globally:

SimpleAuth::Config. = {:controller => "session", :action => "new"}
SimpleAuth::Config. = proc {  }


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(options = {})
  before_filter options.except(:to) do |controller|
    controller.instance_eval do
      # Already logged in, so skip validation.
      next if current_session.try(:valid?) && authorized?

      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, options[:to])
    end
  end
end