Always require typing username when self-deleting account (#40576)

This commit is contained in:
Claire committed 2026-09-24 16:29:46 +02:00
1 parent b978235160
commit 4b1d0278af
3 files changed
+14 -7

No files matched your search

@@ -29,11 +29,9 @@ class Settings::DeletesController < Settings::BaseController
end
def challenge_passed?
if current_user.encrypted_password.blank?
current_account.username == resource_params[:username]
else
current_user.valid_password?(resource_params[:password])
end
return false unless current_account.username == resource_params[:username]
current_user.encrypted_password.blank? || current_user.valid_password?(resource_params[:password])
end
def destroy_account!
+2 -2
View File
@@ -20,10 +20,10 @@
%hr.spacer/
= f.input :username, wrapper: :with_block_label, input_html: { autocomplete: 'off' }, hint: t('deletes.confirm_username')
- if current_user.encrypted_password.present?
= f.input :password, wrapper: :with_block_label, input_html: { autocomplete: 'current-password' }, hint: t('deletes.confirm_password')
- else
= f.input :username, wrapper: :with_block_label, input_html: { autocomplete: 'off' }, hint: t('deletes.confirm_username')
.actions
= f.button :button, t('deletes.proceed'), type: :submit, class: 'negative'
+9
View File
@@ -15,12 +15,21 @@ RSpec.describe 'Settings Deletes' do
.and have_private_cache_control
# Wrong confirmation value
fill_in 'form_delete_confirmation_username', with: user.account.username
fill_in 'form_delete_confirmation_password', with: 'wrongvalue'
click_on I18n.t('deletes.proceed')
expect(page)
.to have_text(I18n.t('deletes.challenge_not_passed'))
# Wrong confirmation value
fill_in 'form_delete_confirmation_username', with: 'wrongvalue'
fill_in 'form_delete_confirmation_password', with: user.password
click_on I18n.t('deletes.proceed')
expect(page)
.to have_text(I18n.t('deletes.challenge_not_passed'))
# Correct confirmation value
fill_in 'form_delete_confirmation_username', with: user.account.username
fill_in 'form_delete_confirmation_password', with: user.password
click_on I18n.t('deletes.proceed')
expect(page)