| @@ 27-72 (lines=46) @@ | ||
| 24 | * @author Beñat Espiña <[email protected]> |
|
| 25 | * @author Gorka Laucirica <[email protected]> |
|
| 26 | */ |
|
| 27 | class ByRequestRememberPasswordChangeUserPasswordHandler |
|
| 28 | { |
|
| 29 | /** |
|
| 30 | * The user password encoder. |
|
| 31 | * |
|
| 32 | * @var UserPasswordEncoder |
|
| 33 | */ |
|
| 34 | private $encoder; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * The user repository. |
|
| 38 | * |
|
| 39 | * @var UserRepository |
|
| 40 | */ |
|
| 41 | private $repository; |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Constructor. |
|
| 45 | * |
|
| 46 | * @param UserRepository $aRepository The user repository |
|
| 47 | * @param UserPasswordEncoder $anEncoder The password encoder |
|
| 48 | */ |
|
| 49 | public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder) |
|
| 50 | { |
|
| 51 | $this->repository = $aRepository; |
|
| 52 | $this->encoder = $anEncoder; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Handles the given command. |
|
| 57 | * |
|
| 58 | * @param ByRequestRememberPasswordChangeUserPasswordCommand $aCommand The command |
|
| 59 | * |
|
| 60 | * @throws UserDoesNotExistException when the user does not exist |
|
| 61 | */ |
|
| 62 | public function __invoke(ByRequestRememberPasswordChangeUserPasswordCommand $aCommand) |
|
| 63 | { |
|
| 64 | $user = $this->repository->userOfRememberPasswordToken(new UserToken($aCommand->rememberPasswordToken())); |
|
| 65 | if (null === $user) { |
|
| 66 | throw new UserDoesNotExistException(); |
|
| 67 | } |
|
| 68 | $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder)); |
|
| 69 | ||
| 70 | $this->repository->persist($user); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 27-72 (lines=46) @@ | ||
| 24 | * @author Beñat Espiña <[email protected]> |
|
| 25 | * @author Gorka Laucirica <[email protected]> |
|
| 26 | */ |
|
| 27 | class WithoutOldPasswordChangeUserPasswordHandler |
|
| 28 | { |
|
| 29 | /** |
|
| 30 | * The user password encoder. |
|
| 31 | * |
|
| 32 | * @var UserPasswordEncoder |
|
| 33 | */ |
|
| 34 | private $encoder; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * The user repository. |
|
| 38 | * |
|
| 39 | * @var UserRepository |
|
| 40 | */ |
|
| 41 | private $repository; |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Constructor. |
|
| 45 | * |
|
| 46 | * @param UserRepository $aRepository The user repository |
|
| 47 | * @param UserPasswordEncoder $anEncoder The password encoder |
|
| 48 | */ |
|
| 49 | public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder) |
|
| 50 | { |
|
| 51 | $this->repository = $aRepository; |
|
| 52 | $this->encoder = $anEncoder; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Handles the given command. |
|
| 57 | * |
|
| 58 | * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command |
|
| 59 | * |
|
| 60 | * @throws UserDoesNotExistException when the user does not exist |
|
| 61 | */ |
|
| 62 | public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand) |
|
| 63 | { |
|
| 64 | $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); |
|
| 65 | if (null === $user) { |
|
| 66 | throw new UserDoesNotExistException(); |
|
| 67 | } |
|
| 68 | $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder)); |
|
| 69 | ||
| 70 | $this->repository->persist($user); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 26-73 (lines=48) @@ | ||
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | * @author Gorka Laucirica <[email protected]> |
|
| 25 | */ |
|
| 26 | class LogInUserHandler |
|
| 27 | { |
|
| 28 | /** |
|
| 29 | * The user repository. |
|
| 30 | * |
|
| 31 | * @var UserRepository |
|
| 32 | */ |
|
| 33 | private $repository; |
|
| 34 | ||
| 35 | /** |
|
| 36 | * The user password encoder. |
|
| 37 | * |
|
| 38 | * @var UserPasswordEncoder |
|
| 39 | */ |
|
| 40 | private $encoder; |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Constructor. |
|
| 44 | * |
|
| 45 | * @param UserRepository $aRepository The user repository |
|
| 46 | * @param UserPasswordEncoder $anEncoder The password encoder |
|
| 47 | */ |
|
| 48 | public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder) |
|
| 49 | { |
|
| 50 | $this->repository = $aRepository; |
|
| 51 | $this->encoder = $anEncoder; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Handles the given command. |
|
| 56 | * |
|
| 57 | * @param LogInUserCommand $aCommand The command |
|
| 58 | * |
|
| 59 | * @throws UserDoesNotExistException when the user does not exist |
|
| 60 | * |
|
| 61 | * @return mixed |
|
| 62 | */ |
|
| 63 | public function __invoke(LogInUserCommand $aCommand) |
|
| 64 | { |
|
| 65 | $user = $this->repository->userOfEmail(new UserEmail($aCommand->email())); |
|
| 66 | if (null === $user) { |
|
| 67 | throw new UserDoesNotExistException(); |
|
| 68 | } |
|
| 69 | $user->login($aCommand->password(), $this->encoder); |
|
| 70 | ||
| 71 | $this->repository->persist($user); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||
| @@ 25-72 (lines=48) @@ | ||
| 22 | * |
|
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | */ |
|
| 25 | class UserOfEmailHandler |
|
| 26 | { |
|
| 27 | /** |
|
| 28 | * The user data transformer. |
|
| 29 | * |
|
| 30 | * @var UserDataTransformer |
|
| 31 | */ |
|
| 32 | private $dataTransformer; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * The user repository. |
|
| 36 | * |
|
| 37 | * @var UserRepository |
|
| 38 | */ |
|
| 39 | private $repository; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Constructor. |
|
| 43 | * |
|
| 44 | * @param UserRepository $aRepository The user repository |
|
| 45 | * @param UserDataTransformer $aDataTransformer The user data transformer |
|
| 46 | */ |
|
| 47 | public function __construct(UserRepository $aRepository, UserDataTransformer $aDataTransformer) |
|
| 48 | { |
|
| 49 | $this->repository = $aRepository; |
|
| 50 | $this->dataTransformer = $aDataTransformer; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Handles the given query. |
|
| 55 | * |
|
| 56 | * @param UserOfEmailQuery $aQuery The query |
|
| 57 | * |
|
| 58 | * @throws UserDoesNotExistException when the user does not exist |
|
| 59 | * @return mixed |
|
| 60 | */ |
|
| 61 | public function __invoke(UserOfEmailQuery $aQuery) |
|
| 62 | { |
|
| 63 | $user = $this->repository->userOfEmail(new UserEmail($aQuery->email())); |
|
| 64 | if (null === $user) { |
|
| 65 | throw new UserDoesNotExistException(); |
|
| 66 | } |
|
| 67 | ||
| 68 | $this->dataTransformer->write($user); |
|
| 69 | ||
| 70 | return $this->dataTransformer->read(); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||