auth

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAccountRoutes

func AddAccountRoutes(router *gweb.RouterGroup)

func AddRolePermission

func AddRolePermission(c *gweb.Context)

添加角色权限

func CancelDelegation added in v1.0.7

func CancelDelegation(c *gweb.Context)

@summary 取消授权

func DelegateAuth added in v1.0.7

func DelegateAuth(c *gweb.Context)

@summary 授权

func GetDelegatedUserPermissions added in v1.0.7

func GetDelegatedUserPermissions(c *gweb.Context)

获取用户授权信息

func GetPermissions

func GetPermissions(c *gweb.Context)

获取权限定义

func GetRole added in v1.0.5

func GetRole(c *gweb.Context)

func GetRolePermissions

func GetRolePermissions(c *gweb.Context)

获取角色的所有权限

func GetRoleUsers

func GetRoleUsers(c *gweb.Context)

获取角色关联的所有用户

func GetRoles

func GetRoles(c *gweb.Context)

获取系统角色

func GetUserRoles

func GetUserRoles(c *gweb.Context)

获取用户角色

func RemoveRolePermission

func RemoveRolePermission(c *gweb.Context)

删除角色权限

func RemoveUserRole

func RemoveUserRole(c *gweb.Context)

删除用户角色

func SaveRole added in v1.0.5

func SaveRole(c *gweb.Context)

func SaveRoleUsers added in v1.0.3

func SaveRoleUsers(c *gweb.Context)

func SaveUserRoles added in v1.0.3

func SaveUserRoles(c *gweb.Context)

增加用户角色

func SpellName

func SpellName(name string) string

汉语拼音

func UpdatePermission added in v1.0.7

func UpdatePermission(c *gweb.Context)

更新功能权限

Types

type AuthControl

type AuthControl struct {
	*gweb.DB
}

权限控制器

func NewAuthControl

func NewAuthControl(tx *gweb.DB) *AuthControl

func (*AuthControl) GetUserPermissions

func (c *AuthControl) GetUserPermissions(userId uint) []Permission

func (*AuthControl) GetUserRoles

func (c *AuthControl) GetUserRoles(userId uint) []Role

func (*AuthControl) HasAnyPermission

func (c *AuthControl) HasAnyPermission(userId uint, permissions ...string) bool

检查用户是否拥有给定权限之一

func (*AuthControl) HasAnyRole

func (c *AuthControl) HasAnyRole(userId uint, roles ...string) bool

检查用户是否拥有给定角色之一

func (*AuthControl) HasPermission

func (c *AuthControl) HasPermission(userId uint, permissions ...string) bool

检查用户是否拥有给定权限

func (*AuthControl) HasRole

func (c *AuthControl) HasRole(userId uint, roles ...string) bool

检查用户是否拥有给定角色

type Gender

type Gender uint8
const (
	GenderUnknown Gender = iota // 未知
	GenderMale                  // 男
	GenderFemale                // 女
)

type Permission

type Permission struct {
	ID            uint   `json:"id" gorm:"primaryKey"`
	Code          string `json:"code" gorm:"not null;unique;size:50;comment:权限编码"`
	Name          string `json:"name" gorm:"not null;unique;size:50;comment:名称"`
	Module        string `json:"module,omitempty" gorm:"not null;index;comment:模块"`
	AllowDelegate bool   `json:"allow_delegate" gorm:"not null;default:false;comment:是否允许权限下放"`
	Desc          string `json:"desc,omitempty" gorm:"size:100;comment:描述"`
}

功能权限

func (*Permission) TableName

func (t *Permission) TableName() string

type Role

type Role struct {
	ID   uint   `json:"id" gorm:"primaryKey"`
	Name string `json:"name" gorm:"not null;unique;size:50;comment:名称"`
	Code string `json:"code" gorm:"not null;unique;size:50;comment:编码"`

	Permissions []*Permission `json:"permissions,omitempty" gorm:"many2many:sys_role_perm;joinForeignKey:role_id;joinReferences:permission_id"`
	Users       []*User       `json:"users,omitempty" gorm:"many2many:sys_user_role;joinForeignKey:role_id;joinReferences:user_id"`
}

Role 角色

func (*Role) TableName

func (t *Role) TableName() string

type RolePermission

type RolePermission struct {
	RoleID       uint `json:"role_id" gorm:"primaryKey;comment:角色ID"`
	PermissionID uint `json:"permission_id" gorm:"primaryKey;comment:权限ID"`

	Role       *Role       `json:"role,omitempty" gorm:"foreignKey:role_id"`
	Permission *Permission `json:"permission,omitempty" gorm:"foreignKey:permission_id"`
}

func (*RolePermission) TableName

func (t *RolePermission) TableName() string

type User

type User struct {
	gweb.Model
	ID          uint   `json:"id" gorm:"primaryKey"`
	UserName    string `json:"username" gorm:"column:username;not null;unique;size:20"`
	Password    string `json:"-" gorm:"not null;"`
	Name        string `json:"name" gorm:"not null;size:20"`
	SpellName   string `json:"spell_name,omitempty" gorm:"size:50;comment:用于排序"`
	Gender      Gender `json:"gender,omitempty" gorm:"default:0"`
	IsSuperuser bool   `json:"is_superuser,omitempty" gorm:"default:false;not null"`

	Roles []*Role `json:"roles,omitempty" gorm:"many2many:sys_user_role;joinForeignKey:user_id;joinReferences:role_id"`
}

User 用户

func (*User) TableName

func (t *User) TableName() string

type UserPermission added in v1.0.3

type UserPermission struct {
	UserID       uint       `json:"user_id" gorm:"primaryKey;comment:用户ID"`
	PermissionID uint       `json:"permission_id" gorm:"primaryKey;comment:权限ID"`
	AuthorizerID uint       `json:"authorizer_id" gorm:"comment:授权人ID"`
	CreatedAt    time.Time  `json:"created_at,omitempty" gorm:"comment:授权时间"`
	ExpiredAt    *time.Time `json:"expired_at,omitempty" gorm:"comment:授权过期时间"`

	Authorizer *User       `json:"authorizer,omitempty" gorm:"foreignKey:authorizer_id"`
	Permission *Permission `json:"permission,omitempty" gorm:"foreignKey:permission_id"`
	User       *User       `json:"user,omitempty" gorm:"foreignKey:user_id"`
}

用户权限,用于标准的权限管理之外的用户授权管理

func (*UserPermission) TableName added in v1.0.3

func (t *UserPermission) TableName() string

type UserRole

type UserRole struct {
	UserID        uint `json:"user_id" gorm:"primaryKey;comment:用户"`
	RoleID        uint `json:"role_id" gorm:"primaryKey;comment:角色"`
	AllowDelegate bool `json:"allow_delegate" gorm:"default:false;comment:是否允许权限下放"`

	User *User `json:"user,omitempty" gorm:"foreignKey:user_id"`
	Role *Role `json:"role,omitempty" gorm:"foreignKey:role_id"`
}

func (*UserRole) TableName

func (t *UserRole) TableName() string

Jump to

Keyboard shortcuts

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