Navigation Menu

Skip to content

Commit

Permalink
Implement handle unverified scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 15, 2011
1 parent de22a30 commit 9b0b505
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/devise/controllers/helpers.rb
Expand Up @@ -163,6 +163,20 @@ def sign_out_and_redirect(resource_or_scope)
redirect_to after_sign_out_path_for(scope)
end

# Sign out all active users or scopes. This helper is useful for signing out all roles
# in one click. This signs out ALL scopes in warden.
def sign_out_all_scopes
Devise.mappings.keys.each { |s| warden.user(s) }
warden.raw_session.inspect
warden.logout
end

# Override Rails' handle unverified request to sign out all scopes.
def handle_unverified_request
sign_out_all_scopes
super # call the default behaviour which resets the session
end

# Define authentication filters and accessor helpers based on mappings.
# These filters should be used inside the controllers as before_filters,
# so you can control the scope of the user who should be signed in to
Expand Down
10 changes: 10 additions & 0 deletions test/integration/rememberable_test.rb
Expand Up @@ -69,4 +69,14 @@ def create_user_and_remember(add_to_token='')
assert_not warden.authenticated?(:user)
assert_equal cookies['remember_user_token'], ''
end

test 'cookies are destroyed on unverified requests' do
swap HomeController, :allow_forgery_protection => true do
user = create_user_and_remember
get users_path
assert warden.authenticated?(:user)
post root_path, :authenticity_token => 'INVALID'
assert_not warden.authenticated?(:user)
end
end
end
2 changes: 1 addition & 1 deletion test/rails_app/config/environment.rb
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.10' unless defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION
DEVISE_ORM = :active_record unless defined? DEVISE_ORM

# Bootstrap the Rails environment, frameworks, and default configuration
Expand Down

0 comments on commit 9b0b505

Please sign in to comment.