Documentation
¶
Index ¶
- type AuthClaims
- type PasswordChangeData
- type PasswordPolicy
- type Service
- func (s *Service) ChangePassword(userID uint, oldPassword, newPassword string) error
- func (s *Service) CheckPassword(password, hash string) bool
- func (s *Service) CheckUserExists(username, email string) error
- func (s *Service) CreateUserSession(user *models.User, ipAddress, userAgent string) (string, error)
- func (s *Service) GenerateRandomToken(length int) (string, error)
- func (s *Service) GetPasswordPolicy() PasswordPolicy
- func (s *Service) HashPassword(password string) (string, error)
- func (s *Service) Login(username, password string) (*models.User, error)
- func (s *Service) LogoutUser(sessionID string) error
- func (s *Service) NormalizeEmail(email string) string
- func (s *Service) NormalizeUsername(username string) string
- func (s *Service) Register(username, password, email string) (*models.User, error)
- func (s *Service) ValidateEmail(email string) error
- func (s *Service) ValidatePassword(password string, username string, email string) error
- func (s *Service) ValidateToken(tokenString string) (*AuthClaims, error)
- func (s *Service) ValidateUsername(username string) error
- func (s *Service) VerifyPassword(hashedPassword, password string) error
- type UserLoginData
- type UserRegistrationData
- type ValidationError
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 ¶
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 ¶
ChangePassword 修改密码
func (*Service) CheckPassword ¶
CheckPassword 验证密码
func (*Service) CheckUserExists ¶
CheckUserExists 检查用户是否存在
func (*Service) CreateUserSession ¶
CreateUserSession 创建用户会话
func (*Service) GenerateRandomToken ¶
GenerateRandomToken 生成随机令牌
func (*Service) GetPasswordPolicy ¶
func (s *Service) GetPasswordPolicy() PasswordPolicy
GetPasswordPolicy 获取当前密码策略
func (*Service) HashPassword ¶
HashPassword 加密密码
func (*Service) NormalizeEmail ¶
NormalizeEmail 规范化邮箱
func (*Service) NormalizeUsername ¶
NormalizeUsername 规范化用户名
func (*Service) ValidateEmail ¶
ValidateEmail 验证邮箱格式
func (*Service) ValidatePassword ¶
ValidatePassword 验证密码是否符合策略
func (*Service) ValidateToken ¶
func (s *Service) ValidateToken(tokenString string) (*AuthClaims, error)
ValidateToken 验证JWT令牌
func (*Service) ValidateUsername ¶
ValidateUsername 验证用户名
func (*Service) VerifyPassword ¶
VerifyPassword 验证密码是否正确
type UserLoginData ¶
UserLoginData 用户登录数据
type UserRegistrationData ¶
UserRegistrationData 用户注册数据
type ValidationError ¶
ValidationError 验证错误
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Click to show internal directories.
Click to hide internal directories.