function generateQRCode(){jQuery("#generate-qr").prop("disabled",!0);var e=jQuery(".qr-code .spinner");e.addClass("is-active"),jQuery("#qr-code-img-err").empty(),jQuery.ajax({url:two_factor_auth.ajaxurl,type:"POST",data:{action:"secnin_generate_qr_code",temp_token:two_factor_auth.temp_token},success:function(r){jQuery("#generate-qr").prop("disabled",!1),e.removeClass("is-active"),r.success&&r.data&&r.data.qr_code?(jQuery("#qr-code-img-err").empty(),jQuery("#qr-code-img").attr("src",r.data.qr_code)):jQuery("#qr-code-img-err").html('<p class="errmsg">'+(r.data&&r.data.message?r.data.message:two_factor_auth.messages.qr_error)+"</p>")},error:function(){jQuery("#generate-qr").prop("disabled",!1),e.removeClass("is-active"),jQuery("#qr-code-img-err").html('<p class="errmsg">'+two_factor_auth.messages.network_error+"</p>")}})}jQuery(document).ready((function($){var e=jQuery("#twofa-form-verify"),r=jQuery("#twofa-code"),a=jQuery("#verify-2fa");jQuery(".qr-code").length&&generateQRCode(),r.on("input",(function(){var e=jQuery(this).val();e=(e=e.replace(/\D/g,"")).slice(0,6),jQuery(this).val(e),a.prop("disabled",6!==e.length)})),e.on("submit",(function(e){e.preventDefault();var t=r.val();jQuery("#twofa-verify-msg").html('<p class="okmsg">'+two_factor_auth.messages.verifying+"</p>"),a.prop("disabled",!0),r.prop("disabled",!0),$.ajax({url:two_factor_auth.ajaxurl,type:"POST",data:{action:"secnin_verify_2fa_code",code:t,nonce:two_factor_auth.verify_nonce,temp_token:two_factor_auth.temp_token,user_id:two_factor_auth.user_id,user_ip:two_factor_auth.user_ip,user_agent:two_factor_auth.user_agent},success:function(e){e.success?(jQuery("#twofa-verify-msg").html('<p class="okmsg">'+e.data.message+"</p>"),setTimeout((function(){window.location.href=e.data.redir_to}),1e3)):(a.prop("disabled",!1),r.prop("disabled",!1),jQuery("#twofa-verify-msg").html('<p class="errmsg">'+e.data.message+"</p>"))},error:function(){jQuery("#twofa-verify-msg").html('<p class="errmsg">'+two_factor_auth.messages.network_error+"</p>"),a.prop("disabled",!1),r.prop("disabled",!1)}})})),jQuery(".skip-2fa-link").on("click",(function(e){e.preventDefault();var r=jQuery(".skip-2fa-link"),a=jQuery("#verify-2fa"),t=jQuery("#generate-qr"),o=jQuery("#twofa-code");r.css("opacity","0.5").css("pointer-events","none"),a.prop("disabled",!0),t.prop("disabled",!0),o.prop("disabled",!0),jQuery.ajax({url:two_factor_auth.ajaxurl,type:"POST",data:{action:"secnin_skip_2fa",temp_token:two_factor_auth.temp_token},success:function(e){e.success?window.location.href=e.data.redirect_url:(r.css("opacity","").css("pointer-events",""),a.prop("disabled",!1),t.prop("disabled",!1),o.prop("disabled",!1),alert(e.data.message||two_factor_auth.messages.unknown_error))},error:function(){r.css("opacity","").css("pointer-events",""),a.prop("disabled",!1),t.prop("disabled",!1),o.prop("disabled",!1),alert(two_factor_auth.messages.network_error)}})})),$("#generate-qr").on("click",(function(e){e.preventDefault(),generateQRCode()}))}));