<?php


namespace OTP\Handler\Forms;

use OTP\Helper\FormSessionVars;
use OTP\Helper\MoOTPDocs;
use OTP\Helper\MoUtility;
use OTP\Helper\SessionUtils;
use OTP\Objects\BaseMessages;
use OTP\Objects\FormHandler;
use OTP\Objects\IFormHandler;
use OTP\Objects\VerificationLogic;
use OTP\Objects\VerificationType;
use OTP\Traits\Instance;
use ReflectionException;
use WP_Error;
class MemberPressRegistrationForm extends FormHandler implements IFormHandler
{
    use Instance;
    protected function __construct()
    {
        $this->_isLoginOrSocialForm = FALSE;
        $this->_isAjaxForm = FALSE;
        $this->_formSessionVar = FormSessionVars::MEMBERPRESS_REG;
        $this->_typePhoneTag = "\x6d\157\x5f\155\162\x70\137\x70\x68\x6f\156\x65\137\145\x6e\141\142\154\145";
        $this->_typeEmailTag = "\155\157\137\155\162\160\137\x65\155\141\151\154\137\145\156\141\142\154\145";
        $this->_typeBothTag = "\155\157\137\x6d\x72\x70\137\x62\x6f\164\150\137\145\x6e\141\x62\154\145";
        $this->_formName = mo_("\x4d\145\155\142\145\x72\120\162\145\163\163\x20\x52\x65\147\151\x73\164\x72\141\164\151\157\156\40\x46\x6f\162\155");
        $this->_formKey = "\x4d\105\115\x42\x45\x52\x50\122\x45\123\x53";
        $this->_isFormEnabled = get_mo_option("\x6d\x72\x70\137\144\x65\x66\141\165\x6c\x74\137\x65\156\141\142\154\x65");
        $this->_formDocuments = MoOTPDocs::MRP_FORM_LINK;
        parent::__construct();
    }
    function handleForm()
    {
        $this->_byPassLogin = get_mo_option("\155\162\x70\137\141\x6e\x6f\x6e\137\x6f\x6e\x6c\x79");
        $this->_phoneKey = get_mo_option("\x6d\162\x70\137\160\150\x6f\x6e\x65\x5f\153\145\171");
        $this->_otpType = get_mo_option("\x6d\162\160\137\145\156\141\142\154\145\137\164\x79\160\145");
        $this->_phoneFormId = "\151\156\x70\x75\164\133\x6e\141\155\x65\x3d" . $this->_phoneKey . "\x5d";
        add_filter("\x6d\145\160\162\x2d\x76\x61\x6c\x69\144\x61\x74\x65\55\x73\151\147\x6e\165\160", array($this, "\155\151\156\151\157\162\141\x6e\x67\145\137\x73\151\x74\145\137\162\x65\147\x69\163\x74\x65\162\137\146\x6f\x72\x6d"), 99, 1);
    }
    function miniorange_site_register_form($errors)
    {
        if (!($this->_byPassLogin && is_user_logged_in())) {
            goto pV3;
        }
        return $errors;
        pV3:
        $F6 = $_POST;
        $sP = '';
        if (!$this->isPhoneVerificationEnabled()) {
            goto HzC;
        }
        $sP = $_POST[$this->_phoneKey];
        $errors = $this->validatePhoneNumberField($errors);
        HzC:
        if (!(is_array($errors) && !empty($errors))) {
            goto pNt;
        }
        return $errors;
        pNt:
        if (!$this->checkIfVerificationIsComplete()) {
            goto Dqu;
        }
        return $errors;
        Dqu:
        MoUtility::initialize_transaction($this->_formSessionVar);
        $errors = new WP_Error();
        foreach ($_POST as $yU => $Fo) {
            if ($yU == "\x75\x73\145\x72\137\x66\x69\x72\x73\164\137\156\141\x6d\145") {
                goto GzX;
            }
            if ($yU == "\165\x73\x65\x72\x5f\x65\x6d\141\151\x6c") {
                goto qC3;
            }
            if ($yU == "\155\145\160\162\x5f\165\163\x65\x72\x5f\x70\x61\x73\x73\167\157\x72\144") {
                goto AcB;
            }
            $yJ[$yU] = $Fo;
            goto Smt;
            GzX:
            $lQ = $Fo;
            goto Smt;
            qC3:
            $R7 = $Fo;
            goto Smt;
            AcB:
            $xy = $Fo;
            Smt:
            sTQ:
        }
        Tsx:
        $yJ["\165\x73\x65\x72\x6d\145\x74\x61"] = $F6;
        $this->startVerificationProcess($lQ, $R7, $errors, $sP, $xy, $yJ);
        return $errors;
    }
    function validatePhoneNumberField($errors)
    {
        global $phoneLogic;
        if (!MoUtility::sanitizeCheck($this->_phoneKey, $_POST)) {
            goto mXb;
        }
        if (MoUtility::validatePhoneNumber($_POST[$this->_phoneKey])) {
            goto f3Q;
        }
        $errors[] = $phoneLogic->_get_otp_invalid_format_message();
        f3Q:
        goto Q6K;
        mXb:
        $errors[] = mo_("\x50\x68\x6f\x6e\145\x20\x6e\x75\155\x62\x65\162\x20\x66\151\x65\x6c\x64\40\x63\x61\x6e\40\x6e\157\x74\x20\142\x65\40\142\154\141\156\x6b");
        Q6K:
        return $errors;
    }
    function startVerificationProcess($lQ, $R7, $errors, $sP, $xy, $yJ)
    {
        if (strcasecmp($this->_otpType, $this->_typePhoneTag) == 0) {
            goto A5H;
        }
        if (strcasecmp($this->_otpType, $this->_typeBothTag) == 0) {
            goto l2J;
        }
        $this->sendChallenge($lQ, $R7, $errors, $sP, VerificationType::EMAIL, $xy, $yJ);
        goto QJ6;
        A5H:
        $this->sendChallenge($lQ, $R7, $errors, $sP, VerificationType::PHONE, $xy, $yJ);
        goto QJ6;
        l2J:
        $this->sendChallenge($lQ, $R7, $errors, $sP, VerificationType::BOTH, $xy, $yJ);
        QJ6:
    }
    function checkIfVerificationIsComplete()
    {
        if (!SessionUtils::isStatusMatch($this->_formSessionVar, self::VALIDATED, $this->getVerificationType())) {
            goto xwa;
        }
        $this->unsetOTPSessionVariables();
        return TRUE;
        xwa:
        return FALSE;
    }
    function moMRPgetphoneFieldId()
    {
        global $wpdb;
        return $wpdb->get_var("\123\x45\x4c\105\103\124\40\x69\x64\40\106\x52\117\115\40{$wpdb->prefix}\x62\160\137\170\160\x72\x6f\x66\151\154\x65\137\x66\151\145\154\144\163\40\x77\x68\145\162\145\x20\x6e\x61\x6d\x65\x20\75\x27" . $this->_phoneKey . "\47");
    }
    function handle_post_verification($TG, $te, $j4, $xy, $sP, $yJ, $Cw)
    {
        SessionUtils::addStatus($this->_formSessionVar, self::VALIDATED, $Cw);
    }
    function handle_failed_verification($te, $j4, $sP, $Cw)
    {
        if (SessionUtils::isOTPInitialized($this->_formSessionVar)) {
            goto KFN;
        }
        return;
        KFN:
        $HK = $this->getVerificationType();
        $Qg = $HK === VerificationType::BOTH ? TRUE : FALSE;
        miniorange_site_otp_validation_form($te, $j4, $sP, MoUtility::_get_invalid_otp_method(), $HK, $Qg);
    }
    public function getPhoneNumberSelector($fv)
    {
        if (!(self::isFormEnabled() && $this->isPhoneVerificationEnabled())) {
            goto rRa;
        }
        array_push($fv, $this->_phoneFormId);
        rRa:
        return $fv;
    }
    function isPhoneVerificationEnabled()
    {
        $Cw = $this->getVerificationType();
        return $Cw === VerificationType::PHONE || $Cw === VerificationType::BOTH;
    }
    public function unsetOTPSessionVariables()
    {
        SessionUtils::unsetSession(array($this->_txSessionId, $this->_formSessionVar));
    }
    function handleFormOptions()
    {
        if (MoUtility::areFormOptionsBeingSaved($this->getFormOption())) {
            goto R6_;
        }
        return;
        R6_:
        $this->_isFormEnabled = $this->sanitizeFormPOST("\155\162\x70\137\144\x65\x66\x61\x75\154\164\x5f\x65\x6e\141\142\x6c\145");
        $this->_otpType = $this->sanitizeFormPOST("\x6d\162\x70\x5f\145\156\x61\x62\154\145\137\164\171\160\x65");
        $this->_phoneKey = $this->sanitizeFormPOST("\x6d\162\160\137\x70\150\x6f\156\145\137\146\151\145\x6c\x64\137\x6b\145\171");
        $this->_byPassLogin = $this->sanitizeFormPOST("\x6d\160\x72\137\x61\156\157\x6e\137\x6f\156\x6c\171");
        if (!$this->basicValidationCheck(BaseMessages::MEMBERPRESS_CHOOSE)) {
            goto dew;
        }
        update_mo_option("\155\x72\160\137\x64\145\146\x61\x75\154\x74\137\145\x6e\141\x62\154\x65", $this->_isFormEnabled);
        update_mo_option("\155\162\x70\x5f\145\x6e\141\x62\x6c\x65\137\164\x79\x70\x65", $this->_otpType);
        update_mo_option("\x6d\162\x70\x5f\x70\150\157\x6e\x65\x5f\153\145\x79", $this->_phoneKey);
        update_mo_option("\x6d\162\160\137\x61\x6e\157\x6e\137\157\156\x6c\171", $this->_byPassLogin);
        dew:
    }
}
