diff --git a/app/controllers/users/delete_controller.rb b/app/controllers/users/delete_controller.rb index 5559dfbf982..5daaabe5042 100644 --- a/app/controllers/users/delete_controller.rb +++ b/app/controllers/users/delete_controller.rb @@ -1,19 +1,39 @@ module Users - class DeleteController < ReauthnRequiredController + class DeleteController < ApplicationController before_action :confirm_two_factor_authenticated + before_action :confirm_current_password, only: [:delete] - def show; end + def show + analytics.track_event(Analytics::ACCOUNT_DELETE_VISITED) + end def delete send_push_notifications current_user.destroy! sign_out flash[:success] = t('devise.registrations.destroyed') + analytics.track_event(Analytics::ACCOUNT_DELETE_SUBMITTED, success: true) redirect_to root_url end private + def confirm_current_password + return if valid_password? + + flash[:error] = t('idv.errors.incorrect_password') + analytics.track_event(Analytics::ACCOUNT_DELETE_SUBMITTED, success: false) + render :show + end + + def valid_password? + current_user.valid_password?(password) + end + + def password + params.fetch(:user, {})[:password].presence + end + def send_push_notifications return if Figaro.env.push_notifications_enabled != 'true' PushNotification::AccountDelete.new.call(current_user.id) diff --git a/app/services/analytics.rb b/app/services/analytics.rb index cf9e4697cf1..5f473bf9d53 100644 --- a/app/services/analytics.rb +++ b/app/services/analytics.rb @@ -65,6 +65,8 @@ def browser_attributes # rubocop:disable Metrics/LineLength ACCOUNT_RESET = 'Account Reset'.freeze + ACCOUNT_DELETE_SUBMITTED = 'Account Delete submitted'.freeze + ACCOUNT_DELETE_VISITED = 'Account Delete visited'.freeze ACCOUNT_DELETION = 'Account Deletion Requested'.freeze ACCOUNT_RESET_VISIT = 'Account deletion and reset visited'.freeze ACCOUNT_VISIT = 'Account Page Visited'.freeze diff --git a/app/views/users/delete/show.html.erb b/app/views/users/delete/show.html.erb new file mode 100644 index 00000000000..06070167938 --- /dev/null +++ b/app/views/users/delete/show.html.erb @@ -0,0 +1,30 @@ +