##// 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 31 </div>
32 32 <button id="saveBtn" class="btn btn-primary" ${'disabled' if c.locked_2fa else ''}>${_('Save')}</button>
33 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 34 </div>
39 35 </div>
40 </div>
41 </div>
36
42 37 % if c.state_of_2fa:
43 38 <div class="panel panel-default">
44 39 <div class="panel-heading">
@@ -54,22 +49,19 b''
54 49 </div>
55 50
56 51 </div>
52
57 53 % endif
54
58 55 <script>
59 56 function submitForm() {
60 57 let formData = new FormData(document.getElementById("2faForm"));
61 58 let xhr = new XMLHttpRequest();
59
62 60 let success = function (response) {
63 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 65 xhr.onreadystatechange = function () {
74 66 if (xhr.readyState == 4 && xhr.status == 200) {
75 67 let responseDoc = new DOMParser().parseFromString(xhr.responseText, "text/html");
@@ -79,7 +71,6 b''
79 71 } else {
80 72 let regenerate_url = pyroutes.url('my_account_regenerate_2fa_recovery_codes');
81 73 ajaxPOST(regenerate_url, {'csrf_token': CSRF_TOKEN}, success);
82 showRecoveryCodesPopup();
83 74 }
84 75 }
85 76 };
@@ -87,8 +78,7 b''
87 78 xhr.open("POST", url, true);
88 79 xhr.send(formData);
89 80 }
90 </script>
91 <script>
81
92 82 document.getElementById('2faEnabled').addEventListener('click', function () {
93 83 document.getElementById('2faDisabled').checked = false;
94 84 });
@@ -109,32 +99,25 b''
109 99 let post_data = {'state': state, 'csrf_token': CSRF_TOKEN};
110 100 let url = pyroutes.url('my_account_configure_2fa');
111 101
112 ajaxPOST(url, post_data, null)
113 };
102 ajaxPOST(url, post_data, function(){}, function(){})
103 }
104
114 105 document.getElementById('saveBtn').addEventListener('click', function () {
115 106 var state = getStateValue();
116 107 saveChanges(state);
117 108 });
118 </script>
119 <script>
120 function showRecoveryCodesPopup() {
121 const popup = document.getElementById("codesPopup");
122 popup.style.display = "block";
109
110 function showRecoveryCodesPopup(recoveryCodes) {
111 let funcData = {'recoveryCodes': recoveryCodes}
112 let recoveryCodesHtml = renderTemplate('recoveryCodes', funcData)
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 123 </script>
General Comments 0
You need to be logged in to leave comments. Login now