oauth

package
v0.0.0-...-52f8398 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2016 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ADMIN = "admin"

ADMIN admin role name

Variables

This section is empty.

Functions

func AdminHandler

func AdminHandler(u *User, dao *Dao, r render.Render)

AdminHandler admin handler

func CurrentUserHandler

func CurrentUserHandler(req *http.Request, db *gorm.DB, c martini.Context, j *token.Jwt, r render.Render)

CurrentUserHandler current user handler

func GoogleHandler

func GoogleHandler(c martini.Context, sp settings.Provider, r render.Render)

GoogleHandler google credentials handler

Types

type Dao

type Dao struct {
	Db *gorm.DB
}

Dao database operations

func (*Dao) Allow

func (p *Dao) Allow(role uint, user uint, dur time.Duration) error

Allow set allow permission

func (*Dao) Can

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

Can can?

func (*Dao) Deny

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

Deny set deny permission

func (*Dao) GetUser

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

GetUser get user by uid

func (*Dao) Is

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

Is is?

func (*Dao) Role

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

Role insure role name exists

type Engine

type Engine struct {
}

Engine oauth engine

func (*Engine) Map

func (p *Engine) Map(inj inject.Injector) martini.Handler

Map map objects

func (*Engine) Migrate

func (p *Engine) Migrate() martini.Handler

Migrate call by db:migrate

func (*Engine) Mount

func (p *Engine) Mount(rt martini.Router)

Mount mount to web

func (*Engine) Seed

func (p *Engine) Seed() martini.Handler

Seed call by db:seed

func (*Engine) Shell

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

Shell shell commands

func (*Engine) Worker

func (p *Engine) Worker() martini.Handler

Worker call by worker

type Google

type Google struct {
	Web struct {
		ClientID     string   `json:"client_id"`
		ClientSecret string   `json:"client_secret"`
		RedirectURLS []string `json:"redirect_uris"`
	} `json:"web"`
}

Google google credentials model

func ReadGoogle

func ReadGoogle(f string) (*Google, error)

ReadGoogle read google credentials.

func (*Google) Parse

func (p *Google) Parse(code string) (*GoogleUser, error)

Parse parse user from request

func (*Google) To

func (p *Google) To() *oauth2.Config

To to oauth2 credentials

type GoogleUser

type GoogleUser struct {
	ID      string `json:"id"`
	Email   string `json:"email"`
	Name    string `json:"name"`
	Link    string `json:"link"`
	Picture string `json:"picture"`
}

GoogleUser google user model

func (*GoogleUser) Save

func (p *GoogleUser) Save(db *gorm.DB) (*User, error)

Save save user to database

type Log

type Log struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	UserID    uint      `gorm:"not null" json:"-"`
	User      User      `json:"-"`
	Message   string    `gorm:"not null;type:VARCHAR(255)" json:"message"`
	CreatedAt time.Time `gorm:"not null;default:current_timestamp" json:"created_at"`
}

Log log model

type Permission

type Permission struct {
	web.Model
	User   User
	UserID uint `gorm:"not null"`
	Role   Role
	RoleID uint      `gorm:"not null"`
	Begin  time.Time `gorm:"not null;default:current_date;type:date"`
	End    time.Time `gorm:"not null;default:'1000-1-1';type:date"`
}

Permission permission model

func (*Permission) BeginS

func (p *Permission) BeginS() string

BeginS begintime

func (*Permission) Enable

func (p *Permission) Enable() bool

Enable is enable?

func (*Permission) EndS

func (p *Permission) EndS() string

EndS endtime

type Role

type Role struct {
	web.Model

	Name         string `gorm:"not null;index;type:VARCHAR(255)"`
	ResourceType string `gorm:"not null;default:'-';index;type:VARCHAR(255)"`
	ResourceID   uint   `gorm:"not null;default:0"`
}

Role role model

func (Role) String

func (p Role) String() string

type User

type User struct {
	gorm.Model
	Email    string `gorm:"not null;index;type:VARCHAR(255)" json:"email"`
	UID      string `gorm:"not null;unique_index;type:char(36)" json:"uid"`
	Home     string `gorm:"not null;type:VARCHAR(255)" json:"home"`
	Name     string `gorm:"not null;type:VARCHAR(255)" json:"name"`
	Password string `gorm:"not null;default:'-';type:VARCHAR(500)" json:"-"`

	ProviderType string `gorm:"not null;default:'unknown';index;type:VARCHAR(255)"`
	ProviderID   string `gorm:"not null;index;type:VARCHAR(255)"`

	LastSignIn  *time.Time `json:"last_sign_in"`
	SignInCount uint       `gorm:"not null;default:0" json:"sign_in_count"`
	ConfirmedAt *time.Time `json:"confirmed_at"`
	LockedAt    *time.Time `json:"locked_at"`

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

User user model

func (*User) IsAvailable

func (p *User) IsAvailable() bool

IsAvailable is available?

func (*User) IsConfirmed

func (p *User) IsConfirmed() bool

IsConfirmed is confirmed?

func (*User) IsLocked

func (p *User) IsLocked() bool

IsLocked is locked?

func (*User) SetGravatar

func (p *User) SetGravatar()

SetGravatar set gravatar logo

func (User) String

func (p User) String() string

Jump to

Keyboard shortcuts

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