Compare commits

..

2 Commits

2 changed files with 14 additions and 4 deletions

View File

@ -134,6 +134,10 @@ func (s AccountServiceDefault) SendEmailVerification(userId uint) error {
return err return err
} }
if user.Verified {
return NewAccountError(ErrKeyAccountAlreadyVerified, nil)
}
token := GenerateSecurityToken() token := GenerateSecurityToken()
var verification models.EmailVerification var verification models.EmailVerification
@ -198,7 +202,7 @@ func (s AccountServiceDefault) VerifyEmail(email string, token string) error {
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return NewAccountError(ErrKeyUserNotFound, result.Error) return NewAccountError(ErrKeyEmailVerificationFailed, result.Error)
} }
return NewAccountError(ErrKeyDatabaseOperationFailed, result.Error) return NewAccountError(ErrKeyDatabaseOperationFailed, result.Error)

View File

@ -26,6 +26,8 @@ const (
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed" ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed"
ErrKeyAccountAlreadyVerified = "ErrAccountAlreadyVerified"
ErrKeyEmailVerificationFailed = "ErrEmailVerificationFailed"
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed = "ErrJWTGenerationFailed" ErrKeyJWTGenerationFailed = "ErrJWTGenerationFailed"
@ -73,6 +75,8 @@ var defaultErrorMessages = map[string]string{
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed: "Failed to update account information.", ErrKeyAccountUpdateFailed: "Failed to update account information.",
ErrKeyAccountAlreadyVerified: "Account is already verified.",
ErrKeyEmailVerificationFailed: "Failed to verify email address.",
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed: "Failed to generate a new JWT token.", ErrKeyJWTGenerationFailed: "Failed to generate a new JWT token.",
@ -119,6 +123,8 @@ var (
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed: http.StatusInternalServerError, ErrKeyAccountUpdateFailed: http.StatusInternalServerError,
ErrKeyAccountAlreadyVerified: http.StatusConflict,
ErrKeyEmailVerificationFailed: http.StatusInternalServerError,
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed: http.StatusInternalServerError, ErrKeyJWTGenerationFailed: http.StatusInternalServerError,