Skip to content

Commit

Permalink
Merge pull request #240 from jasonswett/allow-current-password
Browse files Browse the repository at this point in the history
Allow current_password to be supplied when updating profile.
  • Loading branch information
booleanbetrayal committed Jun 23, 2015
2 parents c1539d3 + d07eca5 commit 62f3d13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/controllers/devise_token_auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def create

def update
if @resource

if @resource.update_attributes(account_update_params)
if @resource.send(resource_update_method, account_update_params)
yield @resource if block_given?
render json: {
status: 'success',
Expand Down Expand Up @@ -142,6 +141,14 @@ def account_update_params

private

def resource_update_method
if account_update_params.has_key?(:current_password)
"update_with_password"
else
"update_attributes"
end
end

def validate_sign_up_params
validate_post_data sign_up_params, 'Please submit proper sign up data in request body.'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
assert_equal @email.downcase, @existing_user.email
assert_equal @email.downcase, @existing_user.uid
end

test "Supply current password" do
@request_params.merge!(
current_password: "secret123",
email: "[email protected]",
)

put "/auth", @request_params, @auth_headers
@data = JSON.parse(response.body)
@existing_user.reload
assert_equal @existing_user.email, "[email protected]"
end
end

describe 'validate non-empty body' do
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :favorite_color
devise_parameter_sanitizer.for(:account_update) << :operating_thetan
devise_parameter_sanitizer.for(:account_update) << :favorite_color
devise_parameter_sanitizer.for(:account_update) << :current_password
end
end

0 comments on commit 62f3d13

Please sign in to comment.