user

package
v0.0.0-...-f683405 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitUserModel

func InitUserModel(database *gorm.DB, config interface{})

InitUserModel initialize the user model with given config

Types

type Group

type Group struct {
	Model
	Name     string   `json:"name" form:"name" validate:"empty=false & format=strict_html"`
	CodeName string   `json:"code_name" json:"code_name" validate:"empty=false & format=slug" gorm:"type:varchar(100);unique_index"`
	Parent   uint     `json:"parent" form:"parent"`
	Roles    []*Role  `json:"roles_data" gorm:"many2many:group_roles;" validate:"-"`
	RoleSet  []string `json:"roles" form:"roles" gorm:"-"`
}

Group group struct

func (*Group) AfterFind

func (g *Group) AfterFind() (err error)

AfterFind after find event

func (*Group) HasPerm

func (g *Group) HasPerm(v string) bool

HasPerm check the group if has permission

func (*Group) Save

func (g *Group) Save() error

Save save the group instance

func (Group) TableName

func (Group) TableName() string

TableName return group model table name

type Model

type Model struct {
	ID        uint       `json:"id" gorm:"primary_key"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" sql:"index"`
}

Model common model stuff

type Permission

type Permission struct {
	Model
	CodeName    string `json:"code_name" form:"code_name" validate:"empty=false"`
	Title       string `json:"title" form:"title" validate:"empty=false"`
	Description string `json:"description" form:"description"`
	App         string `json:"app" form:"app" validate:"empty=false"`
}

Permission permission struct

type Permissions

type Permissions []Permission

Permissions slice of permissions

func (Permissions) Sync

func (perms Permissions) Sync(app string)

Sync synchronize permissions on startup

type Role

type Role struct {
	Model
	Name          string       `json:"name" form:"name" validate:"empty=false & format=strict_html"`
	CodeName      string       `json:"code_name" json:"code_name" validate:"empty=false & format=slug" gorm:"type:varchar(100);unique_index"`
	Parent        uint         `json:"parent" form:"parent"`
	Groups        []*Group     `json:"-" gorm:"many2many:group_roles;"`
	Permission    *Permissions `json:"permissions_data" gorm:"-"  validate:"-"`
	PermissionSet []string     `json:"permissions" form:"permissions" gorm:"-"`
}

Role role struct

func (*Role) AfterFind

func (r *Role) AfterFind() (err error)

AfterFind after find event

func (*Role) HasPerm

func (r *Role) HasPerm(v string) bool

HasPerm check if role has permission

func (*Role) Save

func (r *Role) Save() error

Save save role instance

func (*Role) SetPermission

func (r *Role) SetPermission(permissions Permissions) error

SetPermission set role permission

func (Role) TableName

func (Role) TableName() string

TableName return role model table name

type RolePermission

type RolePermission struct {
	Model
	RoleID       uint
	PermissionID uint
}

RolePermission role to permission orm

type User

type User struct {
	Model
	Name      string    `json:"name" form:"name"`
	Username  string    `json:"username" form:"username"  validate:"empty=false | format=username" gorm:"type:varchar(32);unique_index"`
	Password  string    `json:"-" form:"-" validate:"empty=false & format=strict_html"`
	Email     string    `json:"email" form:"email" validate:"empty=false & format=email" gorm:"type:varchar(32);unique_index"`
	Roles     []*Role   `json:"roles" form:"roles"  validate:"-"`
	Group     *Group    `json:"-" form:"-" gorm:"-"  validate:"-"`
	GroupID   uint      `json:"group_id" form:"group_id"`
	Anonymous bool      `json:"anonymous" form:"anonymous" gorm:"-"`
	Active    bool      `json:"active" form:"active"`
	Seen      time.Time `json:"seen" form:"seen"`
	Admin     bool      `json:"admin" form:"admin"`
	Params    data.Map  `gorm:"type:json" form:"params" json:"params"`
}

User user struct

func (*User) AfterFind

func (u *User) AfterFind() (err error)

AfterFind after find event

func (*User) HasPerm

func (u *User) HasPerm(v string) bool

HasPerm check if user has permission

func (*User) HasRole

func (u *User) HasRole(v interface{}) bool

HasRole check if user has role

func (User) Image

func (u User) Image() string

Image return user image

func (*User) Save

func (u *User) Save() error

Save save user instance

func (*User) SetGroup

func (u *User) SetGroup(group interface{}) error

SetGroup set user group

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword set user password

Jump to

Keyboard shortcuts

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