service

package
v0.0.0-...-9c786f9 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package service contains common functions used by the whole application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcHash

func CalcHash(plaintext, keyOptional []byte) ([]byte, error)

CalcHash generates a fixed-sized BLAKE2b-256 hash of the given text

func DecryptEmail

func DecryptEmail(emailNonce, emailCipher string) (email string, err error)

DecryptEmail returns the plaintext email from the given cipher and nonce

func DelMem2FA

func DelMem2FA(authID uint64)

DelMem2FA - delete secrets from memory

func GenerateCode

func GenerateCode(length int) (string, error)

GenerateCode generates a random alphanumeric code of the given length

func GetClaims

func GetClaims(c *gin.Context) middleware.MyCustomClaims

GetClaims - get JWT custom claims

func GetEmailByAuthID

func GetEmailByAuthID(authID uint64) (string, error)

GetEmailByAuthID fetches user email by authID

func GetHash

func GetHash(dataIn []byte) (dataOut []byte, err error)

GetHash returns single or nested hash of the data

func GetUserByEmail

func GetUserByEmail(email string, decryptEmail bool) (*model.Auth, error)

GetUserByEmail fetches auth info by email or hash of the email

func IsAuthIDValid

func IsAuthIDValid(authID uint64) bool

IsAuthIDValid checks if the given authID is available in the database

func IsTokenAllowed

func IsTokenAllowed(jti string) bool

IsTokenAllowed returns true when the token is not in the blacklist

Dependency: JWT, Redis database + enable 'INVALIDATE_JWT' in .env

func JWTBlacklistChecker

func JWTBlacklistChecker() gin.HandlerFunc

JWTBlacklistChecker validates a token against the blacklist

func RandomByte

func RandomByte(length int) ([]byte, error)

RandomByte returns a secure random byte slice of the given length

func SendEmail

func SendEmail(email string, emailType int, opts ...string) (bool, error)

SendEmail sends a verification/password recovery email if

- required by the application

- an external email service is configured

- a redis database is configured

{true, nil} => email delivered successfully

{false, nil} => email delivery not required/service not configured

{false, error} => email delivery failed

func Validate2FA

func Validate2FA(encryptedMessage []byte, issuer string, userInput string) ([]byte, string, error)

Validate2FA validates user-provided OTP

func ValidateAuthID

func ValidateAuthID(authID uint64) bool

ValidateAuthID - check whether authID is missing

func ValidateUserID

func ValidateUserID(authID uint64, email string) bool

ValidateUserID - check whether authID or email is missing

Types

type PostmarkParams

type PostmarkParams struct {
	ServerToken   string
	TemplateID    int64
	From          string
	To            string
	Tag           string
	TrackOpens    bool
	TrackLinks    string
	MessageStream string
	HTMLModel     map[string]interface{}
}

PostmarkParams - parameters for postmark email delivery service

Jump to

Keyboard shortcuts

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