/** * Handles the given command. * * @param GrantUserRoleCommand $aCommand The command * * @throws UserDoesNotExistException when user does not exist */ public function __invoke(GrantUserRoleCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $user->grant(new UserRole($aCommand->role())); $this->repository->persist($user); }
/** * Handles the given command. * * @param ResendInvitationUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(ResendInvitationUserCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->regenerateInvitationToken(); $this->repository->persist($user); }
/** * 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 LogOutUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(LogOutUserCommand $aCommand) { $user = $this->repository->userOfId(new UserId($aCommand->id())); if (null === $user) { throw new UserDoesNotExistException(); } $user->logout(); $this->repository->persist($user); }
/** * Handles the given command. * * @param RequestRememberPasswordCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(RequestRememberPasswordCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->rememberPassword(); $this->repository->persist($user); }
/** * Handles the given command. * * @param LogInUserCommand $aCommand The command * * @throws UserDoesNotExistException when the user does not exist */ public function __invoke(LogInUserCommand $aCommand) { $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); if (null === $user) { throw new UserDoesNotExistException(); } $user->login($aCommand->password(), $this->encoder); $this->repository->persist($user); }
/** * Handles the given command. * * @param EnableUserCommand $aCommand The command * * @throws UserTokenNotFoundException when the user token does not exist */ public function __invoke(EnableUserCommand $aCommand) { $confirmationToken = $aCommand->confirmationToken(); $user = $this->repository->userOfConfirmationToken(new UserToken($confirmationToken)); if (null === $user) { throw new UserTokenNotFoundException(); } $user->enableAccount(); $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); }
/** * Handles the given command. * * @param InviteUserCommand $aCommand The command * * @throws UserAlreadyExistException when the user already exists */ public function __invoke(InviteUserCommand $aCommand) { $email = new UserEmail($aCommand->email()); $user = $this->repository->userOfEmail($email); if (null !== $user) { throw new UserAlreadyExistException(); } $user = $this->factory->build(new UserId($aCommand->id()), $email, array_map(function ($role) { return new UserRole($role); }, $aCommand->roles())); $this->repository->persist($user); }
/** * 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_doesnt_activate_user_with_wrong_token(UserRepository $repository, User $user, EnableUserCommand $command) { $command->confirmationToken()->shouldBeCalled()->willReturn('confirmation-token'); $user->enableAccount()->shouldNotBeCalled(); $repository->userOfConfirmationToken(new UserToken('confirmation-token'))->shouldBeCalled()->willReturn(null); $repository->persist($user)->shouldNotBeCalled(); $this->shouldThrow(UserTokenNotFoundException::class)->during__invoke($command); }
function it_logs_the_user_out(UserRepository $repository, User $user, LogOutUserCommand $command) { $command->id()->shouldBeCalled()->willReturn('user-id'); $repository->userOfId(new UserId('user-id'))->shouldBeCalled()->willReturn($user); $user->logout()->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_resends_user_invitation(ResendInvitationUserCommand $command, UserRepository $userRepository, User $user) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn($user); $userRepository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_requests_remember_password(RequestRememberPasswordCommand $command, UserRepository $repository, User $user) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn($user); $user->rememberPassword()->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_changes_password(WithoutOldPasswordChangeUserPasswordCommand $command, UserRepository $repository, User $user) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn($user); $command->newPlainPassword()->shouldBeCalled()->willReturn('new-plain-pass'); $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_signs_the_user_up(ByInvitationSignUpUserCommand $command, UserRepository $repository, User $user) { $command->invitationToken()->shouldBeCalled()->willReturn('invitation-token'); $repository->userOfInvitationToken(new UserToken('invitation-token'))->shouldBeCalled()->willReturn($user); $command->password()->shouldBeCalled()->willReturn('plain-password'); $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled(); $user->acceptInvitation()->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_logs_the_user_in(LogInUserCommand $command, UserRepository $repository, User $user) { $encoder = new DummyUserPasswordEncoder('encodedPassword'); $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $command->password()->shouldBeCalled()->willReturn('plainPassword'); $user->login('plainPassword', $encoder)->shouldBeCalled(); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn($user); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_changes_password(ByRequestRememberPasswordChangeUserPasswordCommand $command, UserRepository $repository, User $user) { $command->rememberPasswordToken()->shouldBeCalled()->willReturn('remember-password-token'); $repository->userOfRememberPasswordToken(new UserToken('remember-password-token'))->shouldBeCalled()->willReturn($user); $command->newPlainPassword()->shouldBeCalled()->willReturn('new-plain-pass'); $user->isRememberPasswordTokenExpired()->shouldBeCalled()->willReturn(false); $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_revokes_the_user_role(RevokeUserRoleCommand $command, UserRepository $repository, User $user) { $command->id()->shouldBeCalled()->willReturn('user-id'); $command->role()->shouldBeCalled()->willReturn('ROLE_USER'); $id = new UserId('user-id'); $role = new UserRole('ROLE_USER'); $repository->userOfId($id)->shouldBeCalled()->willReturn($user); $user->revoke($role)->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_invites_user(InviteUserCommand $command, UserRepository $userRepository, UserFactoryInvite $factory, User $user) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $command->roles()->shouldBeCalled()->willReturn(['ROLE_USER']); $roles = [new UserRole('ROLE_USER')]; $command->id()->shouldBeCalled()->willReturn('user-id'); $id = new UserId('user-id'); $factory->build($id, $email, $roles)->shouldBeCalled()->willReturn($user); $userRepository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_changes_password(ChangeUserPasswordCommand $command, UserRepository $repository, User $user) { $encoder = new DummyUserPasswordEncoder('encoded-pass'); $userPassword = UserPassword::fromPlain('old-plain-pass', $encoder, 'dummy-salt'); $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'); $command->newPlainPassword()->shouldBeCalled()->willReturn('new-plain-pass'); $user->changePassword(Argument::type(UserPassword::class))->shouldBeCalled(); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }
function it_signs_the_user_up(WithConfirmationSignUpUserCommand $command, UserRepository $repository, UserFactorySignUp $factory, User $user) { $command->id()->shouldBeCalled()->willReturn('user-id'); $id = new UserId('user-id'); $repository->userOfId($id)->shouldBeCalled()->willReturn(null); $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $repository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $command->password()->shouldBeCalled()->willReturn('plain-password'); $command->roles()->shouldBeCalled()->willReturn(['ROLE_USER']); $roles = [new UserRole('ROLE_USER')]; $factory->build($id, $email, Argument::type(UserPassword::class), $roles)->shouldBeCalled()->willReturn($user); $repository->persist($user)->shouldBeCalled(); $this->__invoke($command); }