public function __construct() { parent::__construct(); $oAffModel = new AffiliateModel(); $oSecurityModel = new SecurityModel(); $sEmail = $this->httpRequest->post('mail'); $sPassword = $this->httpRequest->post('password'); /** Check if the connection is not locked **/ $bIsLoginAttempt = (bool) DbConfig::getSetting('isAffiliateLoginAttempt'); $iMaxAttempts = (int) DbConfig::getSetting('maxAffiliateLoginAttempts'); $iTimeDelay = (int) DbConfig::getSetting('loginAffiliateAttemptTime'); if ($bIsLoginAttempt && !$oSecurityModel->checkLoginAttempt($iMaxAttempts, $iTimeDelay, $sEmail, $this->view, 'Affiliates')) { \PFBC\Form::setError('form_login_aff', Form::loginAttemptsExceededMsg($iTimeDelay)); return; // Stop execution of the method. } // Check Login $sLogin = $oAffModel->login($sEmail, $sPassword, 'Affiliates'); if ($sLogin === 'email_does_not_exist' || $sLogin === 'password_does_not_exist') { sleep(1); // Security against brute-force attack to avoid drowning the server and the database if ($sLogin === 'email_does_not_exist') { $this->session->set('captcha_enabled', 1); // Enable Captcha \PFBC\Form::setError('form_login_aff', t('Oops! "%0%" is not associated with any %site_name% account.', escape(substr($sEmail, 0, PH7_MAX_EMAIL_LENGTH)))); $oSecurityModel->addLoginLog($sEmail, 'Guest', 'No Password', 'Failed! Incorrect Username', 'Affiliates'); } elseif ($sLogin === 'password_does_not_exist') { $oSecurityModel->addLoginLog($sEmail, 'Guest', $sPassword, 'Failed! Incorrect Password', 'Affiliates'); if ($bIsLoginAttempt) { $oSecurityModel->addLoginAttempt('Affiliates'); } $this->session->set('captcha_enabled', 1); // Enable Captcha $sWrongPwdTxt = t('Oops! This password you entered is incorrect.') . '<br />'; $sWrongPwdTxt .= t('Please try again (make sure your caps lock is off).') . '<br />'; $sWrongPwdTxt .= t('Forgot your password? <a href="%0%">Request a new one</a>.', Uri::get('lost-password', 'main', 'forgot', 'affiliate')); \PFBC\Form::setError('form_login_aff', $sWrongPwdTxt); } } else { $oSecurityModel->clearLoginAttempts('Affiliates'); $this->session->remove('captcha_enabled'); $iId = $oAffModel->getId($sEmail, null, 'Affiliates'); $oAffData = $oAffModel->readProfile($iId, 'Affiliates'); if (true !== ($mStatus = (new AffiliateCore())->checkAccountStatus($oAffData))) { \PFBC\Form::setError('form_login_aff', $mStatus); } else { // Is disconnected if the user is logged on as "user" or "administrator". if (UserCore::auth() || AdminCore::auth()) { $this->session->destroy(); } // Regenerate the session ID to prevent the session fixation $this->session->regenerateId(); $aSessionData = ['affiliate_id' => $oAffData->profileId, 'affiliate_email' => $oAffData->email, 'affiliate_username' => $oAffData->username, 'affiliate_first_name' => $oAffData->firstName, 'affiliate_sex' => $oAffData->sex, 'affiliate_ip' => Ip::get(), 'affiliate_http_user_agent' => $this->browser->getUserAgent(), 'affiliate_token' => Various::genRnd($oAffData->email)]; $this->session->set($aSessionData); $oSecurityModel->addLoginLog($oAffData->email, $oAffData->username, '*****', 'Logged in!', 'Affiliates'); $oAffModel->setLastActivity($oAffData->profileId, 'Affiliates'); Header::redirect(Uri::get('affiliate', 'account', 'index'), t('You are successfully logged!')); } } }
/** * Add Refer Link. * * @param string $sUsername The Affiliate Username. * @return void * @internal Today's IP address is also easier to change than delete a cookie, so we have chosen the Cookie instead save the IP address in the database. */ public function addRefer($sUsername) { $oAffModel = new AffiliateModel(); $oCookie = new Cookie(); $iAffId = $oAffModel->getId(null, $sUsername, 'Affiliates'); if (!$oCookie->exists(static::COOKIE_NAME)) { $this->_setCookie($iAffId, $oCookie); // Set a week $oAffModel->addRefer($iAffId); // Add a reference only for new clicks (if the cookie does not exist) } else { $this->_setCookie($iAffId, $oCookie); // Add an extra week } unset($oAffModel, $oCookie); }
public static function display() { if (isset($_POST['submit_aff_edit_account'])) { if (\PFBC\Form::isValid($_POST['submit_aff_edit_account'])) { new EditFormProcess(); } Framework\Url\Header::redirect(); } $bAdminLogged = AdminCore::auth() && !Affiliate::auth(); // Check if the admin is logged. $oAffModel = new AffiliateModel(); $oHR = new Http(); $iProfileId = $bAdminLogged && $oHR->getExists('profile_id') ? $oHR->get('profile_id', 'int') : (new Session())->get('affiliate_id'); $oAff = $oAffModel->readProfile($iProfileId, 'Affiliates'); // Birth date with the date format for the date picker $sBirthDate = (new CDateTime())->get($oAff->birthDate)->date('m/d/Y'); $oForm = new \PFBC\Form('form_aff_edit_account', 500); $oForm->configure(array('action' => '')); $oForm->addElement(new \PFBC\Element\Hidden('submit_aff_edit_account', 'form_aff_edit_account')); $oForm->addElement(new \PFBC\Element\Token('edit_account')); if ($bAdminLogged && $oHR->getExists('profile_id')) { $oForm->addElement(new \PFBC\Element\HTMLExternal('<p class="center"><a class="m_button" href="' . Uri::get('affiliate', 'admin', 'browse') . '">' . t('Back to Browse Affiliates') . '</a></p>')); } unset($oHR); $oForm->addElement(new \PFBC\Element\HTMLExternal('<h2 class="underline">' . t('Global Information:') . '</h2>')); $oForm->addElement(new \PFBC\Element\HTMLExternal('<p class="error">' . t('Attention all your information must be complete, candid and valid.') . '</p>')); $oForm->addElement(new \PFBC\Element\Textbox(t('Your First Name:'), 'first_name', array('id' => 'str_first_name', 'onblur' => 'CValid(this.value,this.id,2,20)', 'value' => $oAff->firstName, 'required' => 1, 'validation' => new \PFBC\Validation\Str(2, 20)))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_first_name"></span>')); $oForm->addElement(new \PFBC\Element\Textbox(t('Your Last Name:'), 'last_name', array('id' => 'str_last_name', 'onblur' => 'CValid(this.value,this.id,2,20)', 'value' => $oAff->lastName, 'required' => 1, 'validation' => new \PFBC\Validation\Str(2, 20)))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error str_last_name"></span>')); $oForm->addElement(new \PFBC\Element\Textbox(t('Username:'******'username', array('description' => t('For site security, you cannot change your username.'), 'disabled' => 'disabled', 'value' => $oAff->username))); $oForm->addElement(new \PFBC\Element\Email(t('Your Email:'), 'mail', array('description' => t('For site security and to avoid spam, you cannot change your email address.'), 'disabled' => 'disabled', 'value' => $oAff->email))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error phone"></span>')); $oForm->addElement(new \PFBC\Element\Radio(t('Your Sex:'), 'sex', array('male' => t('Male'), 'female' => t('Female')), array('value' => $oAff->sex, 'required' => 1))); $oForm->addElement(new \PFBC\Element\Date(t('Your Date of birth:'), 'birth_date', array('id' => 'birth_date', 'onblur' => 'CValid(this.value, this.id)', 'value' => $sBirthDate, 'validation' => new \PFBC\Validation\BirthDate(), 'required' => 1))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<span class="input_error birth_date"></span>')); // Generate dynamic fields $oFields = $oAffModel->getInfoFields($iProfileId, 'AffiliatesInfo'); foreach ($oFields as $sColumn => $sValue) { $oForm = (new DynamicFieldCoreForm($oForm, $sColumn, $sValue))->generate(); } $oForm->addElement(new \PFBC\Element\Button()); $oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_STATIC . PH7_JS . 'validate.js"></script>')); $oForm->render(); }
public function __construct() { parent::__construct(); $oAffModel = new AffiliateModel(); $iProfileId = AdminCore::auth() && !Affiliate::auth() && $this->httpRequest->getExists('profile_id') ? $this->httpRequest->get('profile_id', 'int') : $this->session->get('affiliate_id'); $oAff = $oAffModel->readProfile($iProfileId, 'Affiliates'); if (!$this->str->equals($this->httpRequest->post('first_name'), $oAff->firstName)) { $oAffModel->updateProfile('firstName', $this->httpRequest->post('first_name'), $iProfileId, 'Affiliates'); $this->session->set('affiliate_first_name', $this->httpRequest->post('first_name')); (new Framework\Cache\Cache())->start(UserCoreModel::CACHE_GROUP, 'firstName' . $iProfileId . 'Affiliates', null)->clear(); } if (!$this->str->equals($this->httpRequest->post('last_name'), $oAff->lastName)) { $oAffModel->updateProfile('lastName', $this->httpRequest->post('last_name'), $iProfileId, 'Affiliates'); } if (!$this->str->equals($this->httpRequest->post('sex'), $oAff->sex)) { $oAffModel->updateProfile('sex', $this->httpRequest->post('sex'), $iProfileId, 'Affiliates'); $this->session->set('affiliate_sex', $this->httpRequest->post('sex')); (new Framework\Cache\Cache())->start(UserCoreModel::CACHE_GROUP, 'sex' . $iProfileId . 'Affiliates', null)->clear(); } if (!$this->str->equals($this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d'), $oAff->birthDate)) { $oAffModel->updateProfile('birthDate', $this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d'), $iProfileId, 'Affiliates'); } // Update dynamic fields. $oFields = $oAffModel->getInfoFields($iProfileId, 'AffiliatesInfo'); foreach ($oFields as $sColumn => $sValue) { $sHRParam = $sColumn == 'description' ? Http::ONLY_XSS_CLEAN : null; if (!$this->str->equals($this->httpRequest->post($sColumn, $sHRParam), $sValue)) { $oAffModel->updateProfile($sColumn, $this->httpRequest->post($sColumn, $sHRParam), $iProfileId, 'AffiliatesInfo'); } } unset($oFields); $oAffModel->setLastEdit($iProfileId, 'Affiliates'); $oAffCache = new Affiliate(); $oAffCache->clearReadProfileCache($iProfileId, 'Affiliates'); $oAffCache->clearInfoFieldCache($iProfileId, 'AffiliatesInfo'); unset($oAffModel, $oAff, $oAffCache); \PFBC\Form::setSuccess('form_aff_edit_account', t('Your profile has been saved successfully!')); }
public function step1() { $sBirthDate = $this->dateTime->get($this->httpRequest->post('birth_date'))->date('Y-m-d'); $iAffId = (int) (new Cookie())->get(AffiliateCore::COOKIE_NAME); $aData = ['email' => $this->httpRequest->post('mail'), 'username' => $this->httpRequest->post('username'), 'password' => $this->httpRequest->post('password'), 'first_name' => $this->httpRequest->post('first_name'), 'last_name' => $this->httpRequest->post('last_name'), 'sex' => $this->httpRequest->post('sex'), 'birth_date' => $sBirthDate, 'country' => $this->httpRequest->post('country'), 'city' => $this->httpRequest->post('city'), 'state' => $this->httpRequest->post('state'), 'zip_code' => $this->httpRequest->post('zip_code'), 'ip' => Ip::get(), 'hash_validation' => Various::genRnd(), 'current_date' => (new CDateTime())->get()->dateTime('Y-m-d H:i:s'), 'is_active' => $this->iActiveType, 'affiliated_id' => $iAffId]; $oAffModel = new AffiliateModel(); $iTimeDelay = (int) DbConfig::getSetting('timeDelayUserRegistration'); if (!$oAffModel->checkWaitJoin($aData['ip'], $iTimeDelay, $aData['current_date'], 'Affiliates')) { \PFBC\Form::setError('form_join_aff', Form::waitRegistrationMsg($iTimeDelay)); } elseif (!$oAffModel->join($aData)) { \PFBC\Form::setError('form_join_aff', t('An error occurred during registration!<br /> Please try again with other information in the form fields or come back later.')); } else { // Successful registration in the database! /** Update the Affiliate Commission **/ if ($this->iActiveType == 0) { // Only if the user's account is already activated. AffiliateCore::updateJoinCom($iAffId, $this->config, $this->registry); } // Send an email and sets the welcome message. \PFBC\Form::setSuccess('form_join_aff', t('Your affiliate account has been created! %0%', (new Registration())->sendMail($aData)->getMsg())); } unset($oAffModel); }