auth

package
v0.0.0-...-d94e6cf Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenDuration is validity duration of a token.
	TokenDuration = 24 * time.Hour
	// UserKey is the key to reference the user in context.
	UserKey = "context_user"
)

Variables

View Source
var (
	// ErrTokenInvalid is returned if token is invalid or expired.
	ErrTokenInvalid = errors.New("token invalid or expired")
	// ErrAccountAlreadyExist is returned if an email already exists in the db.
	ErrAccountAlreadyExist = errors.New("the account already exist")
	// ErrInvalidCredentials is returned if an email and password don't match a db entry.
	ErrInvalidCredentials = errors.New("invalid credentials")
	// ErrWrongPassword is returned if the provided password doesn't match.
	ErrWrongPassword = errors.New("wrong password")
)

Functions

func HashPassword

func HashPassword(password string) string

HashPassword hash password using sha512 and salt

Types

type Controller

type Controller struct {
	DB          *gorm.DB
	RedisClient *redis.Client
}

Controller handles authentication routines.

func NewController

func NewController(db *gorm.DB, cfg *config.Config) *Controller

NewController instantiate a new Controller that handles auth routines.

func (Controller) AuthMiddleware

func (controller Controller) AuthMiddleware(fn httputils.APIFunc) httputils.APIFunc

AuthMiddleware handles token checking.

func (Controller) SignIn

func (controller Controller) SignIn(w http.ResponseWriter, r *http.Request, vars map[string]string) error

SignIn handles User creation

func (Controller) SignOut

func (controller Controller) SignOut(w http.ResponseWriter, r *http.Request, vars map[string]string) error

SignOut handles User creation

func (Controller) SignUp

func (controller Controller) SignUp(w http.ResponseWriter, r *http.Request, vars map[string]string) error

SignUp handles User creation

type Token

type Token struct {
	Token string `json:"token"`
}

Token holds the user token

Jump to

Keyboard shortcuts

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