Commit bed4a3f9 by CaIon

fix(user): trim whitespace from username and validate input

parent 12603a77
...@@ -190,6 +190,11 @@ func Register(c *gin.Context) { ...@@ -190,6 +190,11 @@ func Register(c *gin.Context) {
common.ApiErrorI18n(c, i18n.MsgInvalidParams) common.ApiErrorI18n(c, i18n.MsgInvalidParams)
return return
} }
user.Username = strings.TrimSpace(user.Username)
if user.Username == "" {
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
return
}
if err := common.Validate.Struct(&user); err != nil { if err := common.Validate.Struct(&user); err != nil {
common.ApiErrorI18n(c, i18n.MsgUserInputInvalid, map[string]any{"Error": err.Error()}) common.ApiErrorI18n(c, i18n.MsgUserInputInvalid, map[string]any{"Error": err.Error()})
return return
...@@ -631,6 +636,11 @@ func UpdateUser(c *gin.Context) { ...@@ -631,6 +636,11 @@ func UpdateUser(c *gin.Context) {
common.ApiErrorI18n(c, i18n.MsgInvalidParams) common.ApiErrorI18n(c, i18n.MsgInvalidParams)
return return
} }
updatedUser.Username = strings.TrimSpace(updatedUser.Username)
if updatedUser.Username == "" {
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
return
}
if updatedUser.Password == "" { if updatedUser.Password == "" {
updatedUser.Password = "$I_LOVE_U" // make Validator happy :) updatedUser.Password = "$I_LOVE_U" // make Validator happy :)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment