예제 #1
0
 /**
  * Change password method
  *
  * @param EntityInterface $user user data.
  * @throws WrongPasswordException
  * @return mixed
  */
 public function changePassword(EntityInterface $user)
 {
     try {
         $currentUser = $this->_table->get($user->id, ['contain' => []]);
     } catch (RecordNotFoundException $e) {
         throw new UserNotFoundException(__d('CakeDC/Users', "User not found"));
     }
     if (!empty($user->current_password)) {
         if (!$user->checkPassword($user->current_password, $currentUser->password)) {
             throw new WrongPasswordException(__d('CakeDC/Users', 'The current password does not match'));
         }
         if ($user->current_password === $user->password_confirm) {
             throw new WrongPasswordException(__d('CakeDC/Users', 'You cannot use the current password as the new one'));
         }
     }
     $user = $this->_table->save($user);
     if (!empty($user)) {
         $user = $this->_removeValidationToken($user);
     }
     return $user;
 }
예제 #2
0
 /**
  * Change password method
  *
  * @param EntityInterface $user user data.
  * @return mixed
  */
 public function changePassword(EntityInterface $user)
 {
     $currentUser = $this->_table->get($user->id, ['contain' => []]);
     if (!empty($user->current_password)) {
         if (!$user->checkPassword($user->current_password, $currentUser->password)) {
             throw new WrongPasswordException(__d('Users', 'The old password does not match'));
         }
     }
     $user = $this->_table->save($user);
     if (!empty($user)) {
         $user = $this->_removeValidationToken($user);
     }
     return $user;
 }