fix: if user is already verified, abort

This commit is contained in:
Derrick Hammer 2024-03-26 20:17:41 -04:00
parent 12a9ad28fd
commit 64eea68a84
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 3 deletions

View File

@ -134,6 +134,10 @@ func (s AccountServiceDefault) SendEmailVerification(userId uint) error {
return err
}
if user.Verified {
return NewAccountError(ErrKeyAccountAlreadyVerified, nil)
}
token := GenerateSecurityToken()
var verification models.EmailVerification

View File

@ -25,7 +25,8 @@ const (
ErrKeyHashingFailed = "ErrHashingFailed"
// Account update errors
ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed"
ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed"
ErrKeyAccountAlreadyVerified = "ErrAccountAlreadyVerified"
// JWT generation errors
ErrKeyJWTGenerationFailed = "ErrJWTGenerationFailed"
@ -72,7 +73,8 @@ var defaultErrorMessages = map[string]string{
ErrKeyLoginFailed: "Login failed due to an internal error.",
// Account update errors
ErrKeyAccountUpdateFailed: "Failed to update account information.",
ErrKeyAccountUpdateFailed: "Failed to update account information.",
ErrKeyAccountAlreadyVerified: "Account is already verified.",
// JWT generation errors
ErrKeyJWTGenerationFailed: "Failed to generate a new JWT token.",
@ -118,7 +120,8 @@ var (
ErrKeyLoginFailed: http.StatusInternalServerError,
// Account update errors
ErrKeyAccountUpdateFailed: http.StatusInternalServerError,
ErrKeyAccountUpdateFailed: http.StatusInternalServerError,
ErrKeyAccountAlreadyVerified: http.StatusConflict,
// JWT generation errors
ErrKeyJWTGenerationFailed: http.StatusInternalServerError,