Documentation
¶
Overview ¶
Package auth implements for web the module for authentification
Index ¶
- Variables
- func GetCurrentUserID(c *gin.Context) (uuid.UUID, bool)
- func HashPassword(password string) (string, error)
- func IsLoginWithUserID(c *gin.Context) (uuid.UUID, bool)
- func MiddlewareLogin(ws *web.Service) gin.HandlerFunc
- func MiddlewarePermissionParam(ws *web.Service, obj HasPermission, param string) gin.HandlerFunc
- func MiddlewarePermissionParamUUID(ws *web.Service, obj HasPermission) gin.HandlerFunc
- func Register(r *gin.Engine, ws *web.Service)
- func ValidatePassword(hash, password string) bool
- type HasPermission
- type PasswordWithForgetCode
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAPIUserNotFound api error string if user not found ErrAPIUserNotFound = errors.New("user not found") // ErrAPIIncorrectPassword api error string if password is incorrect ErrAPIIncorrectPassword = errors.New("incorrect password") // ErrAPINoSession api error string if no session exists ErrAPINoSession = errors.New("no session") // ErrAPICreateSession api error string if session could not created ErrAPICreateSession = errors.New("create session") // ErrAPICreatePassword api error string if password could not created ErrAPICreatePassword = errors.New("error during create password") // ErrAPINoPermission api error string if an error happen on accesing this object ErrAPINoPermission = errors.New("error on access an object") )
var PasswordHashCost = bcrypt.DefaultCost
PasswordHashCost - to set global, for more speed or security
Functions ¶
func GetCurrentUserID ¶
GetCurrentUserID get UserID of session in golang-gin
func HashPassword ¶
HashPassword - create new hash of password
func IsLoginWithUserID ¶
IsLoginWithUserID get UserID of session in golang-gin
func MiddlewareLogin ¶
func MiddlewareLogin(ws *web.Service) gin.HandlerFunc
MiddlewareLogin if user id in session for golang-gin
func MiddlewarePermissionParam ¶
func MiddlewarePermissionParam(ws *web.Service, obj HasPermission, param string) gin.HandlerFunc
MiddlewarePermissionParam if user has access to obj, check access in golang-gin url by param
func MiddlewarePermissionParamUUID ¶
func MiddlewarePermissionParamUUID(ws *web.Service, obj HasPermission) gin.HandlerFunc
MiddlewarePermissionParamUUID if user has access to obj, check access by uuid in golang-gin url param uuid
func ValidatePassword ¶
ValidatePassword - check if given password is equal to saved hash
Types ¶
type HasPermission ¶
type HasPermission interface {
HasPermission(tx *gorm.DB, userID, objID uuid.UUID) (interface{}, error)
}
HasPermission interface for middleware check in other models
type PasswordWithForgetCode ¶
type PasswordWithForgetCode struct { ForgetCode uuid.UUID `json:"forget_code"` Password string `json:"password"` }
PasswordWithForgetCode - JSON Request to set password without login
type User ¶
type User struct { ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid()" example:"88078ec0-2135-445f-bf05-632701c77695"` Username string `json:"username" gorm:"unique" example:"kukoon"` Password string `json:"-" example:"super secret password"` ForgetCode *uuid.UUID `json:"-" gorm:"forget_code;type:uuid"` }
User struct - default User model which could be extended
func GetCurrentUser ¶
GetCurrentUser get User of session from database in golang-gin
func (*User) SetPassword ¶
SetPassword - create new hash of password
func (*User) ValidatePassword ¶
ValidatePassword - check if given password is equal to saved hash