auth

package
v0.0.0-...-c19555c Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTKey = []byte("your_secret_key")

Functions

func GenerateJWT

func GenerateJWT(user *model.User) (string, time.Time, error)

Types

type CreateAccountRequest

type CreateAccountRequest struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type CustomClaims

type CustomClaims struct {
	UserID uint `json:"user_id"`
	jwt.StandardClaims
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service *Service) *Handler

func (*Handler) CreateAccount

func (h *Handler) CreateAccount(c *gin.Context)

func (*Handler) Login

func (h *Handler) Login(c *gin.Context)

type LoginRequest

type LoginRequest struct {
	Username     string `json:"username"`
	Password     string `json:"password"`
	RefreshToken string `json:"refreshToken"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(db *gorm.DB, userRetriever UserRetriever) *Service

func (*Service) Authenticate

func (s *Service) Authenticate(username, password string) (*model.User, error)

func (*Service) CreateAccountService

func (s *Service) CreateAccountService(input CreateAccountRequest) error

func (*Service) GenerateRefreshToken

func (s *Service) GenerateRefreshToken(userID uint) (string, time.Time, error)

func (*Service) ValidateRefreshToken

func (s *Service) ValidateRefreshToken(tokenString string) (uint, error)

type UserRetriever

type UserRetriever interface {
	GetUserByID(userID string) (*model.User, error)
}

Jump to

Keyboard shortcuts

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