##// END OF EJS Templates
2fa: recovery codes copy
super-admin -
r5361:965120af default
parent child Browse files
Show More
@@ -31,14 +31,9 b''
31 </div>
31 </div>
32 <button id="saveBtn" class="btn btn-primary" ${'disabled' if c.locked_2fa else ''}>${_('Save')}</button>
32 <button id="saveBtn" class="btn btn-primary" ${'disabled' if c.locked_2fa else ''}>${_('Save')}</button>
33 </div>
33 </div>
34 <div id="codesPopup" class="modal">
35 <div class="modal-content">
36 <ul id="recoveryCodesList"></ul>
37 <button id="copyAllBtn" class="btn btn-primary">Copy All</button>
38 </div>
39 </div>
40 </div>
34 </div>
41 </div>
35 </div>
36
42 % if c.state_of_2fa:
37 % if c.state_of_2fa:
43 <div class="panel panel-default">
38 <div class="panel panel-default">
44 <div class="panel-heading">
39 <div class="panel-heading">
@@ -54,22 +49,19 b''
54 </div>
49 </div>
55
50
56 </div>
51 </div>
52
57 % endif
53 % endif
54
58 <script>
55 <script>
59 function submitForm() {
56 function submitForm() {
60 let formData = new FormData(document.getElementById("2faForm"));
57 let formData = new FormData(document.getElementById("2faForm"));
61 let xhr = new XMLHttpRequest();
58 let xhr = new XMLHttpRequest();
59
62 let success = function (response) {
60 let success = function (response) {
63 let recovery_codes = response.recovery_codes;
61 let recovery_codes = response.recovery_codes;
64 const codesList = document.getElementById("recoveryCodesList");
62 showRecoveryCodesPopup(recovery_codes);
63 }
65
64
66 codesList.innerHTML = "";
67 recovery_codes.forEach(code => {
68 const listItem = document.createElement("li");
69 listItem.textContent = code;
70 codesList.appendChild(listItem);
71 });
72 }
73 xhr.onreadystatechange = function () {
65 xhr.onreadystatechange = function () {
74 if (xhr.readyState == 4 && xhr.status == 200) {
66 if (xhr.readyState == 4 && xhr.status == 200) {
75 let responseDoc = new DOMParser().parseFromString(xhr.responseText, "text/html");
67 let responseDoc = new DOMParser().parseFromString(xhr.responseText, "text/html");
@@ -79,7 +71,6 b''
79 } else {
71 } else {
80 let regenerate_url = pyroutes.url('my_account_regenerate_2fa_recovery_codes');
72 let regenerate_url = pyroutes.url('my_account_regenerate_2fa_recovery_codes');
81 ajaxPOST(regenerate_url, {'csrf_token': CSRF_TOKEN}, success);
73 ajaxPOST(regenerate_url, {'csrf_token': CSRF_TOKEN}, success);
82 showRecoveryCodesPopup();
83 }
74 }
84 }
75 }
85 };
76 };
@@ -87,8 +78,7 b''
87 xhr.open("POST", url, true);
78 xhr.open("POST", url, true);
88 xhr.send(formData);
79 xhr.send(formData);
89 }
80 }
90 </script>
81
91 <script>
92 document.getElementById('2faEnabled').addEventListener('click', function () {
82 document.getElementById('2faEnabled').addEventListener('click', function () {
93 document.getElementById('2faDisabled').checked = false;
83 document.getElementById('2faDisabled').checked = false;
94 });
84 });
@@ -109,32 +99,25 b''
109 let post_data = {'state': state, 'csrf_token': CSRF_TOKEN};
99 let post_data = {'state': state, 'csrf_token': CSRF_TOKEN};
110 let url = pyroutes.url('my_account_configure_2fa');
100 let url = pyroutes.url('my_account_configure_2fa');
111
101
112 ajaxPOST(url, post_data, null)
102 ajaxPOST(url, post_data, function(){}, function(){})
113 };
103 }
104
114 document.getElementById('saveBtn').addEventListener('click', function () {
105 document.getElementById('saveBtn').addEventListener('click', function () {
115 var state = getStateValue();
106 var state = getStateValue();
116 saveChanges(state);
107 saveChanges(state);
117 });
108 });
118 </script>
109
119 <script>
110 function showRecoveryCodesPopup(recoveryCodes) {
120 function showRecoveryCodesPopup() {
111 let funcData = {'recoveryCodes': recoveryCodes}
121 const popup = document.getElementById("codesPopup");
112 let recoveryCodesHtml = renderTemplate('recoveryCodes', funcData)
122 popup.style.display = "block";
113
114 SwalNoAnimation.fire({
115 allowOutsideClick: false,
116 confirmButtonText: _gettext('I Copied the codes'),
117 title: _gettext('2FA Recovery Codes'),
118 html: recoveryCodesHtml
119 })
120
123 }
121 }
124
122
125 document.getElementById("copyAllBtn").addEventListener("click", function () {
126 const codesListItems = document.querySelectorAll("#recoveryCodesList li");
127 const allCodes = Array.from(codesListItems).map(item => item.textContent).join(", ");
128
129 const textarea = document.createElement('textarea');
130 textarea.value = allCodes;
131 document.body.appendChild(textarea);
132
133 textarea.select();
134 document.execCommand('copy');
135
136 document.body.removeChild(textarea);
137 const popup = document.getElementById("codesPopup");
138 popup.style.display = ""
139 });
140 </script>
123 </script>
General Comments 0
You need to be logged in to leave comments. Login now