Documentation
¶
Index ¶
- Constants
- Variables
- func AuthHandler(mod Module) gin.HandlerFunc
- func UserRestricted() gin.HandlerFunc
- type Module
- func (mod *Module) ActivateUser(user UserModel) (UserModel, error)
- func (mod *Module) Authenticate(user UserModel, password string) (UserModel, error)
- func (mod *Module) CreateNewUser(user UserModel) (UserModel, error)
- func (mod *Module) DeactivatedUser(user UserModel) (UserModel, error)
- func (mod *Module) Deauthenticate() error
- func (mod *Module) IsAuthenticated() bool
- func (mod *Module) UpdateSession(sess sessions.Session)
- func (mod *Module) User() (User, error)
- type Repository
- type User
- type UserModel
Constants ¶
View Source
const ( // StatusActive represent user with active status StatusActive = true // StatusInactive represent user with inactive status StatusInactive = false )
View Source
const AUTH_KEY = "auth"
View Source
const (
// USER as global key identifier when storing data into session
USER = "user"
)
Variables ¶
View Source
var ( // ErrAlreadyActived displaying error messeage when user has already activated ErrAlreadyActived = errors.New("user already actived") // ErrAlreadyInactived displaying error messeage when user has already Inactivated ErrAlreadyInactived = errors.New("user already inactived") // ErrInactive displaying error message when user has inactive status ErrInactive = errors.New("inactive user") // ErrMissmatch displaying error message when user failed to be authenticated ErrMissmatch = errors.New("missmatch username / password combination") // ErrNotFound displaying error message when user has not been found ErrNotFound = errors.New("user not found") // ErrUserDuplicate displaying error message when the same user has been registered ErrUserDuplicate = errors.New("user duplicate") )
Functions ¶
func AuthHandler ¶
func AuthHandler(mod Module) gin.HandlerFunc
AuthHandler store session into module
func UserRestricted ¶
func UserRestricted() gin.HandlerFunc
UserRestricted is a middleware to restrict some route for authenticated user only
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module for Authentication
func (*Module) ActivateUser ¶
ActivateUser set inactive user as active
func (*Module) Authenticate ¶
Authenticate verify username and password is match with bcrypt Encryption
func (*Module) CreateNewUser ¶
CreateNewUser storing new user data into repository
func (*Module) DeactivatedUser ¶
DeactivateUser set inactive user as Deactived
func (*Module) Deauthenticate ¶
Deauthenticate delete user from current session
func (*Module) IsAuthenticated ¶
IsAuthenticated helper to check whether current session has been authenticated or not
func (*Module) UpdateSession ¶
UpdateSession replacing current sessions.Session in the module
type Repository ¶
type Repository interface {
Find(uint64) (UserModel, error)
FindByUsername(string) (UserModel, error)
FindAll() ([]UserModel, error)
Store(UserModel) (UserModel, error)
Update(UserModel) (UserModel, error)
Remove(uint64) error
}
Repository talk to database
Click to show internal directories.
Click to hide internal directories.