/** * Execute the extra. */ public function execute() { // get activation key $key = $this->URL->getParameter(0); // load template $this->loadTemplate(); // do we have an activation key? if (isset($key)) { // get profile id $profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key); // have id? if ($profileId != null) { // update status FrontendProfilesModel::update($profileId, array('status' => 'active')); // delete activation key FrontendProfilesModel::deleteSetting($profileId, 'activation_key'); // login profile FrontendProfilesAuthentication::login($profileId); // trigger event FrontendModel::triggerEvent('Profiles', 'after_activate', array('id' => $profileId)); // show success message $this->tpl->assign('activationSuccess', true); } else { // failure $this->redirect(FrontendNavigation::getURL(404)); } } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtDisplayName = $this->frm->getField('display_name'); $txtFirstName = $this->frm->getField('first_name'); $txtLastName = $this->frm->getField('last_name'); $txtCity = $this->frm->getField('city'); $ddmCountry = $this->frm->getField('country'); $ddmGender = $this->frm->getField('gender'); $ddmDay = $this->frm->getField('day'); $ddmMonth = $this->frm->getField('month'); $ddmYear = $this->frm->getField('year'); // get number of display name changes $nameChanges = (int) FrontendProfilesModel::getSetting($this->profile->getId(), 'display_name_changes'); // has there been a valid display name change request? if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) { // display name filled in? if ($txtDisplayName->isFilled(FL::getError('FieldIsRequired'))) { // display name exists? if (FrontendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->profile->getId())) { // set error $txtDisplayName->addError(FL::getError('DisplayNameExists')); } } } // birthdate is not required but if one is filled we need all if ($ddmMonth->isFilled() || $ddmDay->isFilled() || $ddmYear->isFilled()) { // valid birth date? if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) { // set error $ddmYear->addError(FL::getError('DateIsInvalid')); } } // validate avatar when given $this->frm->getField('avatar')->isFilled(); // no errors if ($this->frm->isCorrect()) { // init $values = array(); $settings = array(); // has there been a valid display name change request? if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) { // get display name value $values['display_name'] = $txtDisplayName->getValue(); // update url based on the new display name $values['url'] = FrontendProfilesModel::getUrl($txtDisplayName->getValue(), $this->profile->getId()); // update display name count $settings['display_name_changes'] = $nameChanges + 1; } // update values if (!empty($values)) { FrontendProfilesModel::update($this->profile->getId(), $values); } // build settings $settings['first_name'] = $txtFirstName->getValue(); $settings['last_name'] = $txtLastName->getValue(); $settings['city'] = $txtCity->getValue(); $settings['country'] = $ddmCountry->getValue(); $settings['gender'] = $ddmGender->getValue(); // birthday is filled in if ($ddmYear->isFilled()) { // mysql format $settings['birth_date'] = $ddmYear->getValue() . '-'; $settings['birth_date'] .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-'; $settings['birth_date'] .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT); } else { // not filled in $settings['birth_date'] = null; } // avatar $settings['avatar'] = $this->profile->getSetting('avatar'); // create new filename if ($this->frm->getField('avatar')->isFilled()) { // field value $settings['avatar'] = \SpoonFilter::urlise($this->profile->getDisplayName()) . '.' . $this->frm->getField('avatar')->getExtension(); // move the file $this->frm->getField('avatar')->generateThumbnails(FRONTEND_FILES_PATH . '/Profiles/Avatars/', $settings['avatar']); } // save settings $this->profile->setSettings($settings); // trigger event FrontendModel::triggerEvent('Profiles', 'after_saved_settings', array('id' => $this->profile->getId())); // redirect $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Settings') . '?sent=true'); } else { $this->tpl->assign('updateSettingsHasFormError', true); } } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtPassword = $this->frm->getField('password'); $txtEmail = $this->frm->getField('email'); // password filled in? if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) { // password correct? if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) { // set error $txtPassword->addError(FL::getError('InvalidPassword')); } // email filled in? if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email already exists? if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) { // set error $txtEmail->setError(FL::getError('EmailExists')); } } } } // no errors if ($this->frm->isCorrect()) { // update email FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue())); // trigger event FrontendModel::triggerEvent('Profiles', 'after_change_email', array('id' => $this->profile->getId())); // redirect $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ChangeEmail') . '?sent=true'); } else { $this->tpl->assign('updateEmailHasFormError', true); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtDisplayName = $this->frm->getField('display_name'); $txtEmail = $this->frm->getField('email'); $txtPassword = $this->frm->getField('password'); // check email if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // email already exists? if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) { // set error $txtEmail->setError(FL::getError('EmailExists')); } } } // check password $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // no errors if ($this->frm->isCorrect()) { // init values $settings = array(); $values = array(); // generate salt $settings['salt'] = FrontendProfilesModel::getRandomString(); $settings['language'] = FRONTEND_LANGUAGE; // values $values['email'] = $txtEmail->getValue(); $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $settings['salt']); $values['status'] = 'inactive'; $values['display_name'] = $txtDisplayName->getValue(); $values['registered_on'] = FrontendModel::getUTCDate(); $values['last_login'] = FrontendModel::getUTCDate(null, 0); /* * Add a profile. * We use a try-catch statement to catch errors when more users sign up simultaneously. */ try { // insert profile $profileId = FrontendProfilesModel::insert($values); // use the profile id as url until we have an actual url FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name']))); // trigger event FrontendModel::triggerEvent('Profiles', 'after_register', array('id' => $profileId)); // generate activation key $settings['activation_key'] = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $settings['salt']); // set settings FrontendProfilesModel::setSettings($profileId, $settings); // login FrontendProfilesAuthentication::login($profileId); // activation URL $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $settings['activation_key']; // send email $from = $this->get('fork.settings')->get('Core', 'mailer_from'); $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to'); $message = \Common\Mailer\Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/Register.tpl', $mailValues, true); $this->get('mailer')->send($message); // redirect $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true'); } catch (\Exception $e) { // when debugging we need to see the exceptions if ($this->getContainer()->getParameter('kernel.debug')) { throw $e; } // show error $this->tpl->assign('registerHasFormError', true); } } else { $this->tpl->assign('registerHasFormError', true); } } }
/** * Update profile password and salt. * * @param int $profileId Profile id for which we are changing the password. * @param string $password New password. */ public static function updatePassword($profileId, $password) { $profileId = (int) $profileId; $password = (string) $password; // get new salt $salt = FrontendProfilesModel::getRandomString(); // encrypt password $encryptedPassword = FrontendProfilesModel::getEncryptedString($password, $salt); // update salt FrontendProfilesModel::setSetting($profileId, 'salt', $salt); // update password FrontendProfilesModel::update($profileId, array('password' => $encryptedPassword)); }