"use strict";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(a){jQuery("#generate-qr").prop("disabled",!1),e.removeClass("is-active"),a.success&&a.data&&a.data.qr_code?(jQuery("#qr-code-img-err").empty(),jQuery("#qr-code-img").attr("src",a.data.qr_code)):jQuery("#qr-code-img-err").html('<p class="errmsg">'+(a.data&&a.data.message?a.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>")}})}function sendEmailCode(){jQuery("#send-email").prop("disabled",!0);var e=jQuery("#email-status");e.html('<p class="okmsg">'+two_factor_auth.messages.sending_email+"</p>"),jQuery.ajax({url:two_factor_auth.ajaxurl,type:"POST",data:{action:"secnin_send_2fa_email",temp_token:two_factor_auth.temp_token},success:function(a){jQuery("#send-email").prop("disabled",!1),a.success?e.html('<p class="okmsg">'+a.data.message+"</p>"):e.html('<p class="errmsg">'+(a.data&&a.data.message?a.data.message:two_factor_auth.messages.email_error)+"</p>")},error:function(){jQuery("#send-email").prop("disabled",!1),e.html('<p class="errmsg">'+two_factor_auth.messages.network_error+"</p>")}})}jQuery(document).ready((function($){var e=jQuery("#twofa-form-verify"),a=jQuery("#twofa-code"),r=jQuery("#verify-2fa");jQuery(".qr-code").length&&generateQRCode(),jQuery(".email-2fa").length&&sendEmailCode(),a.on("input",(function(){var e=jQuery(this).val();e=(e=e.replace(/\D/g,"")).slice(0,6),jQuery(this).val(e),r.prop("disabled",6!==e.length)})),e.on("submit",(function(e){e.preventDefault();var t=a.val();jQuery("#twofa-verify-msg").html('<p class="okmsg">'+two_factor_auth.messages.verifying+"</p>"),r.prop("disabled",!0),a.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)):(r.prop("disabled",!1),a.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>"),r.prop("disabled",!1),a.prop("disabled",!1)}})})),jQuery(".skip-2fa-link").on("click",(function(e){e.preventDefault();var a=jQuery(".skip-2fa-link"),r=jQuery("#verify-2fa"),t=jQuery("#generate-qr"),s=jQuery("#send-email"),o=jQuery("#twofa-code");a.css("opacity","0.5").css("pointer-events","none"),r.prop("disabled",!0),t.prop("disabled",!0),s.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:(a.css("opacity","").css("pointer-events",""),r.prop("disabled",!1),t.prop("disabled",!1),s.prop("disabled",!1),o.prop("disabled",!1),alert(e.data.message||two_factor_auth.messages.unknown_error))},error:function(){a.css("opacity","").css("pointer-events",""),r.prop("disabled",!1),t.prop("disabled",!1),s.prop("disabled",!1),o.prop("disabled",!1),alert(two_factor_auth.messages.network_error)}})})),$("#generate-qr").on("click",(function(e){e.preventDefault(),generateQRCode()})),$("#send-email").on("click",(function(e){e.preventDefault(),sendEmailCode()}))}));