mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Add support for non-navigational formats in PasswordsController
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
210bc6aa66
commit
97f0bacfa0
2 changed files with 48 additions and 6 deletions
|
@ -13,10 +13,12 @@ class Devise::PasswordsController < ApplicationController
|
|||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => new_session_path(resource_name)
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with(resource) do |format|
|
||||
format.any(*navigational_formats) { render_with_scope :new }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,10 +34,13 @@ class Devise::PasswordsController < ApplicationController
|
|||
self.resource = resource_class.reset_password_by_token(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :updated
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
set_flash_message(:notice, :updated) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => redirect_location(resource_name, resource)
|
||||
else
|
||||
render_with_scope :edit
|
||||
respond_with(resource) do |format|
|
||||
format.any(*navigational_formats) { render_with_scope :edit }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -157,4 +157,41 @@ class PasswordTest < ActionController::IntegrationTest
|
|||
assert !warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'reset password request with valid E-Mail in XML format should return valid response' do
|
||||
create_user
|
||||
post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"}
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
end
|
||||
|
||||
test 'reset password request with invalid E-Mail in XML format should return valid response' do
|
||||
create_user
|
||||
post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'change password with valid parameters in XML format should return valid response' do
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '987654321', :password_confirmation => '987654321'}
|
||||
assert_response :success
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'change password with invalid token in XML format should return invalid response' do
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'change password with invalid new password in XML format should return invalid response' do
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue