models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppKeys = map[string]string{}

Functions

This section is empty.

Types

type AUStatus

type AUStatus string
const (
	AUOK      AUStatus = "ok"
	AUDisable AUStatus = "disabled"
	AUApply   AUStatus = "apply"
	AUDeny    AUStatus = "deny"
)

type Action added in v1.0.0

type Action string
const (
	ActGet    Action = "read"
	ActPut    Action = "put"
	ActDelete Action = "delete"
	ActRename Action = "rename"
)

type App

type App struct {
	UUID      string `gorm:"primaryKey;size:32"`
	CreatedAt JSONTime
	UpdatedAt JSONTime
	DeletedAt gorm.DeletedAt `gorm:"index"`
	Name      string
	Icon      string
	Des       string
	Creator   uint
	UserCount uint
	Users     []*User `gorm:"many2many:AppUsers;"`
	// 初始用户角色
	InitRoleID uint
	InitRole   *Role
	// 是否在首页隐藏
	Hide bool
	// PubKey     string
	// PrivateKey string
	// 认证成功跳转链接
	Host string
	// 加解密用户token (key+key2)
	// 两个key都是请求获取时刷新
	// key oa发放给app 双方保存 针对app生成 每个应用有一个
	// key2 app发放给oa app保存 oa使用一次销毁 针对当个用户生成 每个用户有一个
	// 获取app用户加密秘钥key2
	// TODO
	UserRefreshUrl string
	// app 校验用户token时使用
	Key string `json:"-"`
	// 是否允许用户自动加入应用
	EnableRegister bool
	//
	EnableUserKey bool
	UserKeyUrl    string
	// 允许登录方式
	EnableUser  bool
	EnableWx    bool
	EnablePhone bool
	EnableEmail bool

	Wx *Wechat `gorm:"-"`
}

type AppUser

type AppUser struct {
	BaseModel
	AppUUID string `gorm:"size:32"`
	App     *App   `gorm:"association_foreignkey:UUID"`
	UserID  uint
	User    *User
	Status  AUStatus
}

type Auth

type Auth struct {
	BaseModel
	// 该权限作用的应用
	AppUUID string `gorm:"size:32"`
	App     *App   `gorm:"association_foreignkey:UUID"`
	// 权限绑定只能绑定一个
	RoleID *uint
	Role   *Role
	UserID *uint
	User   *User
	// 资源id
	ResourceID uint `gorm:"not null"`
	Resource   *Resource
	// resource_name 用于其他系统方便区分权限的名字
	RID string `gorm:""`
	// 具体某个资源的id
	RUID  string
	Level oalib.AuthLevel
}

Auth 资源权限

type BaseModel

type BaseModel struct {
	ID        uint           `gorm:"primaryKey"`
	CreatedAt JSONTime       ``
	UpdatedAt JSONTime       ``
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type File added in v1.0.0

type File struct {
	CreatedAt time.Time
	OwnerID   string
	Path      string
	Size      uint
	MD5       string
	Count     uint
	Tag       string
	// contains filtered or unexported fields
}

File es model

func (*File) ID added in v1.0.0

func (f *File) ID() string

type History added in v1.0.0

type History struct {
	CreatedAt time.Time
	ActorID   string
	OwnerID   string
	FileID    string
	Action    Action
	Tag       string
	IP        string
}

type JSON

type JSON []byte

func (JSON) Equals

func (j JSON) Equals(j1 JSON) bool

func (JSON) IsNull

func (j JSON) IsNull() bool

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime custom json time

func Now

func Now() *JSONTime

func (JSONTime) MarshalJSON

func (jt JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON 实现它的json序列化方法

func (*JSONTime) Scan

func (jt *JSONTime) Scan(v interface{}) error

Scan value of time.Time

func (*JSONTime) SetTime

func (jt *JSONTime) SetTime(t time.Time)

func (*JSONTime) UnmarshalJSON

func (jt *JSONTime) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON 反序列化方法

func (JSONTime) Value

func (jt JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type Message

type Message struct {
	BaseModel
	UserID   uint
	User     *User
	Title    string
	Redirect string
	Content  string
	From     string
}

type Resource

type Resource struct {
	BaseModel
	AppUUID string ` gorm:"size:32"`
	App     *App   `gorm:"association_foreignkey:UUID"`
	Name    string
	Des     string
}

type Role

type Role struct {
	BaseModel
	AppUUID string `gorm:"size:32"`
	App     *App   `gorm:"association_foreignkey:UUID"`
	Name    string
	// 角色标签
	Tag   string  `gorm:"default:''"`
	Users []*User `gorm:"many2many:UserRoles;"`
	// 具体权限
	Auths     []*Auth `gorm:"foreignkey:RoleID;references:ID"`
	UserCount uint
}

type User

type User struct {
	BaseModel
	Username  string `gorm:"type:varchar(100);unique;not null"`
	Nickname  string `gorm:"type:varchar(100)"`
	Phone     string `gorm:"type:varchar(20);unique;default:null"`
	Email     string `gorm:"type:varchar(50);unique;default:null"`
	CheckCode string `gorm:"type:varchar(64);not null" json:"-"`
	RealCode  string `gorm:"type:varchar(32);not null" json:"-"`
	Position  string
	// disabled 禁用
	Status string

	Icon  string
	Roles []*Role    `gorm:"many2many:UserRoles;"`
	Apps  []*AppUser `gorm:""`
	Auths []*Auth    `gorm:"foreignkey:UserID;references:ID"`
	Used  uint       `gorm:"default:0"`
	Space uint       `gorm:"default:300"`
}

User db user model

func (*User) CheckLogin

func (u *User) CheckLogin(ps string) (bool, error)

func (*User) GetAuth

func (u *User) GetAuth(uuid, ResourceID string, ResourceUUID ...string) oalib.AuthLevel

func (*User) GetAuths

func (u *User) GetAuths() []*Auth

func (*User) GetToken added in v1.0.0

func (u *User) GetToken(uuid string, key []byte) (string, error)

func (*User) LoadAuths

func (u *User) LoadAuths(tx *gorm.DB) error

func (*User) String

func (u *User) String() string

func (*User) UpdatePass

func (u *User) UpdatePass(ps string) (err error)

type UserRole

type UserRole struct {
	BaseModel
	UserID uint
	RoleID uint
}

type Wechat

type Wechat struct {
	BaseModel
	AppUUID string `gorm:"size:32"`
	App     *App   `gorm:"association_foreignkey:UUID"`
	// 网页授权登录用
	WxID    string
	AgentID string
	Url     string

	// 获取access_token用
	CorpID     string
	CorpSecret string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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