fix: 设置登录IP和登录时间
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user