models

package
v0.0.0-...-f352d09 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExist = errors.New("not exist")
)
View Source
var (
	ErrPasswordNotMatch = errors.New("The password not matched")
)

Functions

func AddPermissionsByList

func AddPermissionsByList(permissions []Permission) error

func Count

func Count(obj interface{}) (int64, error)

func CreateEngine

func CreateEngine(cfg *config.Config) (engine *xorm.Engine, err error)

func CreateUser

func CreateUser(user *User) error

func Delete

func Delete(obj interface{}) error

func DeleteById

func DeleteById(id int64, obj interface{}) error

func EnableCache

func EnableCache() error

打开缓存, 默认只缓存User, Role, Task相关表

func Engine

func Engine() *xorm.Engine

func Find

func Find(limit, start int, objs interface{}) error

func Get

func Get(obj interface{}) error

func GetById

func GetById(id int64, obj interface{}) error

func InitDefaultData

func InitDefaultData() error

func Insert

func Insert(obj interface{}) error

func IsEmailUsed

func IsEmailUsed(email string) bool

邮箱地址是否被使用

func IsExist

func IsExist(obj interface{}) bool

func IsUserNameExist

func IsUserNameExist(username string) bool

检查用户名是否已被注册

func IsValidUserName

func IsValidUserName(name string) error

用户名是否正确

func SyncTables

func SyncTables() error

同步表结构到数据库

func UpdateById

func UpdateById(id int64, obj interface{}, cols ...string) error

Types

type File

type File struct {
	Id     int64  `json:"id"`
	Key    string `json:key xorm:"UNIQUE NOT NULL"`
	Path   string `json:"path"`
	Name   string `json:"name"`
	Ext    string `json:"ext"`
	Size   int    `json:"size"`
	UserId int64  `json:"user_id"`

	CreatedAt time.Time `xorm:"created" json:"created_at"`
	UpdatedAt time.Time `xorm:"updated" json:"updated_at"`

	URL string `xorm:"-" json:"url"`
}

func (*File) CheckValid

func (f *File) CheckValid() error

type Login

type Login struct {
	TokenSecretKey string
	TokenExpiredIn int64
}

func NewLogin

func NewLogin(secret string, sec int64) *Login

func (*Login) GetToken

func (l *Login) GetToken(user *User) (string, error)

type Permission

type Permission struct {
	Id        string    `xorm:"pk" json:"id"`
	Name      string    `json:"name"`
	Group     string    `json:"group"`
	CreatedAt time.Time `xorm:"created" json:"created_at"`
	UpdatedAt time.Time `xorm:"updated" json:"updated_at"`
}

func (*Permission) AddRoles

func (p *Permission) AddRoles(roles []*Role) error

func (*Permission) AddRolesByIds

func (p *Permission) AddRolesByIds(ids []int64) error

func (*Permission) Roles

func (p *Permission) Roles() (roles []*Role, err error)

type PermissionRole

type PermissionRole struct {
	RoleId       int64  `xorm:"pk"`
	PermissionId string `xorm:"pk"`
}

type QueryResult

type QueryResult struct {
	Page        int         `json:"page"`
	PageSize    int         `json:"pagesize"`
	TotalRecord int64       `json:"total_record"`
	Data        interface{} `json:"data"`
}

func NewQueryResult

func NewQueryResult(page int, pagesize int, total int64, data interface{}) *QueryResult

type Role

type Role struct {
	Id          int64
	Name        string `xorm:"UNIQUE NOT NULL"`
	UserId      int64  `json:"user_id"`
	Description string
	CreatedAt   time.Time `xorm:"created" json:"created_at"`
	UpdatedAt   time.Time `xorm:"updated" json:"updated_at"`
}

func (*Role) AddPermissionsByIds

func (r *Role) AddPermissionsByIds(ids ...string) error

func (*Role) AddUser

func (r *Role) AddUser(user *User) error

---- users ----

func (*Role) AddUserByIds

func (r *Role) AddUserByIds(ids ...int64) error

func (*Role) CheckValid

func (r *Role) CheckValid() error

func (*Role) Delete

func (r *Role) Delete() error

删除role及相关数据

func (*Role) DeletePermissions

func (r *Role) DeletePermissions(ids ...string) error

func (*Role) DeleteUserByIds

func (r *Role) DeleteUserByIds(ids ...int64) error

func (*Role) IsGranted

func (r *Role) IsGranted(permission *Permission) bool

func (*Role) IsGrantedById

func (r *Role) IsGrantedById(permissionId string) bool

func (*Role) Permissions

func (r *Role) Permissions() (*[]Permission, error)

---- permissions ----

func (*Role) Users

func (r *Role) Users() (*[]User, error)

type RoleUser

type RoleUser struct {
	RoleId int64 `xorm:"pk"`
	UserId int64 `xorm:"pk"`
}

type User

type User struct {
	Id       int64  `json:"id"`
	Nickname string `json:"nickname"`
	Username string `xorm:"UNIQUE NOT NULL" json:"username"`
	Password string `xorm:"NOT NULL" json:"-"`
	Email    string `xorm:"UNIQUE NOT NULL" json:"email"`

	// Permissions
	IsActive bool `json:"is_active"`
	IsAdmin  bool `json:"is_admin"`

	// 头像
	Avatar string `xorm:"VARCHAR(1024)" json:"avatar"`

	CreatedAt time.Time `xorm:"created" json:"created_at"`
	UpdatedAt time.Time `xorm:"updated" json:"updated_at"`
	DeletedAt time.Time `xorm:"deleted" json:"-"`

	Token     string `xorm:"-" json:"token,omitempty"`
	ExpiredIn int64  `xorm:"-" json:"expired_in,omitempty"`
}

func GetUserByUserName

func GetUserByUserName(username string) *User

----------

func (*User) CheckValid

func (u *User) CheckValid() error

func (*User) EncodePassword

func (u *User) EncodePassword() error

func (*User) IsGranted

func (u *User) IsGranted(permissionId string) bool

检查用户是否有对某个功能有权限

func (*User) IsValidPassword

func (u *User) IsValidPassword(pass string) bool

compare user password

func (*User) Roles

func (u *User) Roles() ([]Role, error)

--- role / permission related

func (*User) UpdatePassword

func (u *User) UpdatePassword(old string, pass string) error

更新用户密码

Jump to

Keyboard shortcuts

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