user

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Secret string

holds the hmac secret, is set from main

Functions

func Auth

func Auth(authenticated bool) gin.HandlerFunc

checks for session cookie and handles permissions

func CheckDuplicate

func CheckDuplicate(name string) (check bool)

check for duplicate name before registering

func HashPassword

func HashPassword(password string) (hash []byte, err error)

hash a given password

func IsValidName

func IsValidName(name string) bool

checks if the name is valid

func Protect

func Protect() gin.HandlerFunc

Protect will check to see if a user has the correct permissions

Types

type Authenticator

type Authenticator interface {
	IsValid() bool
	IsAuthorized(ib uint) bool
	SetId(uid uint)
	SetAuthenticated()
	Password() (err error)
	ComparePassword(password string) bool
	FromName(name string) (err error)
	CreateToken() (newtoken string, err error)
}

type User

type User struct {
	Id              uint
	Name            string
	IsAuthenticated bool
	// contains filtered or unexported fields
}

user struct

func DefaultUser

func DefaultUser() User

create a user struct

func (*User) ComparePassword

func (u *User) ComparePassword(password string) bool

compare password to

func (*User) CreateToken

func (u *User) CreateToken() (newtoken string, err error)

Creates a JWT token with our claims

func (*User) FromName

func (u *User) FromName(name string) (err error)

will get the password and user id from the database for a user name

func (*User) IsAuthorized

func (u *User) IsAuthorized(ib uint) bool

get the user info from id

func (*User) IsValid

func (u *User) IsValid() bool

check user struct validity

func (*User) Password

func (u *User) Password() (err error)

will get the password and name from the database for an instantiated user

func (*User) SetAuthenticated

func (u *User) SetAuthenticated()

sets authenticated

func (*User) SetId

func (u *User) SetId(uid uint)

sets the user id

Jump to

Keyboard shortcuts

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