/** * 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 query. * * @param UserOfEmailQuery $aQuery The query * * @throws UserDoesNotExistException when the user does not exist * * @return mixed */ public function __invoke(UserOfEmailQuery $aQuery) { $user = $this->repository->userOfEmail(new UserEmail($aQuery->email())); if (null === $user) { throw new UserDoesNotExistException(); } $this->dataTransformer->write($user); return $this->dataTransformer->read(); }
/** * 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 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 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 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); }
function it_does_not_invite_when_user_already_exists(UserRepository $userRepository, User $user, InviteUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn($user); $this->shouldThrow(UserAlreadyExistException::class)->during__invoke($command); }
function it_does_not_invite_when_the_user_does_not_exist(UserRepository $userRepository, ResendInvitationUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $userRepository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_get_the_user_because_the_email_does_not_exist(UserRepository $repository, UserOfEmailQuery $query) { $query->email()->shouldBeCalled()->willReturn('*****@*****.**'); $email = new UserEmail('*****@*****.**'); $repository->userOfEmail($email)->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($query); }
/** * 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_does_not_sign_up_if_user_email_already_exists(WithConfirmationSignUpUserCommand $command, UserRepository $repository, 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($user); $this->shouldThrow(UserAlreadyExistException::class)->during__invoke($command); }
function it_does_not_request_remember_password_because_user_does_not_exist(RequestRememberPasswordCommand $command, UserRepository $repository) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_changes_password_because_the_does_not_exist(WithoutOldPasswordChangeUserPasswordCommand $command, UserRepository $repository) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }
function it_does_not_log_if_user_does_not_exist(UserRepository $repository, LogInUserCommand $command) { $command->email()->shouldBeCalled()->willReturn('*****@*****.**'); $repository->userOfEmail(new UserEmail('*****@*****.**'))->shouldBeCalled()->willReturn(null); $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command); }