All files / app/assets/javascripts/authentication/two_factor_auth index.js

57.14% Statements 12/21
16.66% Branches 2/12
66.66% Functions 4/6
57.14% Lines 12/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81              1x                                                               1x 2x   2x       2x   2x     2x                   1x 1x   1x       1x     1x                  
import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import { updateHistory, removeParams } from '~/lib/utils/url_utility';
import ManageTwoFactorForm from './components/manage_two_factor_form.vue';
import RecoveryCodes from './components/recovery_codes.vue';
import { SUCCESS_QUERY_PARAM } from './constants';
 
export const initManageTwoFactorForm = () => {
  const el = document.querySelector('.js-manage-two-factor-form');
 
  if (!el) {
    return false;
  }
 
  const {
    currentPasswordRequired,
    profileTwoFactorAuthPath = '',
    profileTwoFactorAuthMethod = '',
    codesProfileTwoFactorAuthPath = '',
    codesProfileTwoFactorAuthMethod = '',
  } = el.dataset;
 
  const isCurrentPasswordRequired = parseBoolean(currentPasswordRequired);
 
  return new Vue({
    el,
    provide: {
      isCurrentPasswordRequired,
      profileTwoFactorAuthPath,
      profileTwoFactorAuthMethod,
      codesProfileTwoFactorAuthPath,
      codesProfileTwoFactorAuthMethod,
    },
    render(createElement) {
      return createElement(ManageTwoFactorForm);
    },
  });
};
 
export const initRecoveryCodes = () => {
  const el = document.querySelector('.js-2fa-recovery-codes');
 
  Iif (!el) {
    return false;
  }
 
  const { codes = '[]', profileAccountPath = '' } = el.dataset;
 
  return new Vue({
    el,
    render(createElement) {
      return createElement(RecoveryCodes, {
        props: {
          codes: JSON.parse(codes),
          profileAccountPath,
        },
      });
    },
  });
};
 
export const initClose2faSuccessMessage = () => {
  const closeButton = document.querySelector('.js-close-2fa-enabled-success-alert');
 
  Iif (!closeButton) {
    return;
  }
 
  closeButton.addEventListener(
    'click',
    () => {
      updateHistory({
        url: removeParams([SUCCESS_QUERY_PARAM]),
        title: document.title,
        replace: true,
      });
    },
    { once: true },
  );
};