fix: 设置登录IP和登录时间
This commit is contained in:
@@ -47,6 +47,10 @@ func Create(loginUser *vo.LoginUser, ilobArgs ...string) string {
|
||||
// 设置用户令牌有效期并存入缓存
|
||||
Cache(loginUser)
|
||||
|
||||
// 设置登录IP和登录时间
|
||||
loginUser.User.LoginIP = loginUser.IPAddr
|
||||
loginUser.User.LoginDate = loginUser.LoginTime
|
||||
|
||||
// 令牌算法 HS256 HS384 HS512
|
||||
algorithm := config.Get("jwt.algorithm").(string)
|
||||
var method *jwt.SigningMethodHMAC
|
||||
|
||||
@@ -73,6 +73,7 @@ func (s *AccountController) Login(c *gin.Context) {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
} else {
|
||||
s.accountService.UpdateLoginDateAndIP(&loginUser)
|
||||
s.sysLogLoginService.CreateSysLogLogin(
|
||||
loginBody.Username, commonConstants.STATUS_YES, "登录成功",
|
||||
ipaddr, location, os, browser,
|
||||
|
||||
@@ -10,6 +10,9 @@ type IAccount interface {
|
||||
// LoginByUsername 登录生成token
|
||||
LoginByUsername(username, password string) (vo.LoginUser, error)
|
||||
|
||||
// UpdateLoginDateAndIP 更新登录时间和IP
|
||||
UpdateLoginDateAndIP(loginUser *vo.LoginUser) bool
|
||||
|
||||
// ClearLoginRecordCache 清除错误记录次数
|
||||
ClearLoginRecordCache(username string) bool
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"ems.agt/src/framework/utils/crypto"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/vo"
|
||||
"ems.agt/src/modules/system/model"
|
||||
systemService "ems.agt/src/modules/system/service"
|
||||
)
|
||||
|
||||
@@ -105,6 +106,19 @@ func (s *AccountImpl) LoginByUsername(username, password string) (vo.LoginUser,
|
||||
return loginUser, nil
|
||||
}
|
||||
|
||||
// UpdateLoginDateAndIP 更新登录时间和IP
|
||||
func (s *AccountImpl) UpdateLoginDateAndIP(loginUser *vo.LoginUser) bool {
|
||||
sysUser := loginUser.User
|
||||
userInfo := model.SysUser{
|
||||
UserID: sysUser.UserID,
|
||||
LoginIP: sysUser.LoginIP,
|
||||
LoginDate: sysUser.LoginDate,
|
||||
UpdateBy: sysUser.UserName,
|
||||
}
|
||||
rows := s.sysUserService.UpdateUser(userInfo)
|
||||
return rows > 0
|
||||
}
|
||||
|
||||
// ClearLoginRecordCache 清除错误记录次数
|
||||
func (s *AccountImpl) ClearLoginRecordCache(username string) bool {
|
||||
cacheKey := cachekey.PWD_ERR_CNT_KEY + username
|
||||
|
||||
@@ -256,6 +256,8 @@ func (s *SysUserController) Edit(c *gin.Context) {
|
||||
|
||||
body.UserName = "" // 忽略修改登录用户名称
|
||||
body.Password = "" // 忽略修改密码
|
||||
body.LoginIP = "" // 忽略登录IP
|
||||
body.LoginDate = 0 // 忽略登录时间
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.sysUserService.UpdateUserAndRolePost(body)
|
||||
if rows > 0 {
|
||||
@@ -320,12 +322,12 @@ func (s *SysUserController) ResetPwd(c *gin.Context) {
|
||||
}
|
||||
|
||||
userName := ctx.LoginUserToUserName(c)
|
||||
SysUserController := model.SysUser{
|
||||
info := model.SysUser{
|
||||
UserID: body.UserID,
|
||||
Password: body.Password,
|
||||
UpdateBy: userName,
|
||||
}
|
||||
rows := s.sysUserService.UpdateUser(SysUserController)
|
||||
rows := s.sysUserService.UpdateUser(info)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
@@ -360,12 +362,12 @@ func (s *SysUserController) Status(c *gin.Context) {
|
||||
}
|
||||
|
||||
userName := ctx.LoginUserToUserName(c)
|
||||
SysUserController := model.SysUser{
|
||||
info := model.SysUser{
|
||||
UserID: body.UserID,
|
||||
Status: body.Status,
|
||||
UpdateBy: userName,
|
||||
}
|
||||
rows := s.sysUserService.UpdateUser(SysUserController)
|
||||
rows := s.sysUserService.UpdateUser(info)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user