PluginProbe
Two Factor Authentication / 1.14.14
Two Factor Authentication v1.14.14
1.12.2 1.13.0 1.14.10 1.14.11 1.14.14 1.14.15 1.14.16 1.14.17 1.14.23 1.14.24 1.14.26 1.14.27 1.14.3 1.14.4 1.14.5 1.14.7 1.14.8 1.15.5 1.16.0 1.2.10 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 All 98 releases
two-factor-authentication / simba-tfa / includes / frontend-settings.js

frontend-settings.js in Two Factor Authentication 1.14.14, at simba-tfa/includes/frontend-settings.js

123 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var tfa_query_leaving = false;
2
3 // Prevent accidental leaving if there are unsaved settings
4 window.onbeforeunload = function(e) {
5 if (tfa_query_leaving) {
6 e.returnValue = simba_tfa_frontend.ask;
7 return simba_tfa_frontend.ask;
8 }
9 }
10
11 jQuery(function($) {
12
13 $(".tfa_settings_form input, .tfa_settings_form textarea, .tfa_settings_form select" ).on('change', function() {
14 tfa_query_leaving = true;
15 });
16
17 $(".simbatfa_settings_save").on('click', function() {
18
19 $.blockUI({ message: '<div style="margin: 8px;font-size:150%;">'+simba_tfa_frontend.saving+'</div>' });
20
21 // https://stackoverflow.com/questions/10147149/how-can-i-override-jquerys-serialize-to-include-unchecked-checkboxes
22 var form_data = $('.tfa_settings_form input, .tfa_settings_form textarea, .tfa_settings_form select').serialize();
23
24 // Include unchecked checkboxes. Use filter to only include unchecked boxes.
25 $.each($('.tfa_settings_form input[type=checkbox]')
26 .filter(function(idx) {
27 return $(this).prop('checked') === false
28 }),
29 function(idx, el){
30 // attach matched element names to the form_data with a chosen value.
31 var emptyVal = '0';
32 form_data += '&' + $(el).attr('name') + '=' + emptyVal;
33 }
34 );
35
36 $.post(simba_tfa_frontend.ajax_url, {
37 action: 'tfa_frontend',
38 subaction: 'savesettings',
39 settings: form_data,
40 nonce: simba_tfa_frontend.nonce
41 }, function(response) {
42 var settings_saved = false;
43 try {
44 var resp = JSON.parse(response);
45 if (resp.hasOwnProperty('result')) {
46 settings_saved = true;
47 tfa_query_leaving = false;
48 // Allow user code to respond
49 $(document).trigger('tfa_settings_saved', resp);
50 }
51
52 if (resp.hasOwnProperty('message')) {
53 alert(resp.message);
54 }
55
56 if (resp.hasOwnProperty('qr')) {
57 $('.simbaotp_qr_container').data('qrcode', resp['qr']).empty().qrcode({
58 "render": "image",
59 "text": resp['qr'],
60 });
61 }
62
63 if (resp.hasOwnProperty('al_type_disp')) {
64 $("#al_type_name").html(resp['al_type_disp']['disp']);
65 $("#al_type_desc").html(resp['al_type_disp']['desc']);
66 }
67
68 } catch(err) {
69 console.log(err);
70 console.log(response);
71 if ('' === simba_tfa_frontend.also_try) {
72 alert(simba_tfa_frontend.response+response);
73 }
74 }
75 if ('' != simba_tfa_frontend.also_try) {
76 if (!settings_saved) {
77 $.post(simba_tfa_frontend.also_try, {
78 action: 'tfa_frontend',
79 subaction: 'savesettings',
80 settings: form_data,
81 nonce: simba_tfa_frontend.nonce
82 }, function(response) {
83
84 try {
85 var resp = JSON.parse(response);
86 if (resp.hasOwnProperty('result')) {
87 settings_saved = true;
88 tfa_query_leaving = false;
89 // Allow user code to respond
90 $(document).trigger('tfa_settings_saved', resp);
91 }
92 if (resp.hasOwnProperty('message')) {
93 alert(resp.message);
94 }
95 if (resp.hasOwnProperty('qr')) {
96 $('.simbaotp_qr_container').data('qrcode', resp['qr']).empty().qrcode({
97 "render": "image",
98 "text": resp['qr'],
99 });
100 }
101 if (resp.hasOwnProperty('al_type_disp')) {
102 $("#al_type_name").html(resp['al_type_disp']['disp']);
103 $("#al_type_desc").html(resp['al_type_disp']['desc']);
104 }
105
106 } catch(err) {
107 console.log(err);
108 console.log(response);
109 alert(simba_tfa_frontend.response+response);
110 }
111 $.unblockUI();
112 });
113 } else {
114 $.unblockUI();
115 }
116 } else {
117 $.unblockUI();
118 }
119 });
120
121 });
122 });
123