Jelajahi Sumber

test: 静默登录

hsun 6 bulan lalu
induk
melakukan
7b13d1a426
1 mengubah file dengan 51 tambahan dan 0 penghapusan
  1. 51 0
      controllers/user_login.go

+ 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 = "登录成功"
+}