util

package
v0.0.0-...-44a091e Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package util provides some useful utility functions

Index

Constants

View Source
const ConfirmEmailPrefix = "confirm-email:"

ConfirmEmailPrefix is the string that is prefixed before the actual confirm email token while storing in redis so that it will be easily identifiable and it will not collide with any other key

View Source
const ExpirationDuration = 24 * time.Hour

ExpirationDuration is the duration after which the email link expires

View Source
const ForgotPasswordPrefix = "forgot-password:"

ForgotPasswordPrefix is the string that is prefixed before the actual forgot password token while storing in redis so that it will be easily identifiable and it will not collide with any other key

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(hashedPasswd string, plainPasswd string) bool

ComparePasswords compares a hashed password with plain string password and returns a boolean representing whether the passwords match or not

func Decrypt

func Decrypt(encryptedText string) (string, error)

Decrypt decrypts a base64 string using the secret key and returns the plaintext string

func Encrypt

func Encrypt(text string) (string, error)

Encrypt encrypts a string to base64 crypto using AES256 encryption

func GetUserIDFromToken

func GetUserIDFromToken(rdb *redis.Client, token string, prefix string) (string, func() error, error)

GetUserIDFromToken first decrypts the provided token with the secret key and then looks up the user id of the key in redis and returns it

func HashPassword

func HashPassword(passwd string) (string, error)

HashPassword hashed the given password using bcrypt and returns the string form of the hashed password

func LoadEnv

func LoadEnv(verify bool) error

LoadEnv Loads the environment variables defined in the .env file according to the environment running

func SendEmail

func SendEmail(rdb *redis.Client, userID, email, prefix, endpoint string) error

SendEmail creates a unique token for a given userID, stores that token in redis and sends an email to the email address of that user to ask them to visit that link and do what is required

Types

This section is empty.

Jump to

Keyboard shortcuts

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