Module: Clearance::App::Controllers::ApplicationController::ProtectedInstanceMethods
- Defined in:
- lib/clearance/app/controllers/application_controller.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #deny_access(flash_message = nil, opts = {}) ⇒ Object
-
#log_user_in(user) ⇒ Object
Level of indirection so you can easily override this method but also call #login .
- #login(user) ⇒ Object
- #login_required ⇒ Object
- #mailer_model ⇒ Object
- #redirect_back_or(default) ⇒ Object
- #redirect_to_root ⇒ Object
- #store_location ⇒ Object
- #user_from_cookie ⇒ Object
- #user_from_session ⇒ Object
- #user_model ⇒ Object
Instance Method Details
#authenticate ⇒ Object
33 34 35 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 33 def authenticate deny_access unless logged_in? end |
#deny_access(flash_message = nil, opts = {}) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 70 def deny_access( = nil, opts = {}) opts[:redirect] ||= new_session_path store_location flash[:error] = if redirect_to opts[:redirect] end |
#log_user_in(user) ⇒ Object
Level of indirection so you can easily override this method but also call #login .
48 49 50 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 48 def log_user_in(user) login(user) end |
#login(user) ⇒ Object
52 53 54 55 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 52 def login(user) session[:user_id] = user.id if user @current_user = user end |
#login_required ⇒ Object
29 30 31 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 29 def login_required logged_in? || deny_access('Permission denied', :redirect => new_session_path) end |
#mailer_model ⇒ Object
81 82 83 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 81 def mailer_model ClearanceMailer end |
#redirect_back_or(default) ⇒ Object
57 58 59 60 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 57 def redirect_back_or(default) session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default) session[:return_to] = nil end |
#redirect_to_root ⇒ Object
62 63 64 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 62 def redirect_to_root redirect_to root_url end |
#store_location ⇒ Object
66 67 68 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 66 def store_location session[:return_to] = request.request_uri end |
#user_from_cookie ⇒ Object
41 42 43 44 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 41 def user = user_model.find_by_remember_token([:auth_token]) if [:auth_token] user && user.remember_token? ? user : nil end |
#user_from_session ⇒ Object
37 38 39 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 37 def user_from_session user_model.find_by_id session[:user_id] end |
#user_model ⇒ Object
77 78 79 |
# File 'lib/clearance/app/controllers/application_controller.rb', line 77 def user_model User end |