userutil

package
v0.0.0-...-07bc221 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmailExists    = errors.New("mailExists")
	ErrUsernameExists = errors.New("usernameExists")
	ErrPasswd         = errors.New("password not correct")
	ErrDatabase       = errors.New("database error")
	ErrJwtExpired     = errors.New("jwt is expired")
)

Functions

func CheckEmailExists

func CheckEmailExists(email string) (bool, error)

CheckEmailExists @description Check email if exists in database

func CheckPassword

func CheckPassword(username, password string) (int, error)

CheckPassword @description 验证用户登录 if return < 0 error, pwd error or server error if return > 0 success, return user id

func CheckPwd

func CheckPwd(password, hash string) error

CheckPwd check if password is correct

func CheckUserNameExists

func CheckUserNameExists(username string) (bool, error)

CheckUserNameExists @description Check username if exists in database

func EmailChangeNotify

func EmailChangeNotify(email string, timestamp time.Time)

func GenerateJwt

func GenerateJwt(userId int, clientIp string) (string, error)

GenerateJwt @description generate JWT token for user

func GeneratePwd

func GeneratePwd(password string) (string, error)

GeneratePwd hash password

func GetJwtFromAuth

func GetJwtFromAuth(Authorization string) string

GetJwtFromAuth 从 Authorization 中获取JWT

func PasswordChangeNotify

func PasswordChangeNotify(email string, timestamp time.Time)

func RegisterCheck

func RegisterCheck(username, email string) error

RegisterCheck @description Check users email or user if already exists

func SetJwtExpire

func SetJwtExpire(c context.Context, _jwt string) error

SetJwtExpire @description 标记JWT过期

Types

type JwtClaims

type JwtClaims struct {
	ID       string `json:"jti,omitempty"`
	ExpireAt int64  `json:"exp,omitempty"`
	IssuedAt int64  `json:"iat,omitempty"`
	Issuer   string `json:"iss,omitempty"`
	Username string `json:"username"`
	UserId   int    `json:"userId"`
	Email    string `json:"email"`
	LastTime int64  `json:"lastTime"`
	jwt.RegisteredClaims
}

func JwtDecode

func JwtDecode(_jwt string) (JwtClaims, error)

JwtDecode @description check JWT token

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	UserId   int    `json:"userId"`
	Email    string `json:"email"`
	LastTime int64  `json:"lastTime"`
}

func CheckPermission

func CheckPermission(ctx context.Context, _jwt string) (UserInfo, error)

CheckPermission @description check user permission

Jump to

Keyboard shortcuts

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