允许单个账号在同一个IP登录多个客户端

This commit is contained in:
GoEdgeLab
2024-05-03 12:09:27 +08:00
parent a38ea6d778
commit 466107553e
2 changed files with 16 additions and 4 deletions

View File

@@ -73,7 +73,7 @@ func (this *SessionManager) Read(sid string) map[string]string {
func (this *SessionManager) WriteItem(sid string, key string, value string) bool {
// 删除缓存
defer ttlcache.DefaultCache.Delete( "SESSION@" + sid)
defer ttlcache.DefaultCache.Delete("SESSION@" + sid)
// 忽略OTP
if strings.HasSuffix(sid, "_otp") {
@@ -99,7 +99,7 @@ func (this *SessionManager) WriteItem(sid string, key string, value string) bool
func (this *SessionManager) Delete(sid string) bool {
// 删除缓存
defer ttlcache.DefaultCache.Delete( "SESSION@" + sid)
defer ttlcache.DefaultCache.Delete("SESSION@" + sid)
// 忽略OTP
if strings.HasSuffix(sid, "_otp") {

View File

@@ -237,15 +237,27 @@ func (this *IndexAction) RunPost(params struct {
}
// 写入SESSION
var currentIP = loginutils.RemoteIP(&this.ActionObject)
var localSid = rands.HexString(32)
this.Data["localSid"] = localSid
this.Data["ip"] = loginutils.RemoteIP(&this.ActionObject)
this.Data["ip"] = currentIP
params.Auth.StoreAdmin(adminId, params.Remember, localSid)
// 清理老的SESSION
_, err = this.RPC().LoginSessionRPC().ClearOldLoginSessions(this.AdminContext(), &pb.ClearOldLoginSessionsRequest{
Sid: this.Session().Sid,
Ip: currentIP,
})
if err != nil {
this.ErrorPage(err)
return
}
// 记录日志
err = dao.SharedLogDAO.CreateAdminLog(rpcClient.Context(adminId), oplogs.LevelInfo, this.Request.URL.Path, langs.DefaultMessage(codes.AdminLogin_LogSuccess, params.Username), loginutils.RemoteIP(&this.ActionObject), codes.AdminLogin_LogSuccess, []any{params.Username})
if err != nil {
utils.PrintError(err)
this.ErrorPage(err)
return
}
this.Success()