diff --git a/account/account.go b/account/account.go index 2bbed05..132421b 100644 --- a/account/account.go +++ b/account/account.go @@ -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 diff --git a/account/errors.go b/account/errors.go index 9e41192..3076715 100644 --- a/account/errors.go +++ b/account/errors.go @@ -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,