Documentation
¶
Index ¶
- Constants
- Variables
- func HashPassword(password string) string
- type Controller
- func (controller Controller) AuthMiddleware(fn httputils.APIFunc) httputils.APIFunc
- func (controller Controller) SignIn(w http.ResponseWriter, r *http.Request, vars map[string]string) error
- func (controller Controller) SignOut(w http.ResponseWriter, r *http.Request, vars map[string]string) error
- func (controller Controller) SignUp(w http.ResponseWriter, r *http.Request, vars map[string]string) error
- type Token
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 ¶
HashPassword hash password using sha512 and salt
Types ¶
type Controller ¶
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
Click to show internal directories.
Click to hide internal directories.