refactor: handle both user verification, and changing email

This commit is contained in:
Derrick Hammer 2024-02-26 10:35:57 -05:00
parent 5c6224222f
commit 036520581f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 18 additions and 2 deletions

View File

@ -155,12 +155,28 @@ func (s AccountServiceDefault) VerifyEmail(email string, token string) error {
return NewAccountError(ErrKeySecurityTokenExpired, nil)
}
if verification.User.Email != email {
if len(verification.NewEmail) > 0 && verification.NewEmail != email {
return NewAccountError(ErrKeySecurityInvalidToken, nil)
} else if verification.User.Email != email {
return NewAccountError(ErrKeySecurityInvalidToken, nil)
}
var update models.User
doUpdate := false
if !verification.User.Verified {
err := s.updateAccountInfo(verification.UserID, models.User{Verified: true})
update.Verified = true
doUpdate = true
}
if len(verification.NewEmail) > 0 {
update.Email = verification.NewEmail
doUpdate = true
}
if doUpdate {
err := s.updateAccountInfo(verification.UserID, update)
if err != nil {
return err
}