diff --git a/service/user/cookie_helper.go b/service/user/cookie_helper.go index ddb35bf6..06efbfea 100644 --- a/service/user/cookie_helper.go +++ b/service/user/cookie_helper.go @@ -90,6 +90,7 @@ func SetCookieHandler(w http.ResponseWriter, r *http.Request, email string, pass messages := msg.GetMessages(r) // search by email or username isValidEmail := formStruct.EmailValidation(email, messages) + messages.ClearErrors("email") // We need to clear the error added on messages if isValidEmail { if db.ORM.Where("email = ?", email).First(&user).RecordNotFound() { return http.StatusNotFound, errors.New("User not found") diff --git a/service/user/form/form_validator.go b/service/user/form/form_validator.go index afdfe00d..ec26c556 100644 --- a/service/user/form/form_validator.go +++ b/service/user/form/form_validator.go @@ -18,8 +18,10 @@ func EmailValidation(email string, mes *msg.Messages) bool { if exp.MatchString(email) { return true } + mes.AddErrorT("email", "email_not_valid") + return false } - mes.AddError("email", "Email Address is not valid") + mes.AddError("errors", "Regexp couldn't be parsed!") return false } @@ -28,13 +30,13 @@ func ValidateUsername(username string, mes *msg.Messages) bool { exp, errorRegex := regexp.Compile(usernameRegex) if regexpCompiled := log.CheckError(errorRegex); regexpCompiled { if exp.MatchString(username) { - mes.AddError("username", "Username contains illegal characters") + mes.AddErrorT("username", "username_illegal") return false } - } else { - return false + return true } - return true + mes.AddError("errors", "Regexp couldn't be parsed!") + return false } // IsAgreed : Check if terms and conditions are valid diff --git a/translations/en-us.all.json b/translations/en-us.all.json index 69937e01..85acb602 100644 --- a/translations/en-us.all.json +++ b/translations/en-us.all.json @@ -1214,5 +1214,13 @@ { "id": "report_msg", "translation": "The torrent #%s has been reported!" + }, + { + "id": "email_not_valid", + "translation": "Email Address is not valid!" + }, + { + "id": "username_illegal", + "translation": "Username contains illegal characters!" } ] diff --git a/util/messages/messages.go b/util/messages/messages.go index 75206936..3f1f94b1 100644 --- a/util/messages/messages.go +++ b/util/messages/messages.go @@ -87,15 +87,27 @@ func (mes *Messages) AddInfoT(name string, id string) { mes.AddInfo(name, mes.T(id)) } -// ClearErrors : Erase all errors in messages -func (mes *Messages) ClearErrors() { +// ClearAllErrors : Erase all errors in messages +func (mes *Messages) ClearAllErrors() { + mes.Errors = nil + mes.setMessagesInContext() +} + +// ClearAllInfos : Erase all infos in messages +func (mes *Messages) ClearAllInfos() { mes.Infos = nil mes.setMessagesInContext() } +// ClearErrors : Erase all errors in messages +func (mes *Messages) ClearErrors(name string) { + mes.Errors[name] = nil + mes.setMessagesInContext() +} + // ClearInfos : Erase all infos in messages -func (mes *Messages) ClearInfos() { - mes.Errors = nil +func (mes *Messages) ClearInfos(name string) { + mes.Infos[name] = nil mes.setMessagesInContext() }