fix(login):修复用户登录。
This commit is contained in:
parent
1e2c4fd724
commit
2b453da668
|
@ -33,18 +33,20 @@ func InitializeUserController(router *gin.Engine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginFormData struct {
|
type LoginFormData struct {
|
||||||
Username string `form:"uname"`
|
Username string `json:"uname"`
|
||||||
Password string `form:"upass"`
|
Password string `json:"upass"`
|
||||||
Type int8 `form:"type"`
|
Type int8 `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_UserController) Login(c *gin.Context) {
|
func (_UserController) Login(c *gin.Context) {
|
||||||
result := response.NewResult(c)
|
result := response.NewResult(c)
|
||||||
loginData := new(LoginFormData)
|
loginData := new(LoginFormData)
|
||||||
c.BindJSON(loginData)
|
err := c.BindJSON(loginData)
|
||||||
|
if err != nil {
|
||||||
|
result.Error(http.StatusInternalServerError, "表单解析失败。")
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
session *model.Session
|
session *model.Session
|
||||||
err error
|
|
||||||
)
|
)
|
||||||
if loginData.Type == 0 {
|
if loginData.Type == 0 {
|
||||||
session, err = service.UserService.ProcessEnterpriseUserLogin(loginData.Username, loginData.Password)
|
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)
|
session, err = service.UserService.ProcessManagementUserLogin(loginData.Username, loginData.Password)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, &exceptions.AuthenticationError{}) {
|
if authError, ok := err.(*exceptions.AuthenticationError); ok {
|
||||||
authError := err.(exceptions.AuthenticationError)
|
|
||||||
if authError.NeedReset {
|
if authError.NeedReset {
|
||||||
result.LoginNeedReset()
|
result.LoginNeedReset()
|
||||||
return
|
return
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
BaseResponse
|
BaseResponse
|
||||||
NeedReset bool `json:"needReset"`
|
NeedReset bool `json:"needReset"`
|
||||||
Session *model.Session `json:"session,omitempty"`
|
Session *model.Session `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Result) LoginSuccess(session *model.Session) {
|
func (r *Result) LoginSuccess(session *model.Session) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user