Skip to content

Commit 0b48dfb

Browse files
committed
Take advantage of password challenge feature
The password challenge feature was recently added to go with has_secure_password rails/rails#43688
1 parent 63f36ff commit 0b48dfb

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

app/controllers/users/registrations_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def edit
2929
end
3030

3131
def update
32-
update_user_params = params.require(:user).permit(:current_password, :password, :password_confirmation, email_exchanges_attributes: [:email])
32+
update_user_params = params.require(:user).permit(:password_challenge, :password, :password_confirmation, email_exchanges_attributes: [:email])
3333

3434
@user = current_user
3535

36-
if !@user.authenticate(params[:user][:current_password])
36+
if !@user.authenticate(params[:user][:password_challenge])
3737
flash.now[:error] = "Incorrect password"
3838
return render Users::Registrations::EditView.new(user: @user), status: :unprocessable_entity
3939
end

app/models/user.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class User < ApplicationRecord
1313
generates_token_for :confirmation, expires_in: 6.hours
1414
generates_token_for :password_reset, expires_in: 10.minutes
1515

16-
attribute :current_password
17-
1816
def confirmable_email
1917
if pending_email_exchange.present?
2018
pending_email_exchange.email

app/views/users/registrations/edit_view.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def view_template
4545
required: false
4646
end
4747
fieldset do
48-
layout.form_label form, :current_password, "Current password to confirm changes"
49-
layout.form_field form, :password_field, :current_password,
48+
layout.form_label form, :password_challenge, "Current password to confirm changes"
49+
layout.form_field form, :password_field, :password_challenge,
5050
type: "password",
5151
autocomplete: "current-password",
5252
required: false

spec/requests/users/registrations_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
login_user(user)
122122

123123
put users_registration_path,
124-
params: {user: {current_password: "password", password: "newpassword", password_confirmation: "newpassword"}}
124+
params: {user: {password_challenge: "password", password: "newpassword", password_confirmation: "newpassword"}}
125125

126126
expect(response).to redirect_to(users_dashboard_path)
127127
expect(flash[:notice]).to eq("Account updated")
@@ -136,7 +136,7 @@
136136

137137
expect {
138138
put users_registration_path,
139-
params: {user: {current_password: "password", email_exchanges_attributes: [{email: new_email}]}}
139+
params: {user: {password_challenge: "password", email_exchanges_attributes: [{email: new_email}]}}
140140
}.to change(user.email_exchanges, :count).by(1)
141141

142142
expect(response).to redirect_to(users_dashboard_path)

0 commit comments

Comments
 (0)