mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
multi_terminal_login initial commit
This commit is contained in:
parent
d8a5b7e368
commit
4e621ebc69
72
src/common/multi_terminal_login/multi_terminal_login.go
Normal file
72
src/common/multi_terminal_login/multi_terminal_login.go
Normal file
@ -0,0 +1,72 @@
|
||||
package multi_terminal_login
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/push/logic"
|
||||
"Open_IM/src/utils"
|
||||
)
|
||||
|
||||
func MultiTerminalLoginChecker(uid, token string, platformID int32) error {
|
||||
// 1.check userid and platform class 0 not exists and 1 exists
|
||||
existsInterface, err := db.DB.ExistsUserIDAndPlatform(uid, utils.PlatformNameToClass(utils.PlatformIDToName(platformID)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exists := existsInterface.(int64)
|
||||
//get config multi login policy
|
||||
if config.Config.MultiLoginPolicy.OnlyOneTerminalAccess {
|
||||
//OnlyOneTerminalAccess policy need to check all terminal
|
||||
if utils.PlatformNameToClass(utils.PlatformIDToName(platformID)) == "PC" {
|
||||
existsInterface, err = db.DB.ExistsUserIDAndPlatform(uid, "Mobile")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
existsInterface, err = db.DB.ExistsUserIDAndPlatform(uid, "PC")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
exists = existsInterface.(int64)
|
||||
if exists == 1 {
|
||||
err := db.DB.SetUserIDAndPlatform(uid, utils.PlatformNameToClass(utils.PlatformIDToName(platformID)), token, config.Config.TokenPolicy.AccessExpire)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
PushMessageToTheTerminal(uid, platformID)
|
||||
return nil
|
||||
}
|
||||
} else if config.Config.MultiLoginPolicy.MobileAndPCTerminalAccessButOtherTerminalKickEachOther {
|
||||
// common terminal need to kick eich other
|
||||
if exists == 1 {
|
||||
err := db.DB.SetUserIDAndPlatform(uid, utils.PlatformNameToClass(utils.PlatformIDToName(platformID)), token, config.Config.TokenPolicy.AccessExpire)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
PushMessageToTheTerminal(uid, platformID)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
err = db.DB.SetUserIDAndPlatform(uid, utils.PlatformNameToClass(utils.PlatformIDToName(platformID)), token, config.Config.TokenPolicy.AccessExpire)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
PushMessageToTheTerminal(uid, platformID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func PushMessageToTheTerminal(uid string, platform int32) {
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: uid,
|
||||
RecvID: uid,
|
||||
Content: "Your account is already logged on other terminal,please confirm",
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.KickOnlineTip,
|
||||
PlatformID: platform,
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user