fix: token for post authentication action and change phone and email (#5933)

* fix: token for post authentication action and change phone and email

* fix checks and add tests

* improve change checks and add tests

* add more tests

* remove unintended test

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Stefan Benz
2023-05-26 09:24:52 +02:00
committed by GitHub
parent d595177bcd
commit 9aed0319c5
6 changed files with 514 additions and 50 deletions

View File

@@ -33,12 +33,16 @@ func (c *Commands) ChangeHumanEmail(ctx context.Context, email *domain.Email, em
}
userAgg := UserAggregateFromWriteModel(&existingEmail.WriteModel)
changedEvent, hasChanged := existingEmail.NewChangedEvent(ctx, userAgg, email.EmailAddress)
if !hasChanged {
// only continue if there were changes or there were no changes and the email should be set to verified
if !hasChanged && !(email.IsEmailVerified && existingEmail.IsEmailVerified != email.IsEmailVerified) {
return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-2b7fM", "Errors.User.Email.NotChanged")
}
events := []eventstore.Command{changedEvent}
events := make([]eventstore.Command, 0)
if hasChanged {
events = append(events, changedEvent)
}
if email.IsEmailVerified {
events = append(events, user.NewHumanEmailVerifiedEvent(ctx, userAgg))
} else {