mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 18:52:07 +08:00
Merge pull request #3420 from artoscinote/ma_SCI_5856
Made 2fa enable modal accessible globally [SCI-5856]
This commit is contained in:
commit
4934b4eb8e
4 changed files with 44 additions and 39 deletions
38
app/assets/javascripts/sitewide/two_factor_wizard.js
Normal file
38
app/assets/javascripts/sitewide/two_factor_wizard.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
$(document).on('turbolinks:load', function() {
|
||||
$(document).on('click', '#twoFactorAuthenticationDisable', function() {
|
||||
$('#twoFactorAuthenticationModal').modal('show');
|
||||
});
|
||||
|
||||
$(document).on('click', '#twoFactorAuthenticationEnable', function() {
|
||||
// close all other modals
|
||||
$('.modal').modal('hide');
|
||||
|
||||
$.get(this.dataset.qrCodeUrl, function(result) {
|
||||
$('#twoFactorAuthenticationModal .qr-code').html(result.qr_code);
|
||||
$('#twoFactorAuthenticationModal').find('[href="#2fa-step-1"]').tab('show');
|
||||
$('#twoFactorAuthenticationModal').modal('show');
|
||||
$('#twoFactorAuthenticationModal').find('.submit-code-field').removeClass('error').find('#submit_code')
|
||||
.val('');
|
||||
});
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal .2fa-enable-form').on('ajax:error', function(e, data) {
|
||||
$(this).find('.submit-code-field').addClass('error').attr('data-error-text', data.responseJSON.error);
|
||||
}).on('ajax:success', function(e, data) {
|
||||
var blob = new Blob([data.recovery_codes.join('\r\n')], { type: 'text/plain;charset=utf-8' });
|
||||
$('#twoFactorAuthenticationModal').find('.recovery-codes').html(data.recovery_codes.join('<br>'));
|
||||
$('#twoFactorAuthenticationModal').find('[href="#2fa-step-4"]').tab('show');
|
||||
$('.download-recovery-codes').attr('href', window.URL.createObjectURL(blob));
|
||||
$('#twoFactorAuthenticationModal').one('hide.bs.modal', function() {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal .2fa-disable-form').on('ajax:error', function(e, data) {
|
||||
$(this).find('.password-field').addClass('error').attr('data-error-text', data.responseJSON.error);
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal').on('click', '.btn-next-step', function() {
|
||||
$('#twoFactorAuthenticationModal').find(`[href="${$(this).data('step')}"]`).tab('show');
|
||||
});
|
||||
});
|
|
@ -79,37 +79,4 @@
|
|||
}
|
||||
$fileInput[0].value = '';
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationDisable').click(function() {
|
||||
$('#twoFactorAuthenticationModal').modal('show');
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationEnable').click(function() {
|
||||
$.get(this.dataset.qrCodeUrl, function(result) {
|
||||
$('#twoFactorAuthenticationModal .qr-code').html(result.qr_code);
|
||||
$('#twoFactorAuthenticationModal').find('[href="#2fa-step-1"]').tab('show');
|
||||
$('#twoFactorAuthenticationModal').modal('show');
|
||||
$('#twoFactorAuthenticationModal').find('.submit-code-field').removeClass('error').find('#submit_code').val('');
|
||||
});
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal .2fa-enable-form').on('ajax:error', function(e, data) {
|
||||
$(this).find('.submit-code-field').addClass('error').attr('data-error-text', data.responseJSON.error);
|
||||
}).on('ajax:success', function(e, data) {
|
||||
var blob = new Blob([data.recovery_codes.join('\r\n')], { type: 'text/plain;charset=utf-8' });
|
||||
$('#twoFactorAuthenticationModal').find('.recovery-codes').html(data.recovery_codes.join('<br>'));
|
||||
$('#twoFactorAuthenticationModal').find('[href="#2fa-step-4"]').tab('show');
|
||||
$('.download-recovery-codes').attr('href', window.URL.createObjectURL(blob));
|
||||
$('#twoFactorAuthenticationModal').one('hide.bs.modal', function() {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal .2fa-disable-form').on('ajax:error', function(e, data) {
|
||||
$(this).find('.password-field').addClass('error').attr('data-error-text', data.responseJSON.error);
|
||||
});
|
||||
|
||||
$('#twoFactorAuthenticationModal').on('click', '.btn-next-step', function() {
|
||||
$('#twoFactorAuthenticationModal').find(`[href="${$(this).data('step')}"]`).tab('show');
|
||||
});
|
||||
}());
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
|
||||
<h2 class="modal-title"><%= t("users.registrations.edit.2fa_modal.disable.title") %></h2>
|
||||
</div>
|
||||
<%= form_with(url: users_2fa_disable_path, method: "post", class: "2fa-disable-form") do %>
|
||||
<%= form_with(url: main_app.users_2fa_disable_path, method: "post", class: "2fa-disable-form") do %>
|
||||
<div class="modal-body">
|
||||
<p><%= t("users.registrations.edit.2fa_modal.disable.description") %></p>
|
||||
<div class="sci-input-container password-field">
|
||||
|
@ -26,10 +26,10 @@
|
|||
<li role="presentation"><a href="#2fa-step-4" data-toggle="tab" data-no-turbolink="true"></a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<%= render partial: '2fa_modal_apps_tab' %>
|
||||
<%= render partial: '2fa_modal_qr_code_tab' %>
|
||||
<%= render partial: '2fa_modal_verify_code_tab' %>
|
||||
<%= render partial: '2fa_modal_recovery_codes_tab' %>
|
||||
<%= render partial: 'users/registrations/2fa_modal_apps_tab.html.erb' %>
|
||||
<%= render partial: 'users/registrations/2fa_modal_qr_code_tab.html.erb' %>
|
||||
<%= render partial: 'users/registrations/2fa_modal_verify_code_tab.html.erb' %>
|
||||
<%= render partial: 'users/registrations/2fa_modal_recovery_codes_tab.html.erb' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
|
||||
<h2 class="modal-title"><%= t("users.registrations.edit.2fa_modal.step_3.title") %></h2>
|
||||
</div>
|
||||
<%= form_with(url: users_2fa_enable_path, method: "post", class: "2fa-enable-form") do %>
|
||||
<%= form_with(url: main_app.users_2fa_enable_path, method: "post", class: "2fa-enable-form") do %>
|
||||
<div class="modal-body">
|
||||
<p><%= t("users.registrations.edit.2fa_modal.step_3.description") %></p>
|
||||
<p class="sci-input-container submit-code-field">
|
||||
|
|
Loading…
Reference in a new issue