Exemplo n.º 1
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtOldPassword = $this->frm->getField('old_password');
         $txtNewPassword = $this->frm->getField('new_password');
         // old password filled in?
         if ($txtOldPassword->isFilled(FL::getError('PasswordIsRequired'))) {
             // old password correct?
             if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtOldPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                 // set error
                 $txtOldPassword->addError(FL::getError('InvalidPassword'));
             }
             // new password filled in?
             $txtNewPassword->isFilled(FL::getError('PasswordIsRequired'));
         }
         // no errors
         if ($this->frm->isCorrect()) {
             // update password
             FrontendProfilesAuthentication::updatePassword($this->profile->getId(), $txtNewPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_profile_password', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'profile_password') . '?saved=true');
         } else {
             $this->tpl->assign('updatePasswordHasFormError', true);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     // gender dropdown values
     $genderValues = array('male' => SpoonFilter::ucfirst(FL::getLabel('Male')), 'female' => SpoonFilter::ucfirst(FL::getLabel('Female')));
     // birthdate dropdown values
     $days = range(1, 31);
     $months = SpoonLocale::getMonths(FRONTEND_LANGUAGE);
     $years = range(date('Y'), 1900);
     // get settings
     $birthDate = $this->profile->getSetting('birth_date');
     $nameChanges = (int) $this->profile->getSetting('display_name_changes');
     // get day, month and year
     if ($birthDate) {
         list($birthYear, $birthMonth, $birthDay) = explode('-', $birthDate);
     } else {
         $birthDay = '';
         $birthMonth = '';
         $birthYear = '';
     }
     // create the form
     $this->frm = new FrontendForm('updateSettings', null, null, 'updateSettingsForm');
     // create & add elements
     $this->frm->addImage('avatar');
     $this->frm->addText('display_name', $this->profile->getDisplayName());
     $this->frm->addText('first_name', $this->profile->getSetting('first_name'));
     $this->frm->addText('last_name', $this->profile->getSetting('last_name'));
     $this->frm->addText('email', $this->profile->getEmail());
     $this->frm->addText('city', $this->profile->getSetting('city'));
     $this->frm->addDropdown('country', SpoonLocale::getCountries(FRONTEND_LANGUAGE), $this->profile->getSetting('country'));
     $this->frm->addDropdown('gender', $genderValues, $this->profile->getSetting('gender'));
     $this->frm->addDropdown('day', array_combine($days, $days), $birthDay);
     $this->frm->addDropdown('month', $months, $birthMonth);
     $this->frm->addDropdown('year', array_combine($years, $years), (int) $birthYear);
     // set default elements dropdowns
     $this->frm->getField('gender')->setDefaultElement('');
     $this->frm->getField('day')->setDefaultElement('');
     $this->frm->getField('month')->setDefaultElement('');
     $this->frm->getField('year')->setDefaultElement('');
     $this->frm->getField('country')->setDefaultElement('');
     // set email disabled
     $this->frm->getField('email')->setAttribute('disabled', 'disabled');
     // when user exceeded the number of name changes set field disabled
     if ($nameChanges >= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
         $this->frm->getField('display_name')->setAttribute('disabled', 'disabled');
     }
 }
Exemplo n.º 3
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);
         }
     }
 }