admin

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package admin 管理端的相关操作

Index

Constants

View Source
const (

	// SystemID 表示系统的 ID
	SystemID = 0
)

Variables

Functions

func Install

func Install(s *web.Server, mod string, db *orm.DB)

func SexValidator

func SexValidator(v any) bool

func StateValidator

func StateValidator(v any) bool

Types

type Admin

type Admin struct {
	// contains filtered or unexported fields
}

func New

func New(id string, s *web.Server, db *orm.DB, router *web.Router, o *config.User) (*Admin, error)

New 声明 Admin 对象

id 表示模块的 ID,在某些需要唯一值的地方,会加上此值作为前缀; o 表示初始化的一些额外选项,这些值可以直接从配置文件中加载;

func (*Admin) AddSecurityLog

func (m *Admin) AddSecurityLog(uid int64, content, ip, ua string) error

func (*Admin) AddSecurityLogWithContext

func (m *Admin) AddSecurityLogWithContext(uid int64, ctx *web.Context, content string)

func (*Admin) AuthFilter

func (m *Admin) AuthFilter(next web.HandlerFunc) web.HandlerFunc

AuthFilter 验证是否登录

同时如果在登录状态下,会将当前登录用户的数据写入 ctx.Vars。

func (*Admin) IsAllowChangeGroup

func (m *Admin) IsAllowChangeGroup(ctx *web.Context, groups types.SliceOf[int64]) (bool, error)

IsAllowChangeGroup 是否允许当前登录用户将角色 groups 赋予其它用户

除超级用户之外,其它任何人只能应用自己当前角色或是子角色给其它用户。

func (*Admin) LoginUser

func (m *Admin) LoginUser(ctx *web.Context) *ModelAdmin

LoginUser 获取当前登录的用户信息

该信息由 AuthFilter 存储在 ctx.Vars 之中。

func (*Admin) OnLogin added in v0.3.0

func (m *Admin) OnLogin(f func(int64)) (int, error)

func (*Admin) OnLogout added in v0.3.0

func (m *Admin) OnLogout(f func(int64)) (int, error)

func (*Admin) RBACFilter

func (m *Admin) RBACFilter(mod string, res string, next web.HandlerFunc) web.HandlerFunc

RBACFilter 验证是否拥有指定的权限

NOTE: 需要 Admin.AuthFilter 作为前置条件,用到了其产生的 "admin" 变量。

func (*Admin) RegisterResources

func (m *Admin) RegisterResources(mod string, res map[string]web.LocaleStringer) error

RegisterResources 注册资源

func (*Admin) URLPrefix

func (m *Admin) URLPrefix() string

type ModelAdmin added in v0.3.0

type ModelAdmin struct {
	XMLName struct{} `orm:"-" json:"-" xml:"admin"`

	ID       int64     `orm:"name(id);ai" json:"id" xml:"id,attr"`
	Created  time.Time `orm:"name(created)" json:"created" xml:"created,attr"`
	State    State     `orm:"name(state)" json:"state" xml:"state,attr"`
	Sex      Sex       `orm:"name(sex)" json:"sex" xml:"sex,attr"`
	Name     string    `orm:"name(name);len(50)" json:"name,omitempty" xml:"name,omitempty"` // 真实名称
	Nickname string    `orm:"name(nickname);len(50)" json:"nickname" xml:"nickname"`
	Username string    `orm:"name(username);len(50)" json:"username" xml:"username"`
	Avatar   string    `orm:"name(avatar);len(1000)" json:"avatar,omitempty" xml:"avatar,attr,omitempty"`
	Super    bool      `orm:"name(super)" json:"super,omitempty" xml:"super,attr,omitempty"`
}

func (*ModelAdmin) BeforeInsert added in v0.3.0

func (a *ModelAdmin) BeforeInsert() error

func (*ModelAdmin) BeforeUpdate added in v0.3.0

func (a *ModelAdmin) BeforeUpdate() error

BeforeUpdate 更新之前需要执行的操作

func (*ModelAdmin) TableName added in v0.3.0

func (*ModelAdmin) TableName() string

type Sex

type Sex int8
const (
	SexUnknown Sex = iota
	SexMale
	SexFemale
)

func ParseSex

func ParseSex(v string) (Sex, error)

ParseSex 将字符串 v 解析为 State 类型

func (Sex) IsValid

func (s Sex) IsValid() bool

IsValid 验证该状态值是否有效

func (Sex) MarshalText

func (s Sex) MarshalText() ([]byte, error)

MarshalText encoding.TextMarshaler

func (Sex) String

func (s Sex) String() string

String fmt.Stringer

func (*Sex) UnmarshalText

func (s *Sex) UnmarshalText(p []byte) error

UnmarshalText encoding.TextUnmarshaler

type State

type State int8

State 表示管理员的状态

const (
	StateNormal State = iota // 正常
	StateLocked              // 锁定
	StateLeft                // 离职
)

func ParseState

func ParseState(v string) (State, error)

ParseState 将字符串 v 解析为 State 类型

func (State) IsValid

func (s State) IsValid() bool

IsValid 验证该状态值是否有效

func (State) MarshalText

func (s State) MarshalText() ([]byte, error)

MarshalText encoding.TextMarshaler

func (State) String

func (s State) String() string

String fmt.Stringer

func (*State) UnmarshalText

func (s *State) UnmarshalText(p []byte) error

UnmarshalText encoding.TextUnmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL