takeanote-api: github.com/TakeANote/takeanote-api/controllers/auth Index | Files

package auth

import "github.com/TakeANote/takeanote-api/controllers/auth"

Index

Package Files

auth.go

Constants

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

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")
)

func HashPassword Uses

func HashPassword(password string) string

HashPassword hash password using sha512 and salt

type Controller Uses

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

Controller handles authentication routines.

func NewController Uses

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

NewController instantiate a new Controller that handles auth routines.

func (Controller) AuthMiddleware Uses

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

AuthMiddleware handles token checking.

func (Controller) SignIn Uses

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

SignIn handles User creation

func (Controller) SignOut Uses

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

SignOut handles User creation

func (Controller) SignUp Uses

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

SignUp handles User creation

type Token Uses

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

Token holds the user token

Package auth imports 14 packages (graph). Updated 2018-04-17. Refresh now. Tools for package owners.