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 / totp.js

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

102 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(function($) {
2
3 // Render any QR codes on the page
4 $('.simbaotp_qr_container').qrcode({
5 'render': 'image',
6 'text': $('.simbaotp_qr_container:first').data('qrcode'),
7 });
8
9 function update_otp_code() {
10
11 $('.simba_current_otp').html('<em>'+simbatfa_totp.updating+'</em>');
12
13 var got_code = '';
14
15 $.post(simbatfa_totp.ajax_url, {
16 action: 'simbatfa_shared_ajax',
17 subaction: 'refreshotp',
18 nonce: simbatfa_totp.tfa_shared_nonce
19 }, function(response) {
20
21 try {
22 var resp = JSON.parse(response);
23 got_code = resp.code;
24 } catch(err) {
25 if ('' !== simbatfa_totp.also_try) {
26 alert(simbatfa_totp.response+" "+response);
27 }
28 console.log(response);
29 console.log(err);
30 }
31
32 if ('' === got_code && '' !== simbatfa_totp.also_try) {
33 $.post(simbatfa_totp.also_try, {
34 action: 'simbatfa_shared_ajax',
35 subaction: 'refreshotp',
36 nonce: simbatfa_totp.tfa_shared_nonce
37 }, function(response) {
38 try {
39 var resp = JSON.parse(response);
40 if (resp.code) {
41 $('.simba_current_otp').html(resp.code);
42 } else {
43 console.log(response);
44 console.log("TFA: no code found");
45 }
46 } catch(err) {
47 alert(simbatfa_totp.response+" "+response);
48 console.log(response);
49 console.log(err);
50 }
51 });
52 } else if ('' != got_code) {
53 $('.simba_current_otp').html(got_code);
54 } else {
55 console.log("TFA: no code found");
56 }
57 });
58 }
59
60 var min_refresh_after = 30;
61
62 if (0 == $('body.settings_page_two-factor-auth').length) {
63 $('.simba_current_otp').each(function(ind, obj) {
64 var refresh_after = $(obj).data('refresh_after');
65 if (refresh_after > 0 && refresh_after < min_refresh_after) {
66 min_refresh_after = refresh_after;
67 }
68 });
69
70 // Update after the given seconds, and then every 30 seconds
71 setTimeout(function() {
72 setInterval(update_otp_code, 30000)
73 update_otp_code();
74 }, min_refresh_after * 1000);
75 }
76
77 // Handle clicks on the 'refresh' link
78 $('.simbaotp_refresh').on('click', function(e) {
79 e.preventDefault();
80 update_otp_code();
81 });
82
83 $('#tfa_trusted_devices_box').on('click', '.simbatfa-trust-remove', function(e) {
84 e.preventDefault();
85 var device_id = $(this).data('trusted-device-id');
86 $(this).parents('.simbatfa_trusted_device').css('opacity', '0.5');
87 if ('undefined' !== typeof device_id) {
88 $.post(simbatfa_totp.ajax_url, {
89 action: 'simbatfa_shared_ajax',
90 subaction: 'untrust_device',
91 nonce: simbatfa_totp.tfa_shared_nonce,
92 device_id: device_id
93 }, function(response) {
94 var resp = JSON.parse(response);
95 if (resp.hasOwnProperty('trusted_list')) {
96 $('#tfa_trusted_devices_box_inner').html(resp.trusted_list);
97 }
98 });
99 }
100 });
101 });
102