auth

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthClaims

type AuthClaims struct {
	UserID    uint   `json:"user_id"`
	Username  string `json:"username"`
	Role      string `json:"role"`
	SessionID string `json:"session_id"`
	jwt.RegisteredClaims
}

AuthClaims JWT声明

type PasswordChangeData

type PasswordChangeData struct {
	UserID      uint
	OldPassword string
	NewPassword string
}

PasswordChangeData 密码修改数据

type PasswordPolicy

type PasswordPolicy struct {
	MinLength      int
	MaxLength      int
	RequireUpper   bool
	RequireLower   bool
	RequireNumber  bool
	RequireSpecial bool
	ForbidCommon   bool
	ForbidPersonal bool
}

PasswordPolicy 密码策略

type Service

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

Service 认证服务

func NewService

func NewService(repositoryManager *repository.RepositoryManager, manager *config.ConfigManager) *Service

NewService 创建认证服务

func (*Service) ChangePassword

func (s *Service) ChangePassword(userID uint, oldPassword, newPassword string) error

ChangePassword 修改密码

func (*Service) CheckPassword

func (s *Service) CheckPassword(password, hash string) bool

CheckPassword 验证密码

func (*Service) CheckUserExists

func (s *Service) CheckUserExists(username, email string) error

CheckUserExists 检查用户是否存在

func (*Service) CreateUserSession

func (s *Service) CreateUserSession(user *models.User, ipAddress, userAgent string) (string, error)

CreateUserSession 创建用户会话

func (*Service) GenerateRandomToken

func (s *Service) GenerateRandomToken(length int) (string, error)

GenerateRandomToken 生成随机令牌

func (*Service) GetPasswordPolicy

func (s *Service) GetPasswordPolicy() PasswordPolicy

GetPasswordPolicy 获取当前密码策略

func (*Service) HashPassword

func (s *Service) HashPassword(password string) (string, error)

HashPassword 加密密码

func (*Service) Login

func (s *Service) Login(username, password string) (*models.User, error)

Login 用户登录

func (*Service) LogoutUser

func (s *Service) LogoutUser(sessionID string) error

LogoutUser 用户登出

func (*Service) NormalizeEmail

func (s *Service) NormalizeEmail(email string) string

NormalizeEmail 规范化邮箱

func (*Service) NormalizeUsername

func (s *Service) NormalizeUsername(username string) string

NormalizeUsername 规范化用户名

func (*Service) Register

func (s *Service) Register(username, password, email string) (*models.User, error)

Register 用户注册

func (*Service) ValidateEmail

func (s *Service) ValidateEmail(email string) error

ValidateEmail 验证邮箱格式

func (*Service) ValidatePassword

func (s *Service) ValidatePassword(password string, username string, email string) error

ValidatePassword 验证密码是否符合策略

func (*Service) ValidateToken

func (s *Service) ValidateToken(tokenString string) (*AuthClaims, error)

ValidateToken 验证JWT令牌

func (*Service) ValidateUsername

func (s *Service) ValidateUsername(username string) error

ValidateUsername 验证用户名

func (*Service) VerifyPassword

func (s *Service) VerifyPassword(hashedPassword, password string) error

VerifyPassword 验证密码是否正确

type UserLoginData

type UserLoginData struct {
	Username  string
	Password  string
	IPAddress string
	UserAgent string
}

UserLoginData 用户登录数据

type UserRegistrationData

type UserRegistrationData struct {
	Username string
	Email    string
	Password string
	Nickname string
}

UserRegistrationData 用户注册数据

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError 验证错误

func (ValidationError) Error

func (e ValidationError) Error() string

Jump to

Keyboard shortcuts

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