models

package
v0.0.0-...-4678b66 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTSecret []byte

JWTSecret is the secret key for signing JWT tokens

View Source
var RefreshSecret []byte

RefreshSecret is the secret key for signing refresh tokens

View Source
var RefreshTokenExpireDuration = time.Hour * 24

RefreshTokenExpireDuration is the duration for refresh token expiration

View Source
var TokenExpireDuration = time.Hour

TokenExpireDuration is the duration for JWT token expiration

Functions

func CreateRefreshToken

func CreateRefreshToken(userID uint) (string, error)

func GenerateAccessToken

func GenerateAccessToken(userID uint) (string, error)

func InitDB

func InitDB() error

func VerifyAccessToken

func VerifyAccessToken(tokenString string) (*jwt.StandardClaims, error)

Types

type RefreshToken

type RefreshToken struct {
	gorm.Model
	ID        int64
	UserID    uint
	UUID      string
	ExpiresAt int64
}

RefreshToken represents a refresh token

func VerifyRefreshToken

func VerifyRefreshToken(tokenString string) (*RefreshToken, error)

type User

type User struct {
	gorm.Model
	Username     string `json:"username"`
	Email        string `json:"email"`
	Password     string `json:"-" gorm:"-"`
	Salt         string `json:"-"`
	PasswordHash string `json:"-"`

	LastLogin int64
}

func CreteUser

func CreteUser(user *User) (*User, error)

func GetUserByID

func GetUserByID(id uint) (*User, error)

func LoginUser

func LoginUser(username, password string) (*User, error)

func (*User) GeneratePasswordSalt

func (u *User) GeneratePasswordSalt(n int)

GeneratePasswordSalt generates a random string of the specified length

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword hashes a password with a given salt using bcrypt

Jump to

Keyboard shortcuts

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