-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5982a1a
commit 5ca1f73
Showing
76 changed files
with
608 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,21 @@ | |
|
||
namespace Galeas\Api\BoundedContext\Identity\User\Reaction\SendPrimaryEmailVerification; | ||
|
||
use Galeas\Api\BoundedContext\Identity\User\Aggregate\User; | ||
use Galeas\Api\BoundedContext\Identity\User\CommandHandler\VerifyPrimaryEmail\NoUserFoundForCode; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailChangeRequested; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\PrimaryEmailVerificationCodeSent; | ||
use Galeas\Api\BoundedContext\Identity\User\Event\SignedUp; | ||
use Galeas\Api\Common\Event\Event; | ||
use Galeas\Api\Common\ExceptionBase\EventStoreCannotRead; | ||
use Galeas\Api\Common\ExceptionBase\EventStoreCannotWrite; | ||
use Galeas\Api\Common\ExceptionBase\ProjectionCannotRead; | ||
use Galeas\Api\Common\ExceptionBase\QueuingFailure; | ||
use Galeas\Api\Common\Id\Id; | ||
use Galeas\Api\Service\Email\Emailer; | ||
use Galeas\Api\Service\EventStore\EventStore; | ||
use Galeas\Api\Service\QueueProcessor\EventReactor; | ||
|
||
class SendPrimaryEmailVerificationReactor | ||
class SendPrimaryEmailVerificationReactor implements EventReactor | ||
{ | ||
private EventStore $eventStore; | ||
|
||
|
@@ -29,7 +31,7 @@ public function __construct(EventStore $eventStore, Emailer $emailer) { | |
|
||
/** | ||
* @throws PrimaryEmailVerificationAlreadySent | ||
* @throws ProjectionCannotRead|EventStoreCannotRead|EventStoreCannotWrite|QueuingFailure | ||
* @throws ProjectionCannotRead|EventStoreCannotRead|EventStoreCannotWrite | ||
*/ | ||
public function react(Event $event): void | ||
{ | ||
|
@@ -47,32 +49,47 @@ public function react(Event $event): void | |
$newEventId = Id::createNewByHashing( | ||
"Identity/User/PrimaryEmailVerificationSent:" . $event->eventId()->id() | ||
); | ||
$existingEvent = $this->eventStore->findEvent($newEventId->id()); | ||
|
||
if ($existingEvent instanceof Event) { | ||
$existingReaction = $this->eventStore->findEvent($newEventId->id()); | ||
if ($existingReaction instanceof Event) { | ||
throw new PrimaryEmailVerificationAlreadySent(); | ||
} | ||
|
||
$fromEmailAddress = "system.development-application.example.com"; | ||
$subjectLine = "Your Verification Code"; | ||
$emailContents = "This is your verification code: https://example.com/page/?verificationCode=" . $verificationCode; | ||
$this->emailer->send( | ||
"[email protected]", | ||
"https://domain.example/frontend/verifyEmail?verificationCode=verificationCode", | ||
"text" | ||
$sendToEmailAddress, | ||
$subjectLine, | ||
$emailContents, | ||
$fromEmailAddress | ||
); | ||
|
||
$event = PrimaryEmailVerificationCodeSent::fromProperties( | ||
$newEventId, | ||
$event->aggregateId(), | ||
$event->eventId(), | ||
$aggregateAndEventIds = $this->eventStore->find($existingReaction->aggregateId()->id()); | ||
if (null === $aggregateAndEventIds) { | ||
throw new NoUserFoundForCode(); | ||
} | ||
|
||
$user = $aggregateAndEventIds->aggregate(); | ||
if (!($user instanceof User)) { | ||
throw new NoUserFoundForCode(); | ||
} | ||
|
||
$newEvent = PrimaryEmailVerificationCodeSent::new( | ||
Id::createNew(), | ||
$user->aggregateId(), | ||
$user->aggregateVersion() + 1, | ||
$aggregateAndEventIds->lastEventId(), | ||
$aggregateAndEventIds->firstEventId(), | ||
new \DateTimeImmutable("now"), | ||
[], | ||
$verificationCode, | ||
$sendToEmailAddress, | ||
"This is your verification code: https://example.com/page/?verificationCodeode=" . $verificationCode | ||
$emailContents, | ||
$fromEmailAddress, | ||
$subjectLine | ||
); | ||
|
||
$this->eventStore->save($event); | ||
try { | ||
$this->eventStore->completeTransaction(); | ||
} catch (\Exception $e) { | ||
// todo , duplicates -> return success | ||
} | ||
$this->eventStore->save($newEvent); | ||
$this->eventStore->completeTransaction(); | ||
} | ||
} |
Oops, something went wrong.