| 1 |
document.addEventListener( 'DOMContentLoaded', function() { jQuery( document ).ready( function( $ ) { |
| 2 |
var dologin_can_submit_user = ''; |
| 3 |
var dologin_can_submit_bypass = false; |
| 4 |
|
| 5 |
function dologin_cb( e ) |
| 6 |
{ |
| 7 |
var dologin_user_handler = '#user_login'; |
| 8 |
if ( $( this ).find( '#username' ).length ) { |
| 9 |
dologin_user_handler = '#username'; |
| 10 |
} |
| 11 |
|
| 12 |
if ( dologin_can_submit_user && dologin_can_submit_user == $( dologin_user_handler ).val() ) { |
| 13 |
return true; |
| 14 |
} |
| 15 |
|
| 16 |
if ( dologin_can_submit_bypass ) { |
| 17 |
return true; |
| 18 |
} |
| 19 |
|
| 20 |
e.preventDefault(); |
| 21 |
|
| 22 |
$( '#dologin-process' ).show(); |
| 23 |
$( '#dologin-process-msg' ).attr( 'class', 'dologin-spinner' ).html( '' ); |
| 24 |
|
| 25 |
// Append the submit button for 2nd time submission |
| 26 |
var submit_btn = $( this ).find( '[type=submit]' ).first(); |
| 27 |
if ( ! $( this ).find( '[type="hidden"][name="' + submit_btn.attr( 'name' ) + '"]' ).length ) { |
| 28 |
$( this ).append( '<input type="hidden" name="' + submit_btn.attr( 'name' ) + '" value="' + submit_btn.val() + '" />' ); |
| 29 |
} |
| 30 |
|
| 31 |
var that = this; |
| 32 |
|
| 33 |
$.ajax( { |
| 34 |
url: dologin.login_url, |
| 35 |
type: 'POST', |
| 36 |
data: $( this ).serialize(), |
| 37 |
dataType: 'json', |
| 38 |
success: function( res ) { |
| 39 |
if ( res._res !== 'ok' ) { |
| 40 |
$( '#dologin-process-msg' ).attr( 'class', 'dologin-danger' ).html( res._msg ); |
| 41 |
$( '#dologin-two_factor_code' ).attr( 'required', false ); |
| 42 |
$( '#dologin-dynamic_code' ).hide(); |
| 43 |
} else { |
| 44 |
// If no phone set in profile |
| 45 |
if ( 'bypassed' in res ) { |
| 46 |
dologin_can_submit_bypass = true; |
| 47 |
$( that ).submit(); |
| 48 |
return; |
| 49 |
} |
| 50 |
$( '#dologin-process-msg' ).attr( 'class', 'dologin-success' ).html( res.info ); |
| 51 |
$( '#dologin-dynamic_code' ).show(); |
| 52 |
$( '#dologin-two_factor_code' ).attr( 'required', true ); |
| 53 |
dologin_can_submit_user = $( dologin_user_handler ).val(); |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
} ); |
| 58 |
} |
| 59 |
|
| 60 |
$('#loginform').on("submit", dologin_cb ); |
| 61 |
$('.woocommerce-form-login').on("submit", dologin_cb ); |
| 62 |
// $('.tml-login form[name="loginform"], .tml-login form[name="login"], #wpmem_login form, form#ihc_login_form').submit( dologin_cb ); |
| 63 |
|
| 64 |
} ); } ); |