2009-10-07 20:46:40 -04:00
|
|
|
module Devise
|
|
|
|
module Controllers
|
2009-10-10 12:52:14 -04:00
|
|
|
|
|
|
|
# Some helpers taken from RailsWarden.
|
2009-10-07 20:46:40 -04:00
|
|
|
module Authenticable
|
|
|
|
|
2009-10-10 12:52:14 -04:00
|
|
|
def self.included(base)
|
|
|
|
base.class_eval do
|
|
|
|
helper_method :warden, :user, :logged_in?
|
2009-10-09 20:11:58 -04:00
|
|
|
# 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
|
2009-10-09 20:11:58 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2009-10-09 20:11:58 -04:00
|
|
|
# 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
|
2009-10-07 20:46:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|