user

package module
v0.0.0-...-e2ab7eb Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2016 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func ForgotPasswordGetHandler

func ForgotPasswordGetHandler(ctx *enliven.Context)

ForgotPasswordGetHandler Allows a user to enter their email address to have their password reset

func ForgotPasswordPostHandler

func ForgotPasswordPostHandler(ctx *enliven.Context)

ForgotPasswordPostHandler accepts a posted email address which we'll send a new verification code to so they can reset their password

func GeneratePasswordHash

func GeneratePasswordHash(password string, cost ...int) string

GeneratePasswordHash produces a bcrypt hash and returns it

func LoginGetHandler

func LoginGetHandler(ctx *enliven.Context)

LoginGetHandler handles get requests to the login route

func LoginPostHandler

func LoginPostHandler(ctx *enliven.Context)

LoginPostHandler handles the form submission for logging a user in.

func LogoutHandler

func LogoutHandler(ctx *enliven.Context)

LogoutHandler logs a user out and redirects them to the configured page.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func PasswordResetGetHandler

func PasswordResetGetHandler(ctx *enliven.Context)

PasswordResetGetHandler checks if a password reset code is legit, and presents the user with a password reset form.

func PasswordResetPostHandler

func PasswordResetPostHandler(ctx *enliven.Context)

PasswordResetPostHandler checks if a password reset code is legit, and and resets the users password to what has been posted.

func ProfileGetHandler

func ProfileGetHandler(ctx *enliven.Context)

ProfileGetHandler displays the profile editor

func ProfilePostHandler

func ProfilePostHandler(ctx *enliven.Context)

ProfilePostHandler handles the updating of a user's profile

func RegisterGetHandler

func RegisterGetHandler(ctx *enliven.Context)

RegisterGetHandler handles get requests to the register route

func RegisterPostHandler

func RegisterPostHandler(ctx *enliven.Context)

RegisterPostHandler handles get requests to the register route

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SessionMiddleware

func SessionMiddleware(ctx *enliven.Context, next enliven.NextHandlerFunc)

SessionMiddleware handles adding the elements to the context that carry the user's id and status

func VerifyHandler

func VerifyHandler(ctx *enliven.Context)

VerifyHandler checks a user's verification code to see if it matches.

func VerifyPasswordHash

func VerifyPasswordHash(hash string, password string) bool

VerifyPasswordHash checks a password for validity

Types

type App

type App struct{}

App handles adding a route handler for static assets

func NewApp

func NewApp() *App

NewApp generates and returns an instance of the app

func (*App) AddPermission

func (ua *App) AddPermission(permission string, ev *enliven.Enliven, groups ...string)

AddPermission adds a new permission to the user table if it doesn't exist

func (*App) GetName

func (ua *App) GetName() string

GetName returns the app's name

func (*App) HasPermission

func (ua *App) HasPermission(permission string, ctx *enliven.Context) bool

HasPermission checks if a user has a permission matching the permission string passed in

func (*App) Initialize

func (ua *App) Initialize(ev *enliven.Enliven)

Initialize sets up our app to handle embedded static asset requests

type FormError

type FormError struct {
	Message string
	Field   string
}

FormError represents an error in form validation

type Group

type Group struct {
	gorm.Model

	Name        string       `gorm:"not null;unique;"`
	Permissions []Permission `gorm:"many2many:group_permission;"`
}

Group describes the user group database structure

type Permission

type Permission struct {
	gorm.Model

	Name string `gorm:"not_null;unique_index;"`
}

Permission describes a permission that can be linked to many groups

type User

type User struct {
	gorm.Model

	DisplayName      string
	Username         string  `gorm:"type:varchar(100);unique_index;"`
	Email            string  `gorm:"type:varchar(100);unique_index;"`
	Password         string  `gorm:"type:varchar(100);"`
	VerificationCode string  `gorm:"type:varchar(64);index;"`
	Status           int     `gorm:"default:0;"`
	Groups           []Group `gorm:"many2many:user_group;"`
	Superuser        bool    `gorm:"index;"`
}

User describes the user database structure.

func GetUser

func GetUser(ctx *enliven.Context) *User

GetUser returns an instance of the User model

func (*User) GetDisplayName

func (u *User) GetDisplayName() string

GetDisplayName gets the proper display name for a user.

func (User) Stringify

func (u User) Stringify() string

Stringify returns the name of the user

func (*User) UserHasPermission

func (u *User) UserHasPermission(name string) bool

UserHasPermission checks if a user has a specific permission

Jump to

Keyboard shortcuts

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