auth

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2016 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DefaultResourceType default resource-type
	DefaultResourceType = "-"
	//DefaultResourceID default resource-id
	DefaultResourceID = 0

	//RoleAdmin admin
	RoleAdmin = "admin"
	//RoleRoot root
	RoleRoot = "root"
)
View Source
const CurrentUser = "current-user"

CurrentUser current user key

View Source
const (
	//ProvideTypeEmail email provuder-type
	ProvideTypeEmail = "email"
)

Variables

This section is empty.

Functions

func CreateCertificate added in v0.2.0

func CreateCertificate(ca bool, subject pkix.Name, years int) ([]byte, []byte, error)

CreateCertificate create certs

func WritePemFile added in v0.2.0

func WritePemFile(file, _type string, buf []byte) error

WritePemFile wirte to a pem format file

Types

type Dao added in v0.2.0

type Dao struct {
	Db    *gorm.DB   `inject:""`
	Cache *web.Cache `inject:""`
	Aes   *web.Aes   `inject:""`
	Hmac  *web.Hmac  `inject:""`
	I18n  *web.I18n  `inject:""`
}

Dao dao

func (*Dao) AddEmailUser added in v0.2.0

func (p *Dao) AddEmailUser(lang, email, name, password string) (*User, error)

AddEmailUser add email user

func (*Dao) AddOpenIDUser added in v0.2.0

func (p *Dao) AddOpenIDUser(pid, pty, email, name, home, logo string) (*User, error)

AddOpenIDUser add openid user

func (*Dao) Allow added in v0.2.0

func (p *Dao) Allow(role uint, user uint, years, months, days int) error

Allow allow permission

func (*Dao) Authority added in v0.2.0

func (p *Dao) Authority(user uint, rty string, rid uint) []string

Authority get user's role names

func (*Dao) Can added in v0.2.0

func (p *Dao) Can(user uint, name string, rty string, rid uint) bool

Can can?

func (*Dao) Deny added in v0.2.0

func (p *Dao) Deny(role uint, user uint) error

Deny deny permission

func (*Dao) Get added in v0.2.0

func (p *Dao) Get(key string, val interface{}) error

Get get val

func (*Dao) GetUserByEmail added in v0.2.0

func (p *Dao) GetUserByEmail(email string) (*User, error)

GetUserByEmail get user by email

func (*Dao) GetUserByUID added in v0.2.0

func (p *Dao) GetUserByUID(uid string) (*User, error)

GetUserByUID get user by uid

func (*Dao) Is added in v0.2.0

func (p *Dao) Is(user uint, name string) bool

Is is role ?

func (*Dao) Log added in v0.2.0

func (p *Dao) Log(user uint, msg string)

Log add log

func (*Dao) Logf added in v0.2.0

func (p *Dao) Logf(user uint, lang, format string, args ...interface{})

Logf add log

func (*Dao) Role added in v0.2.0

func (p *Dao) Role(name string, rty string, rid uint) (*Role, error)

Role check role exist

func (*Dao) Set added in v0.2.0

func (p *Dao) Set(key string, val interface{}, flag bool) error

Set set key-val

func (*Dao) UserClaims added in v0.2.0

func (p *Dao) UserClaims(u *User) jws.Claims

UserClaims generate user claims

type Engine added in v0.2.0

type Engine struct {
	I18n   *web.I18n         `inject:""`
	Cache  *web.Cache        `inject:""`
	Hmac   *web.Hmac         `inject:""`
	Server *machinery.Server `inject:""`
	Dao    *Dao              `inject:""`
	Db     *gorm.DB          `inject:""`
	Jwt    *Jwt              `inject:""`
}

Engine auth engine

func (*Engine) Home added in v0.2.0

func (p *Engine) Home() gin.HandlerFunc

Home home

func (*Engine) Init added in v0.2.0

func (p *Engine) Init(inj *inject.Graph) error

Init init ioc objects

func (*Engine) Mount added in v0.2.0

func (p *Engine) Mount(rt *gin.Engine)

Mount web points

func (*Engine) Shell added in v0.2.0

func (p *Engine) Shell() []cli.Command

Shell command line

func (*Engine) Worker added in v0.2.0

func (p *Engine) Worker()

Worker register worker

type Jwt added in v0.2.0

type Jwt struct {
	Key    []byte               `inject:"jwt.key"`
	Method crypto.SigningMethod `inject:"jwt.method"`
	Dao    *Dao                 `inject:""`
}

Jwt jwt helper

func (*Jwt) CurrentUserHandler added in v0.2.0

func (p *Jwt) CurrentUserHandler(must bool) gin.HandlerFunc

CurrentUserHandler inject current user

func (*Jwt) MustAdminHandler added in v0.2.0

func (p *Jwt) MustAdminHandler() gin.HandlerFunc

MustAdminHandler check must have admin role

func (*Jwt) MustRolesHandler added in v0.2.0

func (p *Jwt) MustRolesHandler(roles ...string) gin.HandlerFunc

MustRolesHandler check must have one roles at least

func (*Jwt) Sum added in v0.2.0

func (p *Jwt) Sum(cm jws.Claims, days int) ([]byte, error)

Sum create jwt token

func (*Jwt) Validate added in v0.2.0

func (p *Jwt) Validate(buf []byte) (jwt.Claims, error)

Validate check jwt

type Leaveword added in v0.2.0

type Leaveword struct {
	ID        uint      `json:"id"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
}

Leaveword leave word

type Log

type Log struct {
	ID        uint      `json:"id"`
	Message   string    `json:"message"`
	CreatedAt time.Time `json:"created_at"`

	UserID uint `json:"user_id"`
	User   User `json:"user"`
}

Log model

func (*Log) TableName

func (p *Log) TableName() string

TableName table name

type Notice added in v0.2.0

type Notice struct {
	web.Model
	Lang    string `json:"lang"`
	Content string `json:"content"`
}

Notice notice

type Permission

type Permission struct {
	web.Model

	StartUp  time.Time `json:"start_up"`
	ShutDown time.Time `json:"shut_down"`

	UserID uint `json:"user_id"`
	User   User `json:"user"`
	RoleID uint `json:"role_id"`
	Role   Role `json:"role"`
}

Permission permission model

func (*Permission) Begin

func (p *Permission) Begin() string

Begin begin to string

func (*Permission) Enable

func (p *Permission) Enable() bool

Enable is enable?

func (*Permission) End

func (p *Permission) End() string

End end to string

func (*Permission) TableName

func (p *Permission) TableName() string

TableName table name

type Role

type Role struct {
	web.Model

	Name         string `json:"name"`
	ResourceType string `json:"resource_type"`
	ResourceID   uint   `json:"resource_id"`

	Permissions []Permission `json:"permissions"`
}

Role role model

func (Role) String

func (p Role) String() string

func (*Role) TableName

func (p *Role) TableName() string

TableName table name

type SMTP added in v0.2.0

type SMTP struct {
	From     string `json:"form"`
	Username string `json:"username"`
	Password string `json:"-"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
}

SMTP smtp config

type Setting added in v0.2.0

type Setting struct {
	web.Model

	Key  string
	Val  []byte
	Flag bool
}

Setting setting

type User

type User struct {
	web.Model

	Email    string `json:"email"`
	UID      string `json:"uid"`
	Home     string `json:"home"`
	Name     string `json:"name"`
	Password []byte `json:"-"`

	ProviderType string `json:"provider_type"`
	ProviderID   string `json:"provider_id"`

	LastSignInAt    *time.Time `json:"last_sign_in_at"`
	LastSignInIP    string     `json:"last_sign_in_ip"`
	CurrentSignInAt *time.Time `json:"current_sign_in_at"`
	CurrentSignInIP string     `json:"current_sign_in_ip"`
	SignInCount     uint       `json:"sign_in_count"`
	ConfirmedAt     *time.Time `json:"confirmed_at"`
	LockedAt        *time.Time `json:"locked_at"`

	Logs        []Log        `json:"logs"`
	Permissions []Permission `json:"permissions"`
}

User user model

func (*User) IsAvailable

func (p *User) IsAvailable() bool

IsAvailable is valid?

func (*User) IsConfirmed

func (p *User) IsConfirmed() bool

IsConfirmed confirmed?

func (*User) IsLocked

func (p *User) IsLocked() bool

IsLocked locked?

func (p *User) SetGravatarLogo()

SetGravatarLogo set logo by gravatar

func (*User) SetUID

func (p *User) SetUID()

SetUID generate uid

func (User) String

func (p User) String() string

func (*User) TableName

func (p *User) TableName() string

TableName table name

Jump to

Keyboard shortcuts

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