Example #1
0
 function it_builds()
 {
     $this->beConstructedWith(User::class);
     $this->shouldHaveType(UserFactorySignUp::class);
     $this->shouldImplement(BaseUserFactorySignUp::class);
     $this->build(new UserId('user-id'), new UserEmail('*****@*****.**'), UserPassword::fromEncoded('encoded-pass', null), [new UserRole('ROLE_USER')])->shouldReturnAnInstanceOf(User::class);
 }
 /**
  * Handles the given command.
  *
  * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command
  *
  * @throws UserDoesNotExistException when the user does not exist
  */
 public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand)
 {
     $user = $this->repository->userOfEmail(new UserEmail($aCommand->email()));
     if (null === $user) {
         throw new UserDoesNotExistException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
     $this->repository->persist($user);
 }
 /**
  * Handles the given command.
  *
  * @param ByInvitationSignUpUserCommand $aCommand The command
  *
  * @throws UserDoesNotExistException when the user does not exist
  */
 public function __invoke(ByInvitationSignUpUserCommand $aCommand)
 {
     $user = $this->userRepository->userOfInvitationToken(new UserToken($aCommand->invitationToken()));
     if (null === $user) {
         throw new UserDoesNotExistException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->password(), $this->encoder));
     $user->acceptInvitation();
     $this->userRepository->persist($user);
 }
 function it_does_not_change_password_because_user_password_is_invalid(ChangeUserPasswordCommand $command, UserRepository $repository, User $user)
 {
     $encoder = new DummyUserPasswordEncoder('encoded-pass', false);
     $userPassword = UserPassword::fromPlain('plain-pass', $encoder, 'dummy-salt');
     $this->beConstructedWith($repository, $encoder);
     $command->id()->shouldBeCalled()->willReturn('user-id');
     $repository->userOfId(new UserId('user-id'))->shouldBeCalled()->willReturn($user);
     $user->password()->shouldBeCalled()->willReturn($userPassword);
     $command->oldPlainPassword()->shouldBeCalled()->willReturn('old-plain-pass');
     $this->shouldThrow(UserPasswordInvalidException::class)->during__invoke($command);
 }
 /**
  * Handles the given command.
  *
  * @param ByRequestRememberPasswordChangeUserPasswordCommand $aCommand The command
  *
  * @throws UserTokenNotFoundException when the user does not exist
  * @throws UserTokenExpiredException  when the token is expired
  */
 public function __invoke(ByRequestRememberPasswordChangeUserPasswordCommand $aCommand)
 {
     $user = $this->repository->userOfRememberPasswordToken(new UserToken($aCommand->rememberPasswordToken()));
     if (null === $user) {
         throw new UserTokenNotFoundException();
     }
     if ($user->isRememberPasswordTokenExpired()) {
         throw new UserTokenExpiredException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
     $this->repository->persist($user);
 }
 /**
  * Handles the given command.
  *
  * @param ChangeUserPasswordCommand $aCommand The command
  *
  * @throws UserDoesNotExistException    when the user does not exist
  * @throws UserPasswordInvalidException when the user password is invalid
  */
 public function __invoke(ChangeUserPasswordCommand $aCommand)
 {
     $user = $this->repository->userOfId(new UserId($aCommand->id()));
     if (null === $user) {
         throw new UserDoesNotExistException();
     }
     if (false === $user->password()->equals($aCommand->oldPlainPassword(), $this->encoder)) {
         throw new UserPasswordInvalidException();
     }
     $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
     $this->repository->persist($user);
 }
 /**
  * Handles the given command.
  *
  * @param WithConfirmationSignUpUserCommand $aCommand The command
  *
  * @throws UserAlreadyExistException when the user id is already exists
  */
 public function __invoke(WithConfirmationSignUpUserCommand $aCommand)
 {
     $id = new UserId($aCommand->id());
     if (null !== $this->repository->userOfId($id)) {
         throw new UserAlreadyExistException();
     }
     $email = new UserEmail($aCommand->email());
     if (null !== $this->repository->userOfEmail($email)) {
         throw new UserAlreadyExistException();
     }
     $userRoles = array_map(function ($role) {
         return new UserRole($role);
     }, $aCommand->roles());
     $user = $this->factory->build($id, $email, UserPassword::fromPlain($aCommand->password(), $this->encoder), $userRoles);
     $this->repository->persist($user);
 }
 function it_transforms(User $user, \DateTimeImmutable $createdOn, \DateTimeImmutable $lastLogin, \DateTimeImmutable $updatedOn)
 {
     $this->read()->shouldReturn([]);
     $this->write($user);
     $user->roles()->shouldBeCalled()->willReturn([new UserRole('ROLE_USER')]);
     $password = UserPassword::fromEncoded('encoded-password', 'user-password-salt');
     $user->id()->shouldBeCalled()->willReturn(new UserId('user-id'));
     $user->confirmationToken()->shouldBeCalled()->willReturn(null);
     $user->createdOn()->shouldBeCalled()->willReturn($createdOn);
     $user->email()->shouldBeCalled()->willReturn(new UserEmail('*****@*****.**'));
     $user->invitationToken()->shouldBeCalled()->willReturn(null);
     $user->lastLogin()->shouldBeCalled()->willReturn($lastLogin);
     $user->password()->shouldBeCalled()->willReturn($password);
     $user->rememberPasswordToken()->shouldBeCalled()->willReturn(null);
     $user->updatedOn()->shouldBeCalled()->willReturn($updatedOn);
     $this->read()->shouldReturn(['id' => 'user-id', 'confirmation_token' => null, 'created_on' => $createdOn, 'email' => '*****@*****.**', 'invitation_token' => null, 'last_login' => $lastLogin, 'encoded_password' => 'encoded-password', 'salt' => 'user-password-salt', 'remember_password_token' => null, 'roles' => ['ROLE_USER'], 'updated_on' => $updatedOn]);
 }
Example #9
0
 /**
  * Builds the user with the given sql row attributes.
  *
  * @param array $row Array which contains attributes of user
  *
  * @return User
  */
 private function buildUser($row)
 {
     $createdOn = new \DateTimeImmutable($row['created_on']);
     $updatedOn = new \DateTimeImmutable($row['updated_on']);
     $lastLogin = null === $row['last_login'] ? null : new \DateTimeImmutable($row['last_login']);
     $confirmationToken = null;
     if (null !== $row['confirmation_token_token']) {
         $confirmationToken = new UserToken($row['confirmation_token_token']);
         $this->set($confirmationToken, 'createdOn', new \DateTimeImmutable($row['confirmation_token_created_on']));
     }
     $invitationToken = null;
     if (null !== $row['invitation_token_token']) {
         $invitationToken = new UserToken($row['invitation_token_token']);
         $this->set($invitationToken, 'createdOn', new \DateTimeImmutable($row['invitation_token_created_on']));
     }
     $rememberPasswordToken = null;
     if (null !== $row['remember_password_token_token']) {
         $rememberPasswordToken = new UserToken($row['remember_password_token_token']);
         $this->set($rememberPasswordToken, 'createdOn', new \DateTimeImmutable($row['remember_password_token_created_on']));
     }
     $user = User::signUp(new UserId($row['id']), new UserEmail($row['email']), UserPassword::fromEncoded($row['password'], $row['salt']), $this->rolesToArray($row['roles']));
     $user = $this->set($user, 'createdOn', $createdOn);
     $user = $this->set($user, 'updatedOn', $updatedOn);
     $user = $this->set($user, 'lastLogin', $lastLogin);
     $user = $this->set($user, 'confirmationToken', $confirmationToken);
     $user = $this->set($user, 'invitationToken', $invitationToken);
     $user = $this->set($user, 'rememberPasswordToken', $rememberPasswordToken);
     return $user;
 }
Example #10
0
 function let()
 {
     $encoder = new DummyUserPasswordEncoder('encodedPassword');
     $this->beConstructedSignUp(new UserId(), new UserEmail('*****@*****.**'), UserPassword::fromPlain('strongpassword', $encoder), [new UserRole('ROLE_USER')]);
 }
Example #11
0
 function it_changes_password()
 {
     $encoder = new DummyUserPasswordEncoder('encodedPassword');
     $newPassword = UserPassword::fromPlain('strongnewpassword', $encoder);
     $this->rememberPassword();
     $this->rememberPasswordToken()->shouldReturnAnInstanceOf(UserToken::class);
     $this->changePassword($newPassword);
     $this->rememberPasswordToken()->shouldReturn(null);
     $this->password()->shouldReturn($newPassword);
 }