admin

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package admin 管理端的相关操作

Index

Constants

View Source
const (

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

Variables

Functions

func Install

func Install(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(mod string, s *web.Server, db *orm.DB, urlPrefix string, tokenCfg *token.Config, router *web.Router) (*Admin, error)

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) 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 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