<?php


namespace OTP\Handler\Forms;

use OTP\Helper\FormSessionVars;
use OTP\Helper\MoOTPDocs;
use OTP\Helper\MoUtility;
use OTP\Helper\SessionUtils;
use OTP\Objects\FormHandler;
use OTP\Objects\IFormHandler;
use OTP\Objects\VerificationType;
use OTP\Traits\Instance;
use ReflectionException;
use XooUserRegister;
use XooUserRegisterLite;
class UserUltraRegistrationForm extends FormHandler implements IFormHandler
{
    use Instance;
    protected function __construct()
    {
        $this->_isLoginOrSocialForm = FALSE;
        $this->_isAjaxForm = FALSE;
        $this->_formSessionVar = FormSessionVars::UULTRA_REG;
        $this->_typePhoneTag = "\155\157\137\165\165\154\164\x72\x61\x5f\x70\150\157\x6e\x65\x5f\145\x6e\141\142\154\x65";
        $this->_typeEmailTag = "\x6d\x6f\x5f\165\165\x6c\x74\162\x61\x5f\x65\155\141\x69\154\137\x65\x6e\x61\x62\154\145";
        $this->_typeBothTag = "\x6d\157\x5f\165\165\x6c\x74\x72\x61\137\x62\157\164\150\137\x65\156\x61\x62\154\x65";
        $this->_formKey = "\125\x55\x4c\x54\122\x41\137\106\x4f\122\115";
        $this->_formName = mo_("\x55\163\145\x72\40\x55\154\164\162\x61\x20\122\x65\147\x69\x73\164\162\x61\x74\151\157\156\x20\x46\x6f\x72\155");
        $this->_isFormEnabled = get_mo_option("\x75\x75\x6c\164\162\141\x5f\144\145\146\141\x75\154\164\x5f\145\156\x61\142\x6c\x65");
        $this->_formDocuments = MoOTPDocs::UULTRA_FORM_LINK;
        parent::__construct();
    }
    function handleForm()
    {
        $this->_phoneKey = get_mo_option("\x75\x75\x6c\164\162\141\x5f\160\150\x6f\156\145\x5f\153\x65\x79");
        $this->_otpType = get_mo_option("\165\165\154\164\162\x61\137\145\x6e\141\x62\x6c\x65\x5f\x74\171\160\x65");
        $this->_phoneFormId = "\x69\156\x70\165\x74\133\x6e\141\x6d\x65\75" . $this->_phoneKey . "\135";
        $HK = $this->getVerificationType();
        if (MoUtility::sanitizeCheck("\170\x6f\x6f\165\x73\x65\x72\165\x6c\164\162\141\x2d\x72\145\x67\x69\163\x74\x65\162\55\x66\x6f\162\155", $_POST)) {
            goto MC;
        }
        return;
        MC:
        $s9 = $this->isPhoneVerificationEnabled() ? $_POST[$this->_phoneKey] : NULL;
        $this->_handle_uultra_form_submit($_POST["\x75\x73\145\x72\x5f\x6c\x6f\147\151\156"], $_POST["\x75\x73\x65\x72\x5f\145\155\x61\151\x6c"], $s9);
    }
    function isPhoneVerificationEnabled()
    {
        $HK = $this->getVerificationType();
        return $HK == VerificationType::PHONE || $HK === VerificationType::BOTH;
    }
    function _handle_uultra_form_submit($F1, $j4, $s9)
    {
        $C3 = class_exists("\x58\x6f\157\x55\x73\x65\x72\122\x65\x67\151\163\164\x65\x72\114\151\164\145") ? new XooUserRegisterLite() : new XooUserRegister();
        if (!SessionUtils::isOTPInitialized($this->_formSessionVar)) {
            goto eq;
        }
        return;
        eq:
        $C3->uultra_prepare_request($_POST);
        $C3->uultra_handle_errors();
        if (!MoUtility::isBlank($C3->errors)) {
            goto q9;
        }
        $_POST["\x6e\x6f\137\143\141\160\x74\143\150\141"] = "\x79\145\163";
        $this->_handle_otp_verification_uultra($F1, $j4, null, $s9);
        q9:
        return;
    }
    function _handle_otp_verification_uultra($F1, $j4, $errors, $s9)
    {
        MoUtility::initialize_transaction($this->_formSessionVar);
        if (strcasecmp($this->_otpType, $this->_typePhoneTag) == 0) {
            goto N0;
        }
        if (strcasecmp($this->_otpType, $this->_typeBothTag) == 0) {
            goto hy;
        }
        $this->sendChallenge($F1, $j4, $errors, $s9, VerificationType::EMAIL);
        goto S9;
        hy:
        $this->sendChallenge($F1, $j4, $errors, $s9, VerificationType::BOTH);
        S9:
        goto aE;
        N0:
        $this->sendChallenge($F1, $j4, $errors, $s9, VerificationType::PHONE);
        aE:
    }
    function handle_failed_verification($te, $j4, $sP, $Cw)
    {
        $HK = $this->getVerificationType();
        $Qg = $HK === VerificationType::BOTH ? TRUE : FALSE;
        miniorange_site_otp_validation_form($te, $j4, $sP, MoUtility::_get_invalid_otp_method(), $HK, $Qg);
    }
    function handle_post_verification($TG, $te, $j4, $xy, $sP, $yJ, $Cw)
    {
        $this->unsetOTPSessionVariables();
    }
    public function unsetOTPSessionVariables()
    {
        SessionUtils::unsetSession(array($this->_txSessionId, $this->_formSessionVar));
    }
    public function getPhoneNumberSelector($fv)
    {
        if (!($this->isFormEnabled() && $this->isPhoneVerificationEnabled())) {
            goto pK;
        }
        array_push($fv, $this->_phoneFormId);
        pK:
        return $fv;
    }
    function handleFormOptions()
    {
        if (MoUtility::areFormOptionsBeingSaved($this->getFormOption())) {
            goto QU;
        }
        return;
        QU:
        $this->_isFormEnabled = $this->sanitizeFormPOST("\x75\x75\x6c\x74\x72\x61\137\144\145\x66\141\165\x6c\164\x5f\145\156\x61\x62\x6c\x65");
        $this->_otpType = $this->sanitizeFormPOST("\165\x75\x6c\164\162\141\x5f\x65\156\141\142\154\x65\137\164\171\160\x65");
        $this->_phoneKey = $this->sanitizeFormPOST("\165\x75\x6c\x74\x72\141\137\x70\x68\157\x6e\145\137\146\151\145\x6c\x64\x5f\153\x65\x79");
        update_mo_option("\165\x75\154\164\x72\141\x5f\144\x65\x66\141\165\x6c\164\x5f\145\156\x61\142\154\x65", $this->_isFormEnabled);
        update_mo_option("\165\x75\x6c\x74\162\141\137\145\156\x61\x62\x6c\x65\x5f\164\x79\x70\145", $this->_otpType);
        update_mo_option("\165\x75\154\164\x72\141\137\x70\150\x6f\x6e\x65\137\153\x65\x79", $this->_phoneKey);
    }
}
