Example #1
0
 private function _validateUpdate()
 {
     // Username
     if (!isset($this->request->post['username']) || empty($this->request->post['username'])) {
         $this->_error['username'] = tt('Username is required');
     } else {
         if (mb_strtolower($this->request->post['username']) != mb_strtolower($this->auth->getUsername()) && $this->model_account_user->checkUsername($this->request->post['username'])) {
             $this->_error['username'] = tt('Username is already registered');
         } else {
             if (mb_strlen($this->request->post['username']) < ValidatorUser::getUsernameMinLength() || mb_strlen($this->request->post['username']) > ValidatorUser::getUsernameMaxLength()) {
                 $this->_error['username'] = sprintf(tt('Username must be between %s and %s characters'), ValidatorUser::getUsernameMinLength(), ValidatorUser::getUsernameMaxLength());
             } else {
                 if (!ValidatorUser::usernameValid($this->request->post['username'])) {
                     $this->_error['username'] = tt('Username can only contain latin letters, numbers and hyphen');
                 }
             }
         }
     }
     // Email
     if (!isset($this->request->post['email']) || empty($this->request->post['email'])) {
         $this->_error['email'] = tt('Email is required');
     } else {
         if (mb_strtolower($this->request->post['email']) != mb_strtolower($this->auth->getEmail()) && $this->model_account_user->checkEmail($this->request->post['email'])) {
             $user_emails = $this->model_account_user->getEmails($this->auth->getId());
             $available_emails = array();
             foreach ($user_emails as $user_email) {
                 $available_emails[] = $user_email->email;
             }
             if (!in_array($this->request->post['email'], $available_emails)) {
                 $this->_error['email'] = tt('Email address is already registered or reserved');
             }
         } else {
             if (!ValidatorUser::emailValid($this->request->post['email'])) {
                 $this->_error['email'] = tt('Invalid email address');
             }
         }
     }
     if (!isset($this->request->post['confirm']) || !isset($this->request->post['password'])) {
         $this->_error['password'] = tt('Wrong password fields');
         $this->security_log->write('Wrong password fields');
     } else {
         if (!empty($this->request->post['password']) || !empty($this->request->post['confirm'])) {
             // New password
             if (empty($this->request->post['password'])) {
                 $this->_error['password'] = tt('Password is required');
             } else {
                 if (mb_strlen($this->request->post['password']) < ValidatorUser::getPasswordMinLength() || mb_strlen($this->request->post['password']) > ValidatorUser::getPasswordMaxLength()) {
                     $this->_error['password'] = sprintf(tt('Password must be between %s and %s characters'), ValidatorUser::getPasswordMinLength(), ValidatorUser::getPasswordMaxLength());
                 } else {
                     if (!ValidatorUser::passwordValid($this->request->post['password'])) {
                         $this->_error['password'] = tt('Invalid password');
                     }
                 }
             }
             // New password confirm
             if (empty($this->request->post['confirm'])) {
                 $this->_error['confirm'] = tt('Confirm is required');
             } else {
                 if ($this->request->post['confirm'] != $this->request->post['password']) {
                     $this->_error['confirm'] = tt('Password confirmation does not match password');
                 }
             }
         }
     }
     // Check the old password
     if (!isset($this->request->post['old_password']) || empty($this->request->post['old_password'])) {
         $this->_error['old_password'] = tt('Old password is required');
     } else {
         if (!$this->model_account_user->checkPassword($this->auth->getId(), $this->request->post['old_password'])) {
             $this->_error['old_password'] = tt('Incorrect old password');
         }
     }
     return !$this->_error;
 }
Example #2
0
 private function _validateReset()
 {
     // Password
     if (!isset($this->request->post['password']) || empty($this->request->post['password'])) {
         $this->_error['password'] = tt('Password is required');
     } else {
         if (mb_strlen($this->request->post['password']) < ValidatorUser::getPasswordMinLength() || mb_strlen($this->request->post['password']) > ValidatorUser::getPasswordMaxLength()) {
             $this->_error['password'] = sprintf(tt('Password must be between %s and %s characters'), ValidatorUser::getPasswordMinLength(), ValidatorUser::getPasswordMaxLength());
         } else {
             if (!ValidatorUser::passwordValid($this->request->post['password'])) {
                 $this->_error['password'] = tt('Invalid password');
             }
         }
     }
     // Password confirm
     if (!isset($this->request->post['confirm']) || empty($this->request->post['confirm'])) {
         $this->_error['confirm'] = tt('Confirm is required');
     } else {
         if ($this->request->post['confirm'] != $this->request->post['password']) {
             $this->_error['confirm'] = tt('Password confirmation does not match password');
         }
     }
     return !$this->_error;
 }