private function validateForm()
{
// is the form submitted
if ($this->frm->isSubmitted()) {
// get field
$txtEmail = $this->frm->getField('email');
// field is filled in?
if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
// valid email?
if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
// email exists?
if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
$txtEmail->addError(FL::getError('EmailIsUnknown'));
}
}
}
// valid login
if ($this->frm->isCorrect()) {
// get profile id
$profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
// generate forgot password key
$key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString());
// insert forgot password key
FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key);
// reset url
$mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $key;
$mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name');
$mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name');
// trigger event
FrontendModel::triggerEvent('Profiles', 'after_forgot_password', array('id' => $profileId));
// send email
$from = $this->get('fork.settings')->get('Core', 'mailer_from');
$replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
$message = Message::newInstance(FL::getMessage('ForgotPasswordSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Profiles/Layout/Templates/Mails/ForgotPassword.html.twig', $mailValues, true);
$this->get('mailer')->send($message);
// redirect
$this->redirect(SITE_URL . $this->URL->getQueryString() . '?sent=true');
} else {
$this->tpl->assign('forgotPasswordHasError', true);
}
}
}