Module: SimplestAuth::Controller
- Defined in:
- lib/simplest_auth/controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #access_denied ⇒ Object
- #authorized? ⇒ Boolean
- #clear_session ⇒ Object
- #current_user ⇒ Object
- #current_user=(user) ⇒ Object
- #current_user_id ⇒ Object
- #logged_in? ⇒ Boolean
- #login_message ⇒ Object
- #login_required ⇒ Object
- #redirect_back_or_default(default) ⇒ Object
- #session_key ⇒ Object
- #store_location ⇒ Object
- #user_class ⇒ Object
Class Method Details
.included(base) ⇒ Object
67 68 69 |
# File 'lib/simplest_auth/controller.rb', line 67 def self.included(base) base.send :helper_method, :current_user, :logged_in?, :authorized? if base.respond_to? :helper_method end |
Instance Method Details
#access_denied ⇒ Object
17 18 19 20 21 |
# File 'lib/simplest_auth/controller.rb', line 17 def access_denied store_location flash[:error] = redirect_to new_session_url end |
#authorized? ⇒ Boolean
13 14 15 |
# File 'lib/simplest_auth/controller.rb', line 13 def logged_in? end |
#clear_session ⇒ Object
63 64 65 |
# File 'lib/simplest_auth/controller.rb', line 63 def clear_session session[session_key] = nil end |
#current_user ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/simplest_auth/controller.rb', line 44 def current_user @current_user ||= begin if user_class.respond_to?(:get) user_class.get(current_user_id) else current_user_id && user_class.where(:id => current_user_id).first end end || clear_session end |
#current_user=(user) ⇒ Object
54 55 56 57 |
# File 'lib/simplest_auth/controller.rb', line 54 def current_user=(user) session[session_key] = user ? user.id : nil @current_user = user || false end |
#current_user_id ⇒ Object
59 60 61 |
# File 'lib/simplest_auth/controller.rb', line 59 def current_user_id session[session_key] end |
#logged_in? ⇒ Boolean
40 41 42 |
# File 'lib/simplest_auth/controller.rb', line 40 def logged_in? !current_user_id.nil? end |
#login_message ⇒ Object
23 24 25 |
# File 'lib/simplest_auth/controller.rb', line 23 def "Login or Registration Required" end |
#login_required ⇒ Object
36 37 38 |
# File 'lib/simplest_auth/controller.rb', line 36 def login_required || access_denied end |
#redirect_back_or_default(default) ⇒ Object
31 32 33 34 |
# File 'lib/simplest_auth/controller.rb', line 31 def redirect_back_or_default(default) redirect_to(session[:return_to] || default) session[:return_to] = nil end |
#session_key ⇒ Object
9 10 11 |
# File 'lib/simplest_auth/controller.rb', line 9 def session_key user_class.session_key end |
#store_location ⇒ Object
27 28 29 |
# File 'lib/simplest_auth/controller.rb', line 27 def store_location session[:return_to] = (request.respond_to?(:fullpath) ? request.fullpath : request.request_uri) end |
#user_class ⇒ Object
5 6 7 |
# File 'lib/simplest_auth/controller.rb', line 5 def user_class User end |