mirror of
https://github.com/weloe/token-go.git
synced 2025-10-06 07:56:58 +08:00
feat: refactor kickout, replaced
This commit is contained in:
@@ -48,8 +48,8 @@ type IEnforcer interface {
|
|||||||
GetLoginCounts() (int, error)
|
GetLoginCounts() (int, error)
|
||||||
GetLoginTokenCounts() (int, error)
|
GetLoginTokenCounts() (int, error)
|
||||||
|
|
||||||
Kickout(id string, device string) error
|
Kickout(id string, device ...string) error
|
||||||
Replaced(id string, device string) error
|
Replaced(id string, device ...string) error
|
||||||
|
|
||||||
// Banned banned api
|
// Banned banned api
|
||||||
Banned(id string, service string, level int, time int64) error
|
Banned(id string, service string, level int, time int64) error
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package token_go
|
package token_go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/weloe/token-go/constant"
|
"github.com/weloe/token-go/constant"
|
||||||
"github.com/weloe/token-go/model"
|
"github.com/weloe/token-go/model"
|
||||||
@@ -8,11 +9,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Replaced replace other user
|
// Replaced replace other user
|
||||||
func (e *Enforcer) Replaced(id string, device string) error {
|
func (e *Enforcer) Replaced(id string, device ...string) error {
|
||||||
var err error
|
var err error
|
||||||
if session := e.GetSession(id); session != nil {
|
if session := e.GetSession(id); session != nil {
|
||||||
|
var tokenSignList *list.List
|
||||||
|
if len(device) == 0 {
|
||||||
|
tokenSignList = session.GetTokenSignListCopy()
|
||||||
|
} else {
|
||||||
// get by login device
|
// get by login device
|
||||||
tokenSignList := session.GetFilterTokenSign(device)
|
tokenSignList = session.GetFilterTokenSign(device[0])
|
||||||
|
}
|
||||||
// sign account replaced
|
// sign account replaced
|
||||||
for element := tokenSignList.Front(); element != nil; element = element.Next() {
|
for element := tokenSignList.Front(); element != nil; element = element.Next() {
|
||||||
if tokenSign, ok := element.Value.(*model.TokenSign); ok {
|
if tokenSign, ok := element.Value.(*model.TokenSign); ok {
|
||||||
@@ -42,11 +48,17 @@ func (e *Enforcer) Replaced(id string, device string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Kickout kickout user
|
// Kickout kickout user
|
||||||
func (e *Enforcer) Kickout(id string, device string) error {
|
func (e *Enforcer) Kickout(id string, device ...string) error {
|
||||||
session := e.GetSession(id)
|
session := e.GetSession(id)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
|
var tokenSignList *list.List
|
||||||
|
if len(device) == 0 {
|
||||||
|
tokenSignList = session.GetTokenSignListCopy()
|
||||||
|
} else {
|
||||||
// get by login device
|
// get by login device
|
||||||
tokenSignList := session.GetFilterTokenSign(device)
|
tokenSignList = session.GetFilterTokenSign(device[0])
|
||||||
|
}
|
||||||
|
|
||||||
// sign account kicked
|
// sign account kicked
|
||||||
for element := tokenSignList.Front(); element != nil; element = element.Next() {
|
for element := tokenSignList.Front(); element != nil; element = element.Next() {
|
||||||
if tokenSign, ok := element.Value.(*model.TokenSign); ok {
|
if tokenSign, ok := element.Value.(*model.TokenSign); ok {
|
||||||
|
Reference in New Issue
Block a user