services

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

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

Go to latest
Published: Sep 1, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateUser

func AuthenticateUser(ctx context.Context, user *auth.LoginRequest) (string, int64, string, *auth.SimpleUser, error)

验证用户密码是否正确,返回 JWT令牌,过期时间,刷新令牌,用户基本信息,错误信息

func CheckTokenRevoked

func CheckTokenRevoked(userID, tokenString string) bool

CheckTokenRevoked 检查令牌是否被撤销

func CheckUsernameExists

func CheckUsernameExists(username string) (bool, error)

查询是否username已经存在 只有在数据库查询的时候遇到除了mongo.ErrNoDocuments之外的错误才会返回错误

func GenerateAccessToken

func GenerateAccessToken(user *user.User) (string, int64, error)

GenerateAccessToken 生成JWT令牌

func GenerateAvatar

func GenerateAvatar(ctx context.Context, imageURL, multiavatarToken, smmsToken, fileName, userid string) (*string, error)

GenerateAvatar 生成用户头像并上传到 SM.MS 图床

func GenerateRefreshToken

func GenerateRefreshToken(user *user.User) (string, error)

GenerateRefreshToken 生成新的刷新令牌

func RefreshAccessToken

func RefreshAccessToken(refreshTokenString string) (string, int64, error)

RefreshAccessToken 刷新令牌

func RegisterUser

func RegisterUser(newUser *user.User) error

注册

func RevokeRefreshToken

func RevokeRefreshToken(userID, tokenString string) error

RevokeToken 使令牌失效

func UpdateUserAvatar

func UpdateUserAvatar(username, avatarUrl string) error

Types

type Claims

type Claims struct {
	UserId   string `json:"user_id"`
	Username string `json:"username"`
	jwt.StandardClaims
}

Claims 结构体,用于存储JWT声明

func VerifyAccessToken

func VerifyAccessToken(tokenString string) (*Claims, error)

VerifyAccessToken 验证令牌是否有效,返回声明

func VerifyRefreshToken

func VerifyRefreshToken(refreshTokenString string) (*Claims, error)

VerifyRefreshToken 验证刷新令牌

type Data

type Data struct {
	FileID    int    `json:"file_id"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Filename  string `json:"filename"`
	Storename string `json:"storename"`
	Size      int    `json:"size"`
	Path      string `json:"path"`
	Hash      string `json:"hash"`
	URL       string `json:"url"`
	Delete    string `json:"delete"`
	Page      string `json:"page"`
}

Data 定义一个结构体来表示 data 字段

type SmmsResponse

type SmmsResponse struct {
	Success   bool   `json:"success"`
	Code      string `json:"code"`
	Message   string `json:"message"`
	Data      Data   `json:"data"`
	RequestID string `json:"RequestId"`
}

SmmsResponse represents the response structure from SM.MS API SmmsResponse 定义一个结构体来表示整个响应

Jump to

Keyboard shortcuts

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