From 2b453da668560d0b85fafbe9a5c6b8aac0cbd098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sat, 13 Aug 2022 05:53:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(login):=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/user.go | 15 ++++++++------- response/user_response.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/controller/user.go b/controller/user.go index 1d38c77..4c6b50b 100644 --- a/controller/user.go +++ b/controller/user.go @@ -33,18 +33,20 @@ func InitializeUserController(router *gin.Engine) { } type LoginFormData struct { - Username string `form:"uname"` - Password string `form:"upass"` - Type int8 `form:"type"` + Username string `json:"uname"` + Password string `json:"upass"` + Type int8 `json:"type"` } func (_UserController) Login(c *gin.Context) { result := response.NewResult(c) loginData := new(LoginFormData) - c.BindJSON(loginData) + err := c.BindJSON(loginData) + if err != nil { + result.Error(http.StatusInternalServerError, "表单解析失败。") + } var ( session *model.Session - err error ) if loginData.Type == 0 { session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password) @@ -52,8 +54,7 @@ func (_UserController) Login(c *gin.Context) { session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password) } if err != nil { - if errors.Is(err, &exceptions.AuthenticationError{}) { - authError := err.(exceptions.AuthenticationError) + if authError, ok := err.(*exceptions.AuthenticationError); ok { if authError.NeedReset { result.LoginNeedReset() return diff --git a/response/user_response.go b/response/user_response.go index e796fe7..eb488db 100644 --- a/response/user_response.go +++ b/response/user_response.go @@ -8,7 +8,7 @@ import ( type LoginResponse struct { BaseResponse NeedReset bool `json:"needReset"` - Session *model.Session `json:"session,omitempty"` + Session *model.Session `json:"session"` } func (r *Result) LoginSuccess(session *model.Session) {