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) {