Documentation
¶
Index ¶
- func AddAccountRoutes(router *gweb.RouterGroup)
- func AddRolePermission(c *gweb.Context)
- func CancelDelegation(c *gweb.Context)
- func DelegateAuth(c *gweb.Context)
- func GetDelegatedUserPermissions(c *gweb.Context)
- func GetPermissions(c *gweb.Context)
- func GetRole(c *gweb.Context)
- func GetRolePermissions(c *gweb.Context)
- func GetRoleUsers(c *gweb.Context)
- func GetRoles(c *gweb.Context)
- func GetUserRoles(c *gweb.Context)
- func RemoveRolePermission(c *gweb.Context)
- func RemoveUserRole(c *gweb.Context)
- func SaveRole(c *gweb.Context)
- func SaveRoleUsers(c *gweb.Context)
- func SaveUserRoles(c *gweb.Context)
- func SpellName(name string) string
- func UpdatePermission(c *gweb.Context)
- type AuthControl
- func (c *AuthControl) GetUserPermissions(userId uint) []Permission
- func (c *AuthControl) GetUserRoles(userId uint) []Role
- func (c *AuthControl) HasAnyPermission(userId uint, permissions ...string) bool
- func (c *AuthControl) HasAnyRole(userId uint, roles ...string) bool
- func (c *AuthControl) HasPermission(userId uint, permissions ...string) bool
- func (c *AuthControl) HasRole(userId uint, roles ...string) bool
- type Gender
- type Permission
- type Role
- type RolePermission
- type User
- type UserPermission
- type UserRole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAccountRoutes ¶
func AddAccountRoutes(router *gweb.RouterGroup)
func GetDelegatedUserPermissions ¶ added in v1.0.7
获取用户授权信息
func SaveRoleUsers ¶ added in v1.0.3
Types ¶
type AuthControl ¶
权限控制器
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
检查用户是否拥有给定权限
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 角色
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 用户
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"`
}
Click to show internal directories.
Click to hide internal directories.