<?php


namespace OTP\Handler\Forms;

use OTP\Helper\FormSessionVars;
use OTP\Helper\MoOTPDocs;
use OTP\Helper\MoPHPSessions;
use OTP\Helper\MoUtility;
use OTP\Helper\SessionUtils;
use OTP\Objects\FormHandler;
use OTP\Objects\IFormHandler;
use OTP\Objects\VerificationLogic;
use OTP\Objects\VerificationType;
use OTP\Traits\Instance;
use ReflectionException;
class UserProfileMadeEasyRegistrationForm extends FormHandler implements IFormHandler
{
    use Instance;
    protected function __construct()
    {
        $this->_isLoginOrSocialForm = FALSE;
        $this->_isAjaxForm = FALSE;
        $this->_formSessionVar = FormSessionVars::UPME_REG;
        $this->_typePhoneTag = "\x6d\x6f\x5f\165\160\x6d\x65\x5f\x70\150\x6f\x6e\145\x5f\x65\x6e\x61\x62\x6c\x65";
        $this->_typeEmailTag = "\155\157\x5f\x75\x70\x6d\x65\x5f\145\155\141\151\x6c\137\145\156\141\142\154\145";
        $this->_typeBothTag = "\155\157\x5f\x75\x70\155\x65\x5f\142\157\x74\x68\x5f\x65\x6e\x61\x62\154\x65";
        $this->_formKey = "\x55\x50\x4d\x45\x5f\106\117\122\115";
        $this->_formName = mo_("\125\163\145\x72\120\x72\x6f\146\151\x6c\145\x20\x4d\141\144\145\x20\105\141\x73\x79\x20\122\145\x67\x69\163\164\x72\141\164\151\x6f\156\40\106\x6f\x72\155");
        $this->_isFormEnabled = get_mo_option("\165\x70\x6d\x65\x5f\x64\x65\x66\x61\x75\x6c\x74\x5f\145\156\x61\142\154\x65");
        $this->_formDocuments = MoOTPDocs::UPME_FORM_LINK;
        parent::__construct();
    }
    function handleForm()
    {
        $this->_otpType = get_mo_option("\x75\x70\155\x65\x5f\x65\x6e\141\142\154\x65\x5f\x74\x79\x70\145");
        $this->_phoneKey = get_mo_option("\165\160\155\x65\137\x70\x68\157\x6e\x65\x5f\153\145\x79");
        $this->_phoneFormId = "\151\156\x70\x75\x74\133\156\141\155\x65\x3d" . $this->_phoneKey . "\135";
        add_filter("\151\156\x73\145\x72\164\x5f\165\x73\x65\x72\137\155\x65\x74\x61", array($this, "\155\151\x6e\x69\x6f\x72\x61\x6e\147\145\x5f\x75\x70\155\x65\137\x69\x6e\163\145\x72\164\x5f\x75\x73\x65\162"), 1, 3);
        add_filter("\165\160\x6d\145\x5f\x72\x65\x67\x69\163\x74\x72\x61\164\151\157\156\x5f\143\x75\163\164\157\155\137\x66\151\x65\x6c\144\x5f\164\x79\160\145\x5f\x72\x65\x73\164\162\x69\143\164\151\157\x6e\163", array($this, "\155\151\x6e\x69\157\x72\x61\x6e\x67\145\137\x75\160\155\x65\137\x63\150\x65\x63\153\x5f\x70\x68\157\x6e\x65"), 1, 2);
        if (SessionUtils::isStatusMatch($this->_formSessionVar, self::VALIDATED, $this->getVerificationType())) {
            goto fC;
        }
        if (array_key_exists("\165\160\155\x65\55\162\x65\x67\x69\163\164\x65\162\55\146\157\162\x6d", $_POST) && !SessionUtils::isOTPInitialized($this->_formSessionVar)) {
            goto Z_;
        }
        goto p6;
        fC:
        $this->unsetOTPSessionVariables();
        goto p6;
        Z_:
        $this->_handle_upme_form_submit($_POST);
        p6:
    }
    function isPhoneVerificationEnabled()
    {
        $HK = $this->getVerificationType();
        return $HK === VerificationType::PHONE || $HK === VerificationType::BOTH;
    }
    function _handle_upme_form_submit($zB)
    {
        $zt = '';
        foreach ($zB as $yU => $Fo) {
            if (!($yU == $this->_phoneKey)) {
                goto k6;
            }
            $zt = $Fo;
            goto qJ;
            k6:
            Bs:
        }
        qJ:
        $this->miniorange_upme_user($_POST["\x75\x73\x65\162\x5f\x6c\157\147\x69\156"], $_POST["\165\x73\145\162\137\145\155\x61\151\x6c"], $zt);
    }
    function miniorange_upme_insert_user($BW, $user, $GB)
    {
        $cN = MoPHPSessions::getSessionVar("\x66\x69\154\x65\137\165\160\x6c\157\141\x64");
        if (!(!SessionUtils::isOTPInitialized($this->_formSessionVar) || !$cN)) {
            goto ab;
        }
        return $BW;
        ab:
        foreach ($cN as $yU => $Fo) {
            $VM = get_user_meta($user->ID, $yU, true);
            if (!('' != $VM)) {
                goto ev;
            }
            upme_delete_uploads_folder_files($VM);
            ev:
            update_user_meta($user->ID, $yU, $Fo);
            pt:
        }
        bC:
        return $BW;
    }
    function miniorange_upme_check_phone($errors, $bq)
    {
        global $phoneLogic;
        if (!empty($errors)) {
            goto u1;
        }
        if (!($bq["\x6d\145\164\x61"] == $this->_phoneKey)) {
            goto u2;
        }
        if (MoUtility::validatePhoneNumber($bq["\x76\141\154\165\x65"])) {
            goto mk;
        }
        $errors[] = str_replace("\x23\x23\x70\x68\157\156\145\43\x23", $bq["\166\x61\154\x75\x65"], $phoneLogic->_get_otp_invalid_format_message());
        mk:
        u2:
        u1:
        return $errors;
    }
    function miniorange_upme_user($F1, $j4, $sP)
    {
        global $upme_register;
        $upme_register->prepare($_POST);
        $upme_register->handle();
        $cN = array();
        if (MoUtility::isBlank($upme_register->errors)) {
            goto XB;
        }
        return;
        XB:
        MoUtility::initialize_transaction($this->_formSessionVar);
        $this->processFileUpload($cN);
        MoPHPSessions::addSessionVar("\x66\151\154\x65\137\x75\x70\x6c\157\141\144", $cN);
        $this->processAndStartOTPVerification($F1, $j4, $sP);
    }
    function processFileUpload(&$cN)
    {
        if (!empty($_FILES)) {
            goto O6;
        }
        return;
        O6:
        $KI = wp_upload_dir();
        $i0 = $KI["\x62\x61\163\x65\x64\x69\x72"] . "\57\165\160\155\145\x2f";
        if (is_dir($i0)) {
            goto lK;
        }
        mkdir($i0, 511);
        lK:
        foreach ($_FILES as $yU => $aK) {
            $F3 = sanitize_file_name(basename($aK["\x6e\x61\155\x65"]));
            $i0 = $i0 . time() . "\x5f" . $F3;
            $k9 = $KI["\x62\141\163\145\x75\x72\154"] . "\57\165\x70\155\x65\57";
            $k9 = $k9 . time() . "\137" . $F3;
            move_uploaded_file($aK["\164\155\x70\x5f\x6e\141\155\x65"], $i0);
            $cN[$yU] = $k9;
            bD:
        }
        fo:
    }
    public function unsetOTPSessionVariables()
    {
        SessionUtils::unsetSession(array($this->_txSessionId, $this->_formSessionVar));
    }
    public function getPhoneNumberSelector($fv)
    {
        if (!($this->isFormEnabled() && $this->isPhoneVerificationEnabled())) {
            goto DC;
        }
        array_push($fv, $this->_phoneFormId);
        DC:
        return $fv;
    }
    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)
    {
        SessionUtils::addStatus($this->_formSessionVar, self::VALIDATED, $Cw);
    }
    function processAndStartOTPVerification($F1, $j4, $sP)
    {
        if (strcasecmp($this->_otpType, $this->_typePhoneTag) == 0) {
            goto cw;
        }
        if (strcasecmp($this->_otpType, $this->_typeBothTag) == 0) {
            goto N2;
        }
        $this->sendChallenge($F1, $j4, null, $sP, VerificationType::EMAIL);
        goto of;
        N2:
        $this->sendChallenge($F1, $j4, null, $sP, VerificationType::BOTH);
        of:
        goto RK;
        cw:
        $this->sendChallenge($F1, $j4, null, $sP, VerificationType::PHONE);
        RK:
    }
    function handleFormOptions()
    {
        if (MoUtility::areFormOptionsBeingSaved($this->getFormOption())) {
            goto L1;
        }
        return;
        L1:
        $this->_isFormEnabled = $this->sanitizeFormPOST("\165\160\x6d\x65\137\144\145\x66\x61\x75\154\x74\137\145\156\141\142\154\145");
        $this->_otpType = $this->sanitizeFormPOST("\165\x70\x6d\x65\x5f\x65\x6e\x61\142\154\145\x5f\x74\171\x70\x65");
        $this->_phoneKey = $this->sanitizeFormPOST("\x75\x70\155\145\137\x70\x68\x6f\x6e\x65\x5f\146\151\145\154\x64\x5f\x6b\x65\171");
        update_mo_option("\165\160\155\145\137\x64\145\x66\x61\165\x6c\164\137\145\x6e\x61\x62\x6c\x65", $this->_isFormEnabled);
        update_mo_option("\165\160\x6d\145\137\145\x6e\x61\x62\154\145\x5f\164\171\160\145", $this->_otpType);
        update_mo_option("\165\160\x6d\145\x5f\x70\150\157\x6e\145\x5f\153\x65\x79", $this->_phoneKey);
    }
}
