PluginProbe
Two Factor Authentication / 1.2.16
Two Factor Authentication v1.2.16
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 / includes / wooextend.js

wooextend.js in Two Factor Authentication 1.2.16, at includes/wooextend.js

96 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2
3 var submit_can_proceed = false;
4
5 // See if WooCommerce or Affiliate WP login form is present
6 if($('.woocommerce form.login').length > 0) {
7 var tfa_wc_form = $('.woocommerce form.login').first();
8 var tfa_wc_user_field = $('.woocommerce [name=username]').first();
9 var tfa_wc_pass_field = $('.woocommerce [name=password]').first();
10 var tfa_wc_submit_btn = $('.woocommerce [name=login]').first();
11 } else if ($('#affwp-login-form').length > 0) {
12 var tfa_wc_form = $('#affwp-login-form').first();
13 var tfa_wc_user_field = $('#affwp-login-user-login, #affwp-user-login').first();
14 var tfa_wc_pass_field = $('#affwp-login-user-pass, #affwp-user-pass').first();
15 var tfa_wc_submit_btn = $('#affwp-login-form input[type=submit]').first();
16 }
17
18 if ('undefined' != typeof tfa_wc_form) {
19
20 var tfa_wc_p = document.createElement('p');
21 tfa_wc_p.id = 'tfa_wc_holder';
22 tfa_wc_p.style.display = 'none';
23 tfa_wc_p.style.marginBottom = '15px';
24
25 $(tfa_wc_p).insertBefore(tfa_wc_submit_btn);
26
27 var p = document.getElementById('tfa_wc_holder');
28 var lbl = document.createElement('label');
29 lbl.for = 'two_factor_auth';
30 var lbl_text = document.createTextNode(simbatfa_wc_settings.otp+' '+simbatfa_wc_settings.otp_login_help);
31 lbl.appendChild(lbl_text);
32
33 var tfa_field = document.createElement('input');
34 tfa_field.type = 'text';
35 tfa_field.id = 'two_factor_auth';
36 tfa_field.name = 'two_factor_code';
37 tfa_field.className = 'input-text';
38 // tfa_field.style = 'margin-left: 10px; padding-left: 10px;';
39 // lbl.appendChild(tfa_field);
40
41 //Remove button
42 // p.removeChild(document.getElementById('tfa_wc_otp-button'));
43
44 //Add text and input field
45 p.appendChild(lbl);
46 p.appendChild(tfa_field);
47 // tfa_field.focus();
48
49 }
50
51 $(tfa_wc_form).on('submit', function(e) {
52
53 if (submit_can_proceed) { return true; }
54
55 e.preventDefault();
56 //Check so a username is entered.
57 if(tfa_wc_user_field.val().length < 1)
58 {
59 alert(simbatfa_wc_settings.enter_username_first);
60 return false;
61 }
62
63 if (simbatfa_wc_settings.hasOwnProperty('spinnerimg')) {
64 $('label[for="rememberme"], #affwp-login-form input[type=submit]').after('<img class="simbaotp_spinner" src="'+simbatfa_wc_settings.spinnerimg+'" style="margin-left: 4px;height: 20px; position: relative; top: 4px; border:0px; box-shadow:none;">');
65 }
66
67 $.ajax({
68 url: simbatfa_wc_settings.ajaxurl,
69 type: 'POST',
70 data: {
71 action: 'simbatfa-init-otp',
72 user: tfa_wc_user_field.val()
73 },
74 dataType: 'json',
75 success: function(response) {
76 submit_can_proceed = true;
77 if (response.status == true) {
78 $('.simbaotp_spinner').remove();
79 tfaShowOTPField();
80 } else {
81 $(tfa_wc_form).find('input[type="submit"]:first').click();
82 }
83 }
84 });
85
86 // $(tfa_wc_form).off();
87
88 });
89
90 function tfaShowOTPField() {
91 $(tfa_wc_user_field).parent().hide();
92 $(tfa_wc_pass_field).parent().hide();
93 $('#tfa_wc_holder').slideDown().find('input[name="two_factor_code"]').focus();
94 }
95
96 });