auth

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package auth implements for web the module for authentification

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var PasswordHashCost = bcrypt.DefaultCost

PasswordHashCost - to set global, for more speed or security

Functions

func GetCurrentUserID

func GetCurrentUserID(c *gin.Context) (uuid.UUID, bool)

GetCurrentUserID get UserID of session in golang-gin

func HashPassword

func HashPassword(password string) (string, error)

HashPassword - create new hash of password

func IsLoginWithUserID

func IsLoginWithUserID(c *gin.Context) (uuid.UUID, bool)

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 Register

func Register(r *gin.Engine, ws *web.Service)

Register to WebService

func ValidatePassword

func ValidatePassword(hash, password string) bool

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

func GetCurrentUser(c *gin.Context, ws *web.Service) (*User, bool)

GetCurrentUser get User of session from database in golang-gin

func NewUser

func NewUser(username, password string) (*User, error)

NewUser by username and password

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword - create new hash of password

func (*User) ValidatePassword

func (u *User) ValidatePassword(password string) bool

ValidatePassword - check if given password is equal to saved hash

Jump to

Keyboard shortcuts

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