/** * 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 let() { $encoder = new DummyUserPasswordEncoder('encodedPassword'); $this->beConstructedSignUp(new UserId(), new UserEmail('*****@*****.**'), UserPassword::fromPlain('strongpassword', $encoder), [new UserRole('ROLE_USER')]); }
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); }