1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/lib/devise/controllers/authenticable.rb

75 lines
2 KiB
Ruby
Raw Normal View History

module Devise
module Controllers
2009-10-10 12:52:14 -04:00
# Some helpers taken from RailsWarden.
module Authenticable
2009-10-10 12:52:14 -04:00
def self.included(base)
base.class_eval do
helper_method :warden, :user, :logged_in?
# helper_method :session_path, :session_url,
# :new_session_path, :new_session_url,
# :password_path, :password_url,
# :new_password_path, :new_password_url,
# :confirmation_path, :confirmation_url,
# :new_confirmation_path, :new_confirmation_url
2009-10-10 12:52:14 -04:00
end
end
protected
2009-10-10 12:52:14 -04:00
# The main accessor for the warden proxy instance
#
def warden
request.env['warden']
end
# Proxy to the authenticated? method on warden
#
def authenticated?(*args)
warden.authenticated?(*args)
end
alias_method :logged_in?, :authenticated?
# Access the currently logged in user
#
def user(*args)
warden.user(*args)
end
alias_method :current_user, :user
def user=(user)
warden.set_user user
end
alias_method :current_user=, :user=
# Logout the current user
#
def logout(*args)
warden.raw_session.inspect # Without this inspect here. The session does not clear :|
warden.logout(*args)
end
# Proxy to the authenticate method on warden
#
def authenticate(*args)
warden.authenticate(*args)
end
# Proxy to the authenticate method on warden
#
def authenticate!(*args)
warden.authenticate!(*args)
end
# Helper for use in before_filters where no authentication is required:
# Example:
# before_filter :require_no_authentication, :only => :new
#
def require_no_authentication
redirect_to root_path if authenticated?
end
end
end
end