hsun 6 сар өмнө
parent
commit
7b13d1a426

+ 51 - 0
controllers/user_login.go

@@ -1062,3 +1062,54 @@ func (this *UserLoginController) BaseInfo() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+// UsernameLogin
+// @Title 用户登录
+// @Description 用户登录
+// @Param	request	body UsernameLoginReq true "type json string"
+// @Success 200 {object} models.LoginResp
+// @router /username_login [post]
+func (this *UserLoginController) UsernameLogin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	type UsernameLoginReq struct {
+		AdminName string `description:"账号"`
+	}
+	var req UsernameLoginReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	resp, e := services.UserLoginChange(req.AdminName)
+	if e != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = fmt.Sprintf("登录失败, %v", e)
+		return
+	}
+
+	// 新增登录记录
+	go func() {
+		record := new(system.SysUserLoginRecord)
+		record.Uid = resp.AdminId
+		record.UserName = req.AdminName
+		record.Ip = this.Ctx.Input.IP()
+		record.Stage = "login"
+		record.CreateTime = time.Now()
+		_ = system.AddSysUserLoginRecord(record)
+	}()
+
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "登录成功"
+}