Use sign_in and authenticate methods.

This commit is contained in:
José Valim
2009-10-18 15:01:56 -02:00
parent 9051d842c0
commit b0a2da72b5
7 changed files with 34 additions and 37 deletions

View File

@@ -4,7 +4,7 @@ module Devise
def self.included(base)
base.class_eval do
helper_method :warden, :signed_in?, :authenticated?,
helper_method :warden, :signed_in?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
end
end
@@ -14,29 +14,31 @@ module Devise
request.env['warden']
end
# Sign in a user through warden, but does not take any action (like
# redirect).
def sign_in(scope)
# Attempts to authenticate the given scope by running authentication hooks,
# but does not redirect in case of failures.
def authenticate(scope)
warden.authenticate(:scope => scope)
end
# Check if a user is authenticated.
def sign_in!(scope)
# Attempts to authenticate the given scope by running authentication hooks,
# redirecting in case of failures.
def authenticate!(scope)
warden.authenticate!(:scope => scope)
end
# Proxy to the authenticated? method on warden.
# Check if the given scope is signed in session, without running
# authentication hooks.
def signed_in?(scope)
warden.authenticated?(scope)
end
# Set the warden user with the scope, sign in the resource automatically
# (without credentials).
def sign_in_automatically(resource, scope)
# Set the warden user with the scope, signing in the resource automatically,
# without running hooks.
def sign_in(scope, resource)
warden.set_user(resource, :scope => scope)
end
# Sign out based on scope
# Sign out based on scope.
def sign_out(scope, *args)
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope, *args)
@@ -52,27 +54,23 @@ module Devise
# User => :authenticable
# Admin => :authenticable
#
# Generated Filters:
# sign_in_user!
# sign_in_admin!
# Generated methods:
# authenticate_user! # Signs user in or redirect
# authenticate_admin! # Signs admin in or redirect
# user_signed_in? # Checks whether there is an user signed in or not
# admin_signed_in? # Checks whether there is an admin signed in or not
# current_user # Current signed in user
# current_admin # Currend signed in admin
# user_session # Session data available only to the user scope
# admin_session # Session data available only to the admin scope
#
# Use:
# before_filter :sign_in_user! # Tell devise to use :user map
# before_filter :sign_in_admin! # Tell devise to use :admin map
#
# Generated helpers:
# sign_in_user! # Checks whether there is an user signed in or not
# sign_in_admin! # Checks whether there is an admin signed in or not
# user_signed_in? # Checks whether there is an user signed in or not
# admin_signed_in? # Checks whether there is an admin signed in or not
# current_user # Current signed in user
# current_admin # Currend signed in admin
# user_session # Session data available only to the user scope
# admin_session # Session data available only to the admin scope
# before_filter :authenticate_user! # Tell devise to use :user map
# before_filter :authenticate_admin! # Tell devise to use :admin map
#
Devise.mappings.each_key do |mapping|
class_eval <<-METHODS, __FILE__, __LINE__
def sign_in_#{mapping}!
def authenticate_#{mapping}!
warden.authenticate!(:scope => :#{mapping})
end