/**
  * Validate the form
  */
 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())) {
                     // get profile id using the filled in email
                     $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
                     // get profile
                     $profile = FrontendProfilesModel::get($profileId);
                     // must be inactive
                     if ($profile->getStatus() != FrontendProfilesAuthentication::LOGIN_INACTIVE) {
                         $txtEmail->addError(FL::getError('ProfileIsActive'));
                     }
                 } else {
                     $txtEmail->addError(FL::getError('EmailIsInvalid'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // activation URL
             $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $profile->getSetting('activation_key');
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_resend_activation', array('id' => $profileId));
             // send email
             FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $profile->getEmail(), '');
             // redirect
             $this->redirect(SELF . '?sent=true');
         } else {
             $this->tpl->assign('resendActivationHasError', true);
         }
     }
 }
 /**
  * Validate the form
  */
 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', 'reset_password') . '/' . $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
             FrontendMailer::addEmail(FL::getMessage('ForgotPasswordSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/forgot_password.tpl', $mailValues, $txtEmail->getValue(), '');
             // redirect
             $this->redirect(SELF . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }
Example #3
0
 /**
  * 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');
         // 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()) {
             // generate salt
             $salt = FrontendProfilesModel::getRandomString();
             // init values
             $values = array();
             // values
             $values['email'] = $txtEmail->getValue();
             $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt);
             $values['status'] = 'inactive';
             $values['display_name'] = $txtEmail->getValue();
             $values['registered_on'] = FrontendModel::getUTCDate();
             /*
              * 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
                 $activationKey = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $salt);
                 // set settings
                 FrontendProfilesModel::setSetting($profileId, 'salt', $salt);
                 FrontendProfilesModel::setSetting($profileId, 'activation_key', $activationKey);
                 // login
                 FrontendProfilesAuthentication::login($profileId);
                 // activation URL
                 $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $activationKey;
                 // send email
                 FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $values['email'], '');
                 // redirect
                 $this->redirect(SELF . '?sent=true');
             } catch (Exception $e) {
                 // when debugging we need to see the exceptions
                 if (SPOON_DEBUG) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('registerHasFormError', true);
             }
         } else {
             $this->tpl->assign('registerHasFormError', true);
         }
     }
 }
Example #4
0
 /**
  * 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', 'change_email') . '?sent=true');
         } else {
             $this->tpl->assign('updateEmailHasFormError', true);
         }
     }
 }