Replaced hardcoded message errors in email validation
Added some translation string Improved the way the emails and usernames are checked (less conditions) Minor fix on clear error functions
Cette révision appartient à :
Parent
1675b12cad
révision
ee0e611d11
4 fichiers modifiés avec 32 ajouts et 9 suppressions
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket