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 _validateAffiliate()
 {
     // Validate invite email address
     if (isset($this->request->get['invite_email'])) {
         if (!isset($this->request->post['invite_email']) || empty($this->request->post['invite_email'])) {
             $this->_error['invite_email'] = tt('Email address to required');
         } else {
             if (!ValidatorUser::emailValid($this->request->post['invite_email'])) {
                 $this->_error['invite_email'] = tt('Invalid email address');
             } else {
                 if ($this->model_account_user->checkEmail($this->request->post['invite_email'])) {
                     $this->_error['invite_email'] = tt('User with this e-mail address already registered');
                 }
             }
         }
         return !$this->_error;
     } else {
         if (isset($this->request->get['settings'])) {
             if (!isset($this->request->post['withdraw_address']) || empty($this->request->post['withdraw_address'])) {
                 $this->_error['withdraw_address'] = tt('Withdraw address required!');
             } else {
                 if (!ValidatorBitcoin::addressValid($this->request->post['withdraw_address'])) {
                     $this->_error['withdraw_address'] = tt('Invalid withdraw address');
                 }
             }
             if (!isset($this->request->post['currency_id']) || empty($this->request->post['currency_id']) || !$this->currency->hasId($this->request->post['currency_id'])) {
                 $this->security_log->write('Wrong affiliate currency_id field');
                 $this->_error['currency_id'] = tt('Invalid currency_id');
             }
             return !$this->_error;
             // Validate request
         } else {
             return false;
         }
     }
 }