Skip to content

Commit 45611b5

Browse files
committed
check empty input
1 parent 03b7704 commit 45611b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

routers/api/v1/admin/user.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,19 @@ func EditUser(ctx *context.APIContext) {
206206
}
207207
var emailChanged bool
208208
if form.Email != nil {
209-
if err := user_model.ValidateEmail(*form.Email); err != nil {
210-
ctx.InternalServerError(err)
209+
email := strings.TrimSpace(*form.Email)
210+
if len(email) == 0 {
211+
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("email is not allowed to be empty string"))
211212
return
212213
}
213214

214-
emailChanged = !strings.EqualFold(u.Email, *form.Email)
215-
u.Email = *form.Email
216-
if len(u.Email) == 0 {
217-
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("email is not allowed to be empty string"))
215+
if err := user_model.ValidateEmail(email); err != nil {
216+
ctx.InternalServerError(err)
218217
return
219218
}
219+
220+
emailChanged = !strings.EqualFold(u.Email, email)
221+
u.Email = email
220222
}
221223
if form.Website != nil {
222224
u.Website = *form.Website

0 commit comments

Comments
 (0)