From 3b16eb7abb2986132d3f7fdfe36d1d21e0d650bb Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Thu, 14 Nov 2019 16:19:23 -0700 Subject: [PATCH] FIX: Confirm new email with backup codes enabled This is a fix for this bug: https://meta.discourse.org/t/-/133185?u=blake where rails would throw a missing template error when trying to confirm a new email address when you had two factor backup codes enabled. Apparently this feature broke during this commit: 68d35b14f4b5193c1bae0f175b9e461152e13ac7 when a partial that contained a lot of javascript was removed most likely because it didn't comply with our Content Security Policy, so as a fix I rewrote the previous js functionality without using any javascript and then added a spec to verify that the correct backup code form is displayed when that page is loaded. --- app/views/users_email/confirm.html.erb | 32 +++++++++++--------- spec/requests/users_email_controller_spec.rb | 11 +++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/views/users_email/confirm.html.erb b/app/views/users_email/confirm.html.erb index 0f236a1992f..69d63eecce7 100644 --- a/app/views/users_email/confirm.html.erb +++ b/app/views/users_email/confirm.html.erb @@ -8,21 +8,26 @@
<%= t('change_email.please_continue', site_name: SiteSetting.title) %> <% elsif @update_result == :invalid_second_factor%> -
-

<%= t('login.second_factor_title') %>

-
- <%=form_tag({}, method: :put) do %> - <%= label_tag(:second_factor_token, t('login.second_factor_description')) %> -
<%= render 'common/second_factor_text_field' %>
- <% if @show_invalid_second_factor_error %> -
<%= t('login.invalid_second_factor_code') %>
+ <% if !params[:show_backup] || params[:show_backup] == "false" %> +
+

<%= t('login.second_factor_title') %>

+
+ <%=form_tag({}, method: :put) do %> + <%= label_tag(:second_factor_token, t('login.second_factor_description')) %> +
<%= render 'common/second_factor_text_field' %>
+ <% if @show_invalid_second_factor_error %> +
<%= t('login.invalid_second_factor_code') %>
+ <% end %> + <%= submit_tag t('submit'), class: "btn btn-primary" %> <% end %> - <%= submit_tag t('submit'), class: "btn btn-primary" %> +
+ <% if @backup_codes_enabled %> + <%= link_to t("login.second_factor_toggle.backup_code"), show_backup: "true" %> <% end %> -
+ <% end %> - <%if @backup_codes_enabled %> -