Documentation ¶
Overview ¶
从数据库中获取角色权限 并验证角色权限的包
AuthItem 路由和角色控制
Index ¶
- Constants
- Variables
- func AuthItemsHandler(c *assist.Context) (err error)
- func BeginLocalSeedUserName()
- func CreateAuthItemsHandler(c *assist.Context) (err error)
- func CreateSystemConfigsHandler(c *assist.Context) (err error)
- func CreateUserHandler(c *assist.Context) (err error)
- func DelAuthItemsHandler(c *assist.Context) (err error)
- func DelSystemConfigsHandler(c *assist.Context) (err error)
- func DelUsersHandler(c *assist.Context) (err error)
- func EditAuthItemsHandler(c *assist.Context) (err error)
- func EditSystemConfigsHandler(c *assist.Context) (err error)
- func EditUsersHandler(c *assist.Context) (err error)
- func PasswordHash(plain string) string
- func PasswordVerify(secret, plain string) bool
- func RoleAuthItemsChildsHandler(c *assist.Context) (err error)
- func RolesHandler(c *assist.Context) (err error)
- func SystemConfigsHandler(c *assist.Context) (err error)
- func UsersHandler(c *assist.Context) (err error)
- type Adapter
- func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error
- func (a *Adapter) LoadPolicy(model model.Model) (err error)
- func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
- func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error
- func (a *Adapter) SavePolicy(model model.Model) error
- type AuthAssignment
- type AuthAssignments
- type AuthItem
- type AuthItemChild
- type AuthItemChildAdds
- type AuthItemChilds
- type AuthItems
- type Casbin
- func (p *Casbin) AddAuthItemChild(c *assist.Context) (err error)
- func (p *Casbin) AddAuthItemChilds(c *assist.Context) (err error)
- func (p *Casbin) DelAuthItemChild(c *assist.Context) (err error)
- func (p *Casbin) GetCasbinMenus() (casbinMenus Menus, err error)
- func (p *Casbin) GetCasbinMenus2Handler(c *assist.Context) (err error)
- func (p *Casbin) GetCasbinMenusHandler(c *assist.Context) (err error)
- func (p *Casbin) ServeHTTP() echo.MiddlewareFunc
- type CfgValue
- type CreateAuthItem
- type DelAuthItem
- type DelSystemConfig
- type EditSelected
- type Menu
- type MenuSlice
- type Menus
- type QueryUser
- type ReqSvcAuthItemChilds
- type ReqSvcAuthItems
- type ReqSvcSystemConfigs
- type ReqSvcUsers
- type ResSvcAuthItemChilds
- type ResSvcAuthItems
- type ResSvcUsers
- type Role
- type RoleAuthItem
- type Roles
- type RouterSelected
- type Selected
- type Sort
- type SvcAuthItemChilds
- type SvcAuthItems
- type SvcEditAuthItems
- type SvcEditUser
- type SvcUsers
- type SystemConfig
- type SystemConfigSelected
- type SystemConfigs
- type User
- func (p *User) BindWx(wxBindReq *WxBindReq, appID string, secretKey string, ...) (err error)
- func (p *User) Create(user *UserCreate, ip string) (err error)
- func (p *User) CreateUserName()
- func (p *User) Del(id int) (err error)
- func (p *User) Edit(svc *SvcEditUser) (err error)
- func (p *User) GetCookie(mysession session.Session) bool
- func (s *User) GetSession() echo.MiddlewareFunc
- func (p *User) Login(user *UserLogin, mysession session.Session) (err error)
- func (p *User) LoginWx(wxLoginReq *WxLoginReq, appID string, secretKey string, ...) (err error)
- func (p *User) Logout(mysession session.Session) (err error)
- func (p *User) QueryByField(fieldName string, fieldValue interface{}) (err error)
- func (p *User) QueryByOpenID() (err error)
- func (p *User) QueryByUsername() (err error)
- func (p *User) Register(user *UserRegister, ip string) (err error)
- type UserCreate
- type UserLogin
- type UserRegister
- type UserSelected
- type UserSystemConfig
- type Users
- type WeApp
- type WxBindReq
- type WxLoginReq
Constants ¶
const SELECT_System_Config_SQL string = `` /* 626-byte string literal not displayed */
const SaltSize = 16
Variables ¶
var (
LOCAL_SEED_USER_NAME = make(chan string) // 随机用户名种子
)
Functions ¶
func CreateAuthItemsHandler ¶
通过网络创建一个全新的路由
func DelAuthItemsHandler ¶
DelAuthItemsHandler 删除一个路由
func DelSystemConfigsHandler ¶
DelSystemConfigsHandler 删除一个菜单 这里会找3级菜单, 然后全部删除掉
func EditAuthItemsHandler ¶
EditAuthItemsHandler 编辑一个路由
func EditUsersHandler ¶
修改一个用户 EditUsersHandler 编辑一个路由
func PasswordHash ¶
func PasswordVerify ¶
func RoleAuthItemsChildsHandler ¶
RoleAuthItemsChildsHandler 获取角色对应的全部角色关系和功能权限信息
func RolesHandler ¶
func SystemConfigsHandler ¶
Types ¶
type Adapter ¶
func NewAdapterDB ¶
func (*Adapter) LoadPolicy ¶
LoadPolicy 重新实现载入 角色和路由对照关系的内容
func (*Adapter) RemoveFilteredPolicy ¶
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
RemoveFilteredPolicy removes policy rules that match the filter from the storage.
func (*Adapter) RemovePolicy ¶
RemovePolicy removes a policy rule from the storage.
type AuthAssignment ¶
路由权限管理
func (*AuthAssignment) Add ¶
func (p *AuthAssignment) Add(itemName string, userID string) (err error)
Add 为user添加一个角色
func (*AuthAssignment) AddDefault ¶
func (p *AuthAssignment) AddDefault(userID string) (err error)
AddDefault 创建一个默认的角色
type AuthAssignments ¶
type AuthAssignments struct {
AuthAssignments []AuthAssignment // 全部权限
}
路由权限列表管理
func (*AuthAssignments) BatchAdd ¶
func (p *AuthAssignments) BatchAdd(s *gorm.DB) (err error)
BatchAdd 批量添加角色 事务一致性的函数 配合其他库使用
func (*AuthAssignments) GetUserAll ¶
func (p *AuthAssignments) GetUserAll(userID int)
GetUserAll 获取user的全部角色
type AuthItem ¶
type AuthItem struct { Name string `gorm:"size:64"` Type int Description string `gorm:"size:256"` RouterName string `gorm:"size:256"` // 路由名称 RouterType int // 服务还是页面 页面是1 服务是2 ModelName string // 模块名称 BusName string // 业务名称 CreatedAt int64 UpdatedAt int64 }
func (*AuthItem) Create ¶
func (p *AuthItem) Create(createAuthItem *CreateAuthItem) (err error)
Create 创建一个路由
func (*AuthItem) Edit ¶
func (p *AuthItem) Edit(svc *SvcEditAuthItems) (err error)
type AuthItemChild ¶
func (*AuthItemChild) Add ¶
func (p *AuthItemChild) Add(parent string, child string) (err error)
Add 为某个角色增加一个路由
func (*AuthItemChild) Del ¶
func (p *AuthItemChild) Del(parent string, child string)
Del 为某个角色删除一个路由
type AuthItemChildAdds ¶
type AuthItemChildAdds []AuthItemChild
type AuthItemChilds ¶
type AuthItemChilds struct { AuthItemChilds []AuthItemChild RoleAuths []AuthItemChild // 角色与角色关系权限组 RouterAuths []AuthItemChild // 角色和功能权限关系组 }
func (*AuthItemChilds) GetAll ¶
func (p *AuthItemChilds) GetAll()
func (*AuthItemChilds) GetRoleAuths ¶
func (p *AuthItemChilds) GetRoleAuths(roleName string)
type Casbin ¶
type Casbin struct {
// contains filtered or unexported fields
}
Casbin 自定义权限管理模块
func (*Casbin) AddAuthItemChild ¶
UpdateAuthItemChild 新增一个路由和角色对照关系
func (*Casbin) AddAuthItemChilds ¶
一次性添加多个权限
func (*Casbin) DelAuthItemChild ¶
DelAuthItemChild 删除一个路由和角色对照关系
func (*Casbin) GetCasbinMenus ¶
func (*Casbin) GetCasbinMenus2Handler ¶
GetCasbinMenusHandler 获得有权限控制的菜单
func (*Casbin) GetCasbinMenusHandler ¶
type CreateAuthItem ¶
type DelAuthItem ¶
type DelSystemConfig ¶
type DelSystemConfig struct {
ID int
}
type EditSelected ¶
type Menu ¶
type Menu struct { Url string `json:"Url"` Comment string `json:"Comment"` Icon string `json:"Icon"` //Type string `json:"Type"` //Spec string `json:"Spec"` Order int `json:"Order"` Name string `json:"Name"` ParentID int Component string `json:"Component"` SubMenu MenuSlice `json:"Menu"` }
func (*Menu) GetCfgValue ¶
type ReqSvcAuthItemChilds ¶
type ReqSvcAuthItemChilds struct {
Selected RouterSelected `json:"Selected"`
}
ReqSvcRouters 全路由列表查询业务请求节点
type ReqSvcAuthItems ¶
type ReqSvcAuthItems struct { Selected Selected `json:"Selected"` Sort Sort `json:"Sort"` Pagination business.PaginationIn `json:"Pagination"` }
全路由列表查询业务请求节点
type ReqSvcSystemConfigs ¶
type ReqSvcSystemConfigs struct {
Selected SystemConfigSelected `json:"Selected"`
}
全路由列表查询业务请求节点
type ReqSvcUsers ¶
type ReqSvcUsers struct { Selected UserSelected `json:"Selected"` Sort Sort `json:"Sort"` Pagination business.PaginationIn `json:"Pagination"` }
全路由列表查询业务请求节点
type ResSvcAuthItemChilds ¶
type ResSvcAuthItemChilds struct { RoleName string `json:"RoleName"` InRoleRoleAuths []RoleAuthItem `json:"InRoleRoleAuths"` // 角色对应的角色与角色关系权限组 InRoleRouterAuths []RoleAuthItem `json:"InRoleRouterAuths"` // 角色对应的角色和功能权限关系组 OutRoleRoleAuths []RoleAuthItem `json:"OutRoleRoleAuths"` // 角色没有的角色与角色关系权限组 OutRoleRouterAuths []RoleAuthItem `json:"OutRoleRouterAuths"` // 角色没有的角色和功能权限关系组 }
ResSvcAuthItemChilds 权限管理列表查询返回结构 不做分页处理, 返回的是全部项目
func (*ResSvcAuthItemChilds) GetRoleAuthItemsChilds ¶
func (p *ResSvcAuthItemChilds) GetRoleAuthItemsChilds(roleName string) (err error)
GetRoleAuthItemsChilds 获取角色有的 角色没有的 角色对照权限列表查询
type ResSvcAuthItems ¶
type ResSvcAuthItems struct { //PageSize int // 一页多少条 // //PrevOffsetCount int // 上一页是第几页 //OffsetCount int // 当前是第几页 //NextOffsetCount int // 下一页是第几页 AuthItems AuthItems Pagination business.PaginationOut `json:"Pagination"` }
ResSvcAuthItems 全路由列表查询业务返回节点
type ResSvcUsers ¶
type ResSvcUsers struct { Users Users Pagination business.PaginationOut `json:"Pagination"` }
func (*ResSvcUsers) GetUsers ¶
func (p *ResSvcUsers) GetUsers(reqSvc *ReqSvcUsers) (err error)
type RoleAuthItem ¶
type SvcAuthItemChilds ¶
type SvcAuthItemChilds struct { ResSvc ResSvcAuthItemChilds // 列表 查询返回结果 ReqSvc ReqSvcAuthItemChilds // 列表查询请求 }
对外使用的权限查询列表结构组
type SvcAuthItems ¶
type SvcAuthItems struct { ReqSvcCreate CreateAuthItem // 创建请求 ResSvc ResSvcAuthItems // 列表分页查询返回结果 ReqSvc ReqSvcAuthItems // 列表分页查询请求 }
func (*SvcAuthItems) GetAuthItemsByType ¶
func (p *SvcAuthItems) GetAuthItemsByType(reqSvc *ReqSvcAuthItems) (resSvc ResSvcAuthItems)
type SvcEditAuthItems ¶
type SvcEditAuthItems struct { EditSelected EditSelected `json:"Selected"` CreateAuthItem CreateAuthItem `json:"AuthItem"` }
type SvcEditUser ¶
type SvcEditUser struct { UserID int `json:"UserID"` UserCreate UserCreate `json:"User"` }
type SvcUsers ¶
type SvcUsers struct { ReqSvc ReqSvcUsers // 列表分页查询请求 ResSvc ResSvcUsers // 列表分页查询返回结果 }
type SystemConfig ¶
type SystemConfig struct { ID int CfgName string // 配置名称 CfgValue string // 配置值 CfgOrder int // 排序 CfgPid int // 父ID Ctime time.Time // 创建时间 CfgType string // 'SYSTEM:系统配置,USER:用户配置,ROUTE:路由,PLUGIN:插件' CfgStatus int // 1显示 0 不显示 CfgComment string // 配置说明 }
func (*SystemConfig) Create ¶
func (p *SystemConfig) Create() (err error)
func (*SystemConfig) Del ¶
func (p *SystemConfig) Del(id int) (err error)
func (*SystemConfig) Edit ¶
func (p *SystemConfig) Edit() (err error)
type SystemConfigSelected ¶
type SystemConfigs ¶
type SystemConfigs struct {
SystemConfigs []SystemConfig
}
func (*SystemConfigs) GetSystemConfigs ¶
func (p *SystemConfigs) GetSystemConfigs(cfgName string, cfgType string) (err error)
获取条件查询的用户总数
type User ¶
type User struct { ID int `gorm:"column:id" ` RoleID int Status int // 初始状态 CreatedAt time.Time Phone string CreatedIP string StaffID int `gorm:"-"` // 员工编码 CompanyID int // 公司编码 saas系统使用 StaffName string `gorm:"-"` Username string Password string Email string Nickname string OpenID string AuthAssignments AuthAssignments // 用户对应的角色列表 HeadImgID int HeadImage file.Image `gorm:"-"` }
User 保存用户信息的类,存储用户全部的身份信息
var SessionUser *User
func (*User) BindWx ¶
func (p *User) BindWx(wxBindReq *WxBindReq, appID string, secretKey string, mysession session.Session) (err error)
LoginWx 微信绑定
func (*User) Create ¶
func (p *User) Create(user *UserCreate, ip string) (err error)
Create 管理员创建用户 必须创建时就指定对应的角色 用户名 昵称 邮箱 电话号码 角色列表都是必填项目 输入参数UserCreate
func (*User) CreateUserName ¶
func (p *User) CreateUserName()
func (*User) GetSession ¶
func (s *User) GetSession() echo.MiddlewareFunc
GetSession 通过cookie中保存的key获取session中的数据 和官方文档的不同,这种写法是在调用具体函数前进行cookie解析 如果在路由验证后调用的话就太迟了
func (*User) LoginWx ¶
func (p *User) LoginWx(wxLoginReq *WxLoginReq, appID string, secretKey string, mysession session.Session) (err error)
微信登录 已有的用户
func (*User) QueryByField ¶
QueryByField 根据字段名称和值获取user表和员工表的具体信息
func (*User) QueryByOpenID ¶
QueryByOpenID 使用微信的openID查询user信息的方法
type UserCreate ¶
type UserRegister ¶
type UserSelected ¶
type UserSystemConfig ¶
type Users ¶
type Users []QueryUser
Email string `json:"Email" gorm:"size:64"` Username string `json:"Username" gorm:"size:128"` Phone string `json:"Username" gorm:"size:128"` Nickname string `json:"Username" gorm:"size:128"` Created_at string `json:"Created_at" gorm:"size:128"` Updated_at string `json:"Username" gorm:"size:128"` Password string `json:"Password" gorm:"size:128"` 用户的列表查询
type WeApp ¶
type WeApp struct { AppID string Secret string JsCode string CodeToSessURL string SessionKey string OpenID string HeaderHost string // 调用的域名 Timeout time.Duration }