Module: Clearance::ApplicationController::ProtectedInstanceMethods

Defined in:
lib/clearance/app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject



27
28
29
# File 'lib/clearance/app/controllers/application_controller.rb', line 27

def authenticate
  deny_access unless self.current_user
end

#create_session_for(user) ⇒ Object



45
46
47
# File 'lib/clearance/app/controllers/application_controller.rb', line 45

def create_session_for(user)
  session[:user_id] = user.id if user
end

#deny_access(flash_message = nil, opts = {}) ⇒ Object



62
63
64
65
66
67
# File 'lib/clearance/app/controllers/application_controller.rb', line 62

def deny_access(flash_message = nil, opts = {})
  opts[:redirect] ||= 
  store_location
  flash[:error] = flash_message if flash_message
  redirect_to opts[:redirect]
end

#login(user) ⇒ Object



40
41
42
43
# File 'lib/clearance/app/controllers/application_controller.rb', line 40

def (user)
  create_session_for user
  @current_user = user
end

#redirect_back_or(default) ⇒ Object



49
50
51
52
# File 'lib/clearance/app/controllers/application_controller.rb', line 49

def redirect_back_or(default)
  session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)
  session[:return_to] = nil
end

#redirect_to_rootObject



54
55
56
# File 'lib/clearance/app/controllers/application_controller.rb', line 54

def redirect_to_root
  redirect_to root_url
end

#store_locationObject



58
59
60
# File 'lib/clearance/app/controllers/application_controller.rb', line 58

def store_location
  session[:return_to] = request.request_uri
end


35
36
37
38
# File 'lib/clearance/app/controllers/application_controller.rb', line 35

def user_from_cookie
  user = User.find_by_remember_token(cookies[:auth_token]) if cookies[:auth_token]
  user && user.remember_token? ? user : nil
end

#user_from_sessionObject



31
32
33
# File 'lib/clearance/app/controllers/application_controller.rb', line 31

def user_from_session
  User.find_by_id session[:user_id]
end