mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Updating helpers to use sign_in/sign_out instead of authenticate/logout.
This commit is contained in:
parent
6da49499ff
commit
0664359381
5 changed files with 29 additions and 24 deletions
|
@ -9,7 +9,7 @@ class SessionsController < ApplicationController
|
|||
|
||||
# POST /session/sign_in
|
||||
def create
|
||||
if warden.authenticate(:scope => resource_name)
|
||||
if sign_in(resource_name)
|
||||
set_flash_message :success, :signed_in
|
||||
redirect_to root_path
|
||||
else
|
||||
|
@ -21,8 +21,8 @@ class SessionsController < ApplicationController
|
|||
# GET /session/sign_out
|
||||
# DELETE /session/sign_out
|
||||
def destroy
|
||||
set_flash_message :success, :signed_out if authenticated?(resource_name)
|
||||
logout(resource_name)
|
||||
set_flash_message :success, :signed_out if signed_in?(resource_name)
|
||||
sign_out(resource_name)
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module Devise
|
|||
def self.included(base)
|
||||
base.class_eval do
|
||||
helper_method :warden, :signed_in?, :authenticated?,
|
||||
*Devise.mappings.keys.map { |m| :"current_#{m}" }
|
||||
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,22 +15,27 @@ module Devise
|
|||
request.env['warden']
|
||||
end
|
||||
|
||||
# Sign in a user through warden
|
||||
#
|
||||
def sign_in(scope)
|
||||
warden.authenticate(:scope => scope)
|
||||
end
|
||||
|
||||
# Check if a user is authenticated or not performing the proper action.
|
||||
#
|
||||
def authenticate!(scope)
|
||||
def sign_in!(scope)
|
||||
warden.authenticate!(:scope => scope)
|
||||
end
|
||||
|
||||
# Proxy to the authenticated? method on warden
|
||||
#
|
||||
def authenticated?(scope)
|
||||
def signed_in?(scope)
|
||||
warden.authenticated?(scope)
|
||||
end
|
||||
alias :signed_in? :authenticated?
|
||||
|
||||
# Logout based on scope
|
||||
# Sign out based on scope
|
||||
#
|
||||
def logout(scope, *args)
|
||||
def sign_out(scope, *args)
|
||||
warden.raw_session.inspect # Without this inspect here. The session does not clear.
|
||||
warden.logout(scope, *args)
|
||||
end
|
||||
|
@ -43,24 +48,24 @@ module Devise
|
|||
# Example:
|
||||
#
|
||||
# Maps:
|
||||
# Devise.map :users, :for => [:authenticable]
|
||||
# Devise.map :user, :for => [:authenticable]
|
||||
# Devise.map :admin, :for => [:authenticable]
|
||||
#
|
||||
# Generated Filters:
|
||||
# user_authenticate!
|
||||
# admin_authenticate!
|
||||
# sign_in_user!
|
||||
# sign_in_admin!
|
||||
#
|
||||
# Use:
|
||||
# before_filter :user_authenticate! # Tell devise to use :user map
|
||||
# before_filter :admin_authenticate! # Tell devise to use :admin map
|
||||
# before_filter :sign_in_user! # Tell devise to use :user map
|
||||
# before_filter :sign_in_admin! # Tell devise to use :admin map
|
||||
#
|
||||
Devise.mappings.each_key do |mapping|
|
||||
class_eval <<-METHODS, __FILE__, __LINE__
|
||||
def #{mapping}_authenticate!
|
||||
def sign_in_#{mapping}!
|
||||
warden.authenticate!(:scope => :#{mapping})
|
||||
end
|
||||
|
||||
def #{mapping}_authenticated?
|
||||
def #{mapping}_signed_in?
|
||||
warden.authenticated?(:#{mapping})
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|||
|
||||
test 'run authenticate? with scope on warden' do
|
||||
@mock_warden.expects(:authenticated?).with(:my_scope)
|
||||
@controller.authenticated?(:my_scope)
|
||||
@controller.signed_in?(:my_scope)
|
||||
end
|
||||
|
||||
test 'proxy signed_in? to authenticated' do
|
||||
|
@ -49,27 +49,27 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|||
|
||||
test 'proxy logout to warden' do
|
||||
@mock_warden.expects(:logout).with(:user).returns(true)
|
||||
@controller.logout(:user)
|
||||
@controller.sign_out(:user)
|
||||
end
|
||||
|
||||
test 'proxy user_authenticate! to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
||||
@controller.user_authenticate!
|
||||
@controller.sign_in_user!
|
||||
end
|
||||
|
||||
test 'proxy admin_authenticate! to authenticate with admin scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
||||
@controller.admin_authenticate!
|
||||
@controller.sign_in_admin!
|
||||
end
|
||||
|
||||
test 'proxy user_authenticated? to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticated?).with(:user)
|
||||
@controller.user_authenticated?
|
||||
@controller.user_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy admin_authenticated? to authenticate with admin scope' do
|
||||
@mock_warden.expects(:authenticated?).with(:admin)
|
||||
@controller.admin_authenticated?
|
||||
@controller.admin_signed_in?
|
||||
end
|
||||
|
||||
test 'require no authentication tests current mapping' do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AdminsController < ApplicationController
|
||||
before_filter :admin_authenticate!
|
||||
before_filter :sign_in_admin!
|
||||
|
||||
def index
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :user_authenticate!
|
||||
before_filter :sign_in_user!
|
||||
|
||||
def index
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue