[feat] 将 user 报了出去
This commit is contained in:
parent
efb2586c5e
commit
d5c3c4704a
24
base/user.go
24
base/user.go
@ -8,7 +8,7 @@ import (
|
|||||||
"git.fsdpf.net/go/contracts"
|
"git.fsdpf.net/go/contracts"
|
||||||
)
|
)
|
||||||
|
|
||||||
type user struct {
|
type User struct {
|
||||||
id int
|
id int
|
||||||
uuid string
|
uuid string
|
||||||
username string
|
username string
|
||||||
@ -17,39 +17,39 @@ type user struct {
|
|||||||
roles []string
|
roles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) ID() int {
|
func (this User) ID() int {
|
||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) Uuid() string {
|
func (this User) Uuid() string {
|
||||||
return this.uuid
|
return this.uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) Username() string {
|
func (this User) Username() string {
|
||||||
return this.username
|
return this.username
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) Nickname() string {
|
func (this User) Nickname() string {
|
||||||
return this.nickname
|
return this.nickname
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) GetUserInfo() any {
|
func (this User) GetUserInfo() any {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) Roles() (roles []string) {
|
func (this User) Roles() (roles []string) {
|
||||||
return this.roles
|
return this.roles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) HasUserRoles(roles ...string) bool {
|
func (this User) HasUserRoles(roles ...string) bool {
|
||||||
return lo.Contains(this.Roles(), "ffffffff-ffff-ffff-ffff-ffffffffffff") || len(lo.Intersect(this.Roles(), roles)) > 0
|
return lo.Contains(this.Roles(), "ffffffff-ffff-ffff-ffff-ffffffffffff") || len(lo.Intersect(this.Roles(), roles)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) IsAnonymous() bool {
|
func (this User) IsAnonymous() bool {
|
||||||
return reflect.DeepEqual(this.Roles(), []string{"00000000-0000-0000-0000-000000000000"})
|
return reflect.DeepEqual(this.Roles(), []string{"00000000-0000-0000-0000-000000000000"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this user) Platform() string {
|
func (this User) Platform() string {
|
||||||
if this.platform == "" {
|
if this.platform == "" {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func (this user) Platform() string {
|
|||||||
|
|
||||||
// 获取匿名用户
|
// 获取匿名用户
|
||||||
func GetAnonymous() contracts.User {
|
func GetAnonymous() contracts.User {
|
||||||
return user{
|
return User{
|
||||||
id: 0,
|
id: 0,
|
||||||
uuid: "00000000-0000-0000-0000-000000000000",
|
uuid: "00000000-0000-0000-0000-000000000000",
|
||||||
username: "anonymous",
|
username: "anonymous",
|
||||||
@ -70,7 +70,7 @@ func GetAnonymous() contracts.User {
|
|||||||
|
|
||||||
// 系统用户
|
// 系统用户
|
||||||
func GetSystemUser() contracts.User {
|
func GetSystemUser() contracts.User {
|
||||||
return user{
|
return User{
|
||||||
id: -1,
|
id: -1,
|
||||||
uuid: "ffffffff-ffff-ffff-ffff-ffffffffffff",
|
uuid: "ffffffff-ffff-ffff-ffff-ffffffffffff",
|
||||||
username: "system",
|
username: "system",
|
||||||
|
Loading…
Reference in New Issue
Block a user