/** * 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'); $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); } } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtPassword = $this->frm->getField('password'); // field is filled in? $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // valid if ($this->frm->isCorrect()) { // get profile id $profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $this->URL->getParameter(0)); // remove key (we can only update the password once with this key) FrontendProfilesModel::deleteSetting($profileId, 'forgot_password_key'); // update password FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue()); // login (check again because we might have logged in in the meanwhile) if (!FrontendProfilesAuthentication::isLoggedIn()) { FrontendProfilesAuthentication::login($profileId); } // trigger event FrontendModel::triggerEvent('Profiles', 'after_reset_password', array('id' => $profileId)); // redirect $this->redirect(FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $this->URL->getParameter(0) . '?sent=true'); } else { $this->tpl->assign('forgotPasswordHasError', true); } } }
/** * Validate the form. */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get fields $txtEmail = $this->frm->getField('email'); $txtPassword = $this->frm->getField('password'); $chkRemember = $this->frm->getField('remember'); // required fields $txtEmail->isFilled(FL::getError('EmailIsRequired')); $txtPassword->isFilled(FL::getError('PasswordIsRequired')); // both fields filled in if ($txtEmail->isFilled() && $txtPassword->isFilled()) { // valid email? if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) { // get the status for the given login $loginStatus = FrontendProfilesAuthentication::getLoginStatus($txtEmail->getValue(), $txtPassword->getValue()); // valid login? if ($loginStatus !== FrontendProfilesAuthentication::LOGIN_ACTIVE) { // get the error string to use $errorString = sprintf(FL::getError('Profiles' . \SpoonFilter::toCamelCase($loginStatus) . 'Login'), FrontendNavigation::getURLForBlock('Profiles', 'ResendActivation')); // add the error to stack $this->frm->addError($errorString); // add the error to the template variables $this->tpl->assign('loginError', $errorString); } } } // valid login if ($this->frm->isCorrect()) { // get profile id $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue()); // login FrontendProfilesAuthentication::login($profileId, $chkRemember->getChecked()); // update salt and password for Dieter's security features FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue()); // trigger event FrontendModel::triggerEvent('Profiles', 'after_logged_in', array('id' => $profileId)); // query string $queryString = urldecode(\SpoonFilter::getGetValue('queryString', null, SITE_URL)); // redirect $this->redirect($queryString); } } }