Documentation ¶
Overview ¶
Package service contains common functions used by the whole application
Index ¶
- func CalcHash(plaintext, keyOptional []byte) ([]byte, error)
- func DecryptEmail(emailNonce, emailCipher string) (email string, err error)
- func DelMem2FA(authID uint64)
- func GenerateCode(length int) (string, error)
- func GetClaims(c *gin.Context) middleware.MyCustomClaims
- func GetEmailByAuthID(authID uint64) (string, error)
- func GetHash(dataIn []byte) (dataOut []byte, err error)
- func GetUserByEmail(email string, decryptEmail bool) (*model.Auth, error)
- func IsAuthIDValid(authID uint64) bool
- func IsTokenAllowed(jti string) bool
- func JWTBlacklistChecker() gin.HandlerFunc
- func Postmark(params PostmarkParams) (postmark.EmailResponse, error)
- func RandomByte(length int) ([]byte, error)
- func SendEmail(email string, emailType int, opts ...string) (bool, error)
- func Validate2FA(encryptedMessage []byte, issuer string, userInput string) ([]byte, string, error)
- func ValidateAuthID(authID uint64) bool
- func ValidateUserID(authID uint64, email string) bool
- type PostmarkParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptEmail ¶
DecryptEmail returns the plaintext email from the given cipher and nonce
func GenerateCode ¶
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 ¶
GetEmailByAuthID fetches user email by authID
func GetUserByEmail ¶
GetUserByEmail fetches auth info by email or hash of the email
func IsAuthIDValid ¶
IsAuthIDValid checks if the given authID is available in the database
func IsTokenAllowed ¶
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 Postmark ¶
func Postmark(params PostmarkParams) (postmark.EmailResponse, error)
Postmark email delivery service using HTML templates
https://postmarkapp.com/developer/api/email-api
https://postmarkapp.com/developer/api/templates-api
https://account.postmarkapp.com/servers/{ServerID}/templates
func RandomByte ¶
RandomByte returns a secure random byte slice of the given length
func SendEmail ¶
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 ¶
Validate2FA validates user-provided OTP
func ValidateAuthID ¶
ValidateAuthID - check whether authID is missing
func ValidateUserID ¶
ValidateUserID - check whether authID or email is missing