models

package
v0.0.0-...-f37b1f8 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2016 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrations

func Migrations()

Migrations creates data tables and records for admin user, base client, groups and abilities

Types

type APIMessage

type APIMessage struct {
	Message string `json:"message"`
}

type Ability

type Ability struct {
	ID        uint
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`

	Name    string   `json:"name"`
	Clients []Client `gorm:"many2many:ability_clients;"  json:"clients"`
}

type AuthUser

type AuthUser struct {
	Name         string `json:"name"`
	Email        string `json:"email"`
	Password     string `json:"password"`
	ClientSecret string `json:"client_secret"`
}

AuthUser struct has the information to be use when an user try to authenticate

type Client

type Client struct {
	ID        uint
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`

	Name         string    `json:"name"`
	ClientID     string    `json:"client_id"`
	ClientSecret string    `json:"client_secret"`
	Groups       []Group   `gorm:"many2many:client_groups;"  json:"groups"`
	Abilities    []Ability `gorm:"many2many:ability_clients;"  json:"abilities"`
}

func (*Client) GenerateKeys

func (c *Client) GenerateKeys()

type Group

type Group struct {
	ID        uint
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`

	Name        string   `json:"name"`
	Description string   `json:"description"`
	Users       []User   `gorm:"many2many:user_groups;"  json:"users"`
	Clients     []Client `gorm:"many2many:client_groups;"  json:"clients"`
}

func (Group) HasAbility

func (g Group) HasAbility(abilityName string) bool

HasAbility checks if group has a specific ability

type NewAbility

type NewAbility struct {
	Name string `json:"name"`
}

type NewClient

type NewClient struct {
	Name string `json:"name"`
}

type NewGroup

type NewGroup struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type NewUser

type NewUser struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

NewUser struct has the information to create a new user

type User

type User struct {
	ID        uint
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`

	Name            string `json:"name"`
	Email           string `json:"email"`
	EncryptPassword string `json:"-"`

	Groups []Group `gorm:"many2many:user_groups;"   json:"groups"`
}

User keep user information like email and password for authentication

func (User) Authenticate

func (u User) Authenticate(email, password, secretKey string) bool

Authenticate check if email and password are correct and if have authorization for use the client

func (User) HasAbility

func (u User) HasAbility(abilityName string) bool

HasAbility checks if user has a specific ability

func (User) HasClientAccess

func (u User) HasClientAccess(secretKey string) bool

HasClientAccess checks if user has authorization to authenticate in a client

func (*User) SetEmail

func (u *User) SetEmail(email string) error

SetEmail sets the user email after validate it

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword sets the user password after encrypt it

Jump to

Keyboard shortcuts

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