fix(login):修复用户登录。
This commit is contained in:
parent
1e2c4fd724
commit
2b453da668
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user