Пример #1
0
 /**
  * Update a given user.
  * @param NovemberUser $userToEdit
  * @param array $params
  */
 public function updateUser($userToEdit, $params, $synch = true)
 {
     if (isset($params['email'])) {
         // Check if there's a user with this email first.
         $existing = $this->dbService->getByField(array('email' => $params['email']), $this->userClass);
         if ($existing && $existing->id != $userToEdit->getId()) {
             throw new ExistingUserException($params['email'] . ' already exists');
         }
     }
     // Make sure no role is being changed! we do that in another method.
     unset($params['role']);
     $newPass = null;
     if (isset($params['password'])) {
         $newPass = $params['password'];
         $userToEdit->generateSaltedPassword($params['password']);
         unset($params['password']);
     }
     $userToEdit->bind($params);
     $validator = new ModelValidator();
     if (!$validator->isValid($userToEdit)) {
         throw new InvalidModelException($validator->getMessages());
     }
     $ret = $this->dbService->updateObject($userToEdit);
     $this->authComponent->updateUser($userToEdit, $newPass);
     return $ret;
 }