utils

package
v0.0.0-...-bbbc4ea Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ResetPasswordEmailTemplate = `` /* 436-byte string literal not displayed */

Variables

View Source
var (
	TokenExpired     = errors.New(" Token is expired")
	TokenNotValidYet = errors.New(" Token not active yet")
	TokenMalformed   = errors.New(" That's not even a token")
	TokenInvalid     = errors.New(" Couldn't handle this token:")
)

Error notes

Functions

func BytesDataHash

func BytesDataHash(data []byte) string

return the hash value of data. user MD5

func CheckEmailSentIn3Minute

func CheckEmailSentIn3Minute(email string) bool

Check the record of sent an email for reset password to the user in 10 minute. If sent already, return true, else return false

func CreatQRCodeBytes

func CreatQRCodeBytes(content string) ([]byte, error)

return a qrCode bytes data

func CreateJWTToken

func CreateJWTToken(claims CustomJWTClaims, salt []byte) (string, error)

Create JWT token

func GetPasswordHash

func GetPasswordHash(password string, salts ...string) string

get a password hash vale with salts

func GetRedisClient

func GetRedisClient(addr, password string, db int) *redis.Client

func GetReflectFieldNames

func GetReflectFieldNames(instance interface{}) map[string]int

get all field name of a struct

func GetReflectValueByField

func GetReflectValueByField(instance interface{}, field string) (interface{}, error)

get a field value if a struct by the field name

func GinFormFileHash

func GinFormFileHash(file *multipart.FileHeader) (string, []byte, error)

return the hash value of an file which recv in Gin

func ParseQRCodeBytes

func ParseQRCodeBytes(data []byte) (string, error)

return qrCode real content

func RefreshJWTToken

func RefreshJWTToken(tokenString string, salt []byte, survivalTime time.Duration) (string, error)

Refresh JWT token

func SendPasswordResetEmail

func SendPasswordResetEmail(email, authToken string) error

Send an email for reset password to the user, the core content is a authentication string, that can mark user was sign in, use to update the password

func SetEmailSentTag

func SetEmailSentTag(email string)

Save a tag value in redis, to mark have sent the reset password email for the user. The expire time of the data is 3 minute.

func UploadDataToCloud

func UploadDataToCloud() error

todo upload file data to oss or other static file server

func UploadFileToLocal

func UploadFileToLocal(data []byte, path string) error

upload the file to local dir

Types

type CustomJWTClaims

type CustomJWTClaims struct {
	Id int64 `json:"user_id"`
	jwt.StandardClaims
}

Payload, contains some custom information

func ParseJWTToken

func ParseJWTToken(tokenString string, salt []byte) (*CustomJWTClaims, error)

Parse JWT token

Jump to

Keyboard shortcuts

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