mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Add cancel to registrations controller as a way to delete information from session.
This commit is contained in:
parent
d0d88cf259
commit
ac8221aca7
6 changed files with 47 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
class Devise::RegistrationsController < ApplicationController
|
class Devise::RegistrationsController < ApplicationController
|
||||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
||||||
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
|
|
||||||
|
@ -45,6 +45,14 @@ class Devise::RegistrationsController < ApplicationController
|
||||||
sign_out_and_redirect(self.resource)
|
sign_out_and_redirect(self.resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /resource/cancel
|
||||||
|
# Forces the session data which is usually expired after sign
|
||||||
|
# in to be expired now.
|
||||||
|
def cancel
|
||||||
|
expire_session_data_after_sign_in!
|
||||||
|
redirect_to new_registration_path(resource_name)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Build a devise resource passing in the session. Useful to move
|
# Build a devise resource passing in the session. Useful to move
|
||||||
|
|
|
@ -216,8 +216,15 @@ module ActionDispatch::Routing
|
||||||
end
|
end
|
||||||
|
|
||||||
def devise_registration(mapping, controllers) #:nodoc:
|
def devise_registration(mapping, controllers) #:nodoc:
|
||||||
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
|
path_names = {
|
||||||
:path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
|
:new => mapping.path_names[:sign_up],
|
||||||
|
:cancel => mapping.path_names[:cancel]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource :registration, :except => :show, :path => mapping.path_names[:registration],
|
||||||
|
:path_names => path_names, :controller => controllers[:registrations] do
|
||||||
|
get :cancel
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def devise_oauth_callback(mapping, controllers) #:nodoc:
|
def devise_oauth_callback(mapping, controllers) #:nodoc:
|
||||||
|
|
|
@ -150,4 +150,16 @@ class RegistrationTest < ActionController::IntegrationTest
|
||||||
|
|
||||||
assert User.all.empty?
|
assert User.all.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'a user should be able to cancel sign up by deleting data in the session' do
|
||||||
|
get "/set"
|
||||||
|
assert_equal "something", @request.session["user_facebook_oauth_token"]
|
||||||
|
|
||||||
|
get "/users/sign_up"
|
||||||
|
assert_equal "something", @request.session["user_facebook_oauth_token"]
|
||||||
|
|
||||||
|
get "/users/cancel"
|
||||||
|
assert_nil @request.session["user_facebook_oauth_token"]
|
||||||
|
assert_redirected_to new_user_registration_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,9 @@ class HomeController < ApplicationController
|
||||||
|
|
||||||
def private
|
def private
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set
|
||||||
|
session["user_facebook_oauth_token"] = "something"
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,9 +39,10 @@ Rails.application.routes.draw do
|
||||||
:sign_in => "login", :sign_out => "logout",
|
:sign_in => "login", :sign_out => "logout",
|
||||||
:password => "secret", :confirmation => "verification",
|
:password => "secret", :confirmation => "verification",
|
||||||
:unlock => "unblock", :sign_up => "register",
|
:unlock => "unblock", :sign_up => "register",
|
||||||
:registration => "management"
|
:registration => "management", :cancel => "giveup"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match "/set", :to => "home#set"
|
||||||
root :to => "home#index"
|
root :to => "home#index"
|
||||||
end
|
end
|
|
@ -86,6 +86,11 @@ class DefaultRoutingTest < ActionController::TestCase
|
||||||
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'map cancel user registration' do
|
||||||
|
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel'}, {:path => 'users/cancel', :method => :get})
|
||||||
|
assert_named_route "/users/cancel", :cancel_user_registration_path
|
||||||
|
end
|
||||||
|
|
||||||
test 'map oauth callbacks' do
|
test 'map oauth callbacks' do
|
||||||
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'facebook'}, {:path => 'users/oauth/facebook/callback', :method => :get})
|
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'facebook'}, {:path => 'users/oauth/facebook/callback', :method => :get})
|
||||||
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'github'}, {:path => 'users/oauth/github/callback', :method => :get})
|
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'github'}, {:path => 'users/oauth/github/callback', :method => :get})
|
||||||
|
@ -140,6 +145,11 @@ class CustomizedRoutingTest < ActionController::TestCase
|
||||||
test 'map account with custom path name for registration' do
|
test 'map account with custom path name for registration' do
|
||||||
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
|
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'map account with custom path name for cancel registration' do
|
||||||
|
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel', :locale => 'en'}, '/en/accounts/management/giveup')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ScopedRoutingTest < ActionController::TestCase
|
class ScopedRoutingTest < ActionController::TestCase
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue