fix: 设置登录IP和登录时间

This commit is contained in:
TsMask
2023-10-21 17:43:17 +08:00
parent 7aca7b2fc1
commit ec76e34576
5 changed files with 28 additions and 4 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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