feat(auth): 登录注册 - 添加短信通知与组合验证支持

This commit is contained in:
ddCat committed 2026-09-22 23:46:15 +08:00
1 parent 6c013ebf7e
commit bc0d109428
55 files changed
+4013 -103

No files matched your search

+14 -10
View File
@@ -3,16 +3,19 @@ package model
import "time"
type User struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
Username string `json:"username" gorm:"uniqueIndex;size:80"`
Email string `json:"email,omitempty" gorm:"size:160"`
DisplayName string `json:"displayName" gorm:"size:80"`
Role UserRole `json:"role" gorm:"index;size:24"`
Status UserStatus `json:"status" gorm:"index;size:24"`
PasswordHash string `json:"-"`
LastLoginAt *time.Time `json:"lastLoginAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id" gorm:"primaryKey;size:36"`
Username string `json:"username" gorm:"uniqueIndex;size:80"`
Email string `json:"email,omitempty" gorm:"size:160"`
Phone string `json:"phone,omitempty" gorm:"size:24"`
EmailVerifiedAt *time.Time `json:"emailVerifiedAt,omitempty"`
PhoneVerifiedAt *time.Time `json:"phoneVerifiedAt,omitempty"`
DisplayName string `json:"displayName" gorm:"size:80"`
Role UserRole `json:"role" gorm:"index;size:24"`
Status UserStatus `json:"status" gorm:"index;size:24"`
PasswordHash string `json:"-"`
LastLoginAt *time.Time `json:"lastLoginAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type AuthSession struct {
@@ -48,6 +51,7 @@ type OAuthState struct {
}
type EmailVerificationCode struct {
Attempts int `json:"-"`
ID string `json:"id" gorm:"primaryKey;size:36"`
Email string `json:"email" gorm:"index;size:160"`
CodeHash string `json:"-" gorm:"size:64"`
@@ -0,0 +1,69 @@
package model
import (
"gorm.io/gorm"
"time"
)
type SMSChannel struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
Name string `json:"name" gorm:"size:80"`
Provider string `json:"provider" gorm:"size:32;index"`
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
DailyLimit int `json:"dailyLimit"`
SignName string `json:"signName" gorm:"size:80"`
AppID string `json:"appId" gorm:"size:80"`
Credentials string `json:"-"`
TemplatesJSON string `json:"-"`
Version int `json:"version"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// SMSRecord contains no code, template parameters, raw response or full phone.
type SMSRecord struct {
ID string `json:"id" gorm:"primaryKey;size:36"`
ChannelID string `json:"channelId" gorm:"size:36;index"`
ChannelName string `json:"channelName" gorm:"size:80"`
Provider string `json:"provider" gorm:"size:32"`
Purpose string `json:"purpose" gorm:"size:24;index"`
MaskedPhone string `json:"maskedPhone" gorm:"size:32"`
TargetHash string `json:"-" gorm:"size:64;index"`
State string `json:"state" gorm:"size:24;index"`
RequestID string `json:"requestId" gorm:"size:160"`
MessageID string `json:"messageId" gorm:"size:160"`
ErrorCode string `json:"errorCode" gorm:"size:160"`
DurationMS int64 `json:"durationMs"`
CreatedAt time.Time `json:"createdAt" gorm:"index"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Verification tickets are immutable, short-lived and purpose/target bound.
// Only code HMACs and the hash of the high-entropy client ticket are persisted.
type AuthVerification struct {
ID string `gorm:"primaryKey;size:36"`
TokenHash string `gorm:"size:64"`
Purpose string `gorm:"size:24"`
Method string `gorm:"size:24"`
UserID string `gorm:"size:36"`
Email string `gorm:"size:160"`
Phone string `gorm:"size:24"`
EmailHash string `gorm:"size:64"`
PhoneHash string `gorm:"size:64"`
PolicyHash string `gorm:"size:64"`
Ready bool
Attempts int
ExpiresAt time.Time `gorm:"index"`
UsedAt *time.Time
CreatedAt time.Time
}
// Fixed window quotas and per-recipient cooldowns are shared by all instances.
type NotificationQuota struct {
Key string `gorm:"primaryKey;size:180"`
Count int
NextAt time.Time
ExpiresAt time.Time `gorm:"index"`
}