2fa.js 1012 B

12345678910111213141516171819202122232425262728293031
  1. import $ from 'jquery';
  2. import { config } from 'grav-config';
  3. import request from '../utils/request';
  4. const body = $('body');
  5. // Dashboard update and Grav update
  6. body.on('click', '[data-2fa-regenerate]', function() {
  7. let element = $(this);
  8. let url = `${config.base_url_relative}/ajax.json/task${config.param_sep}regenerate2FASecret`;
  9. element.attr('disabled', 'disabled').find('> .fa').addClass('fa-spin');
  10. request(url, { method: 'post' }, (response) => {
  11. $('[data-2fa-image]').attr('src', response.image);
  12. $('[data-2fa-secret]').text(response.secret);
  13. $('[data-2fa-value]').val(response.secret.replace(' ', ''));
  14. element.removeAttr('disabled').find('> .fa').removeClass('fa-spin');
  15. });
  16. });
  17. const toggleSecret = () => {
  18. const toggle = $('#toggle_twofa_enabled1');
  19. const secret = $('.twofa-secret');
  20. secret[toggle.is(':checked') ? 'addClass' : 'removeClass']('show');
  21. };
  22. body.on('click', '.twofa-toggle input', toggleSecret);
  23. toggleSecret();