diff --git a/cmd/server/app/network/controller/user.go b/cmd/server/app/network/controller/user.go index 48c77fdb3a614799adbc258425b7df0668130154..5f34087c6b00ea60942ef3c4aa652d9d02d6d3d7 100644 --- a/cmd/server/app/network/controller/user.go +++ b/cmd/server/app/network/controller/user.go @@ -15,7 +15,9 @@ package controller import ( + "fmt" "net/http" + "regexp" "strconv" "strings" "time" @@ -84,6 +86,19 @@ func LoginHandler(c *gin.Context) { return } + // 输入email格式校验 + if user.Email != "admin" { + patt := `^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$` + if match, err := regexp.MatchString(patt, user.Email); err != nil || !match { + if err != nil { + response.Fail(c, nil, fmt.Sprintf("email format error: %s, %s", user.Email, err.Error())) + return + } + response.Fail(c, nil, fmt.Sprintf("email format error: %s", user.Email)) + return + } + } + u, err := userservice.GetUserByEmail(user.Email) if err != nil { response.Fail(c, nil, err.Error())