/**
  * {@inheritDoc}
  */
 public function loadUserByEmail($email)
 {
     $user = $this->apiUserRepository->findUserByEmail($email);
     if (!$user || true === $user->getDiamanteUser()->isDeleted()) {
         throw new UsernameNotFoundException(sprintf('User "%s" does not exist.', $email));
     }
     return $user;
 }
 /**
  * {@inheritDoc}
  */
 public function loadUserByEmail($email)
 {
     $user = $this->apiUserRepository->findUserByEmail($email);
     if (!$user) {
         throw new UsernameNotFoundException(sprintf('User "%s" does not exist.', $email));
     }
     return $user;
 }
 /**
  * Confirm user registration
  * @param Command\ConfirmCommand $command
  * @return void
  */
 public function confirm(Command\ConfirmCommand $command)
 {
     $apiUser = $this->apiUserRepository->findUserByHash($command->hash);
     if (is_null($apiUser)) {
         throw new \RuntimeException('Can not confirm registration.');
     }
     try {
         $apiUser->activate($command->hash);
         $this->apiUserRepository->store($apiUser);
     } catch (\Exception $e) {
         throw new \RuntimeException('Can not confirm registration.');
     }
 }
 public function testChangePassword()
 {
     $emailAddress = '*****@*****.**';
     $password = '******';
     $apiUser = new ApiUser($emailAddress, null);
     $this->apiUserRepository->expects($this->once())->method('findUserByHash')->will($this->returnValue($apiUser));
     $apiUser->generateHash();
     $hash = $apiUser->getHash();
     $this->apiUserRepository->expects($this->once())->method('store')->with($apiUser);
     $command = new ChangePasswordCommand();
     $command->password = $password;
     $command->hash = $hash;
     $this->resetPasswordService->changePassword($command);
 }
 public function testConfirm()
 {
     $apiUser = $this->createApiUser();
     $this->apiUserRepository->expects($this->once())->method('findUserByHash')->with($apiUser->getHash())->will($this->returnValue($apiUser));
     $this->apiUserRepository->expects($this->once())->method('store')->with($apiUser);
     $command = new ConfirmCommand();
     $command->hash = $apiUser->getHash();
     $this->service->confirm($command);
 }
 /**
  * @param ChangePasswordCommand $command
  * @return void
  */
 public function changePassword(ChangePasswordCommand $command)
 {
     /**
      * @var ApiUser $apiUser
      */
     $apiUser = $this->apiUserRepository->findUserByHash($command->hash);
     if (is_null($apiUser)) {
         throw new \RuntimeException('Your password reset link has expired.');
     }
     $apiUser->changePassword($command->password);
     $this->apiUserRepository->store($apiUser);
 }
 /**
  * Update Diamante and Api users related to current session
  *
  * @ApiDoc(
  *  description="Update current user",
  *  uri="/users/current.{_format}",
  *  method={
  *      "PATCH",
  *      "PUT"
  *  },
  *  resource=true,
  *  statusCodes={
  *      200="Returned when successful",
  *      403="Returned when the user is not authorized to update user",
  *      404="Returned when the user is not found"
  *  }
  * )
  *
  * @param UpdateUserCommand $command
  * @return DiamanteUser
  */
 public function update(UpdateUserCommand $command)
 {
     $apiUser = $this->authorizationService->getLoggedUser();
     $diamanteUser = $this->loadDiamanteUser($apiUser);
     if ($command->firstName) {
         $diamanteUser->setFirstName($command->firstName);
     }
     if ($command->lastName) {
         $diamanteUser->setLastName($command->lastName);
     }
     if ($command->password) {
         $apiUser->setPassword($command->password);
     }
     $this->diamanteUserRepository->store($diamanteUser);
     $this->apiUserRepository->store($apiUser);
     return $diamanteUser;
 }