Module: Clearance::ApplicationController::ProtectedInstanceMethods
- Defined in:
- lib/clearance/application_controller.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #create_session_for(user) ⇒ Object
- #deny_access(flash_message = nil, opts = {}) ⇒ Object
- #login(user) ⇒ Object
- #redirect_back_or(default) ⇒ Object
- #store_location ⇒ Object
- #user_from_cookie ⇒ Object
- #user_from_session ⇒ Object
Instance Method Details
#authenticate ⇒ Object
23 24 25 |
# File 'lib/clearance/application_controller.rb', line 23 def authenticate deny_access if current_user.nil? end |
#create_session_for(user) ⇒ Object
41 42 43 |
# File 'lib/clearance/application_controller.rb', line 41 def create_session_for(user) session[:user_id] = user.id if user end |
#deny_access(flash_message = nil, opts = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/clearance/application_controller.rb', line 54 def deny_access( = nil, opts = {}) opts[:redirect] ||= login_url store_location flash[:error] = if redirect_to opts[:redirect] end |
#login(user) ⇒ Object
36 37 38 39 |
# File 'lib/clearance/application_controller.rb', line 36 def login(user) create_session_for user @current_user = user end |
#redirect_back_or(default) ⇒ Object
45 46 47 48 |
# File 'lib/clearance/application_controller.rb', line 45 def redirect_back_or(default) session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default) session[:return_to] = nil end |
#store_location ⇒ Object
50 51 52 |
# File 'lib/clearance/application_controller.rb', line 50 def store_location session[:return_to] = request.request_uri end |
#user_from_cookie ⇒ Object
31 32 33 34 |
# File 'lib/clearance/application_controller.rb', line 31 def user = User.find_by_remember_token([:auth_token]) if [:auth_token] user && user.remember_token? ? user : nil end |
#user_from_session ⇒ Object
27 28 29 |
# File 'lib/clearance/application_controller.rb', line 27 def user_from_session User.find_by_id(session[:user_id]) end |