9adafb1354
后台登录框原来预填了 sundynix/sundynix,等于把凭证写在页面上,去掉。 令牌改为 access(2h) + refresh 两段式: - 新表 sundynix_refresh_tokens,只存 sha256,明文只在签发时返回一次 - 有效期:小程序 30 天、后台 7 天 - 新接口 /api/auth/refresh|logout、/api/admin/refresh|logout 安全约定: - 每次续期都轮换刷新令牌,旧的立即作废 - 作废后 60 秒内再到达算并发重试放行,超过则判定泄露、吊销该账号全部会话 - 主动退出与被连坐吊销的令牌不吃宽限期,否则「吊销全部」形同虚设 - 禁用用户时一并吊销刷新令牌,最多 2 小时彻底失去访问 两端请求层都做了单飞续期:并发请求同时 401 只发一次 refresh, 否则刷新令牌会被并发轮换掉互相打架。小程序续期失败回退 wx.login, 登录/续期请求标 noAuthRetry,避免登录失败(同样返回 40100)触发自我套娃。 顺带修掉 vite 代理仍指向 8080 的遗留(端口早已改 9090)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
53 lines
1007 B
Go
53 lines
1007 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/sundynix/pets-be/pkg/idgen"
|
|
)
|
|
|
|
// Base 所有模型的公共字段。主键为雪花算法字符串 ID(非自增)。
|
|
type Base struct {
|
|
ID string `gorm:"primaryKey;size:24" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// BeforeCreate 未显式赋值时自动生成雪花 ID(通过嵌入对所有模型生效)。
|
|
func (b *Base) BeforeCreate(tx *gorm.DB) error {
|
|
if b.ID == "" {
|
|
b.ID = idgen.Next()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// AllModels 需要 AutoMigrate 的模型清单(按依赖顺序)
|
|
func AllModels() []any {
|
|
return []any{
|
|
&User{},
|
|
&Pet{},
|
|
&HealthRecord{},
|
|
&DailyTask{},
|
|
&Plan{},
|
|
&PlanTask{},
|
|
&Reminder{},
|
|
&Post{},
|
|
&Comment{},
|
|
&PostLike{},
|
|
&Article{},
|
|
&AIMessage{},
|
|
&ProMembership{},
|
|
&Admin{},
|
|
&DailyAdvice{},
|
|
&CareTemplate{},
|
|
&CareTemplateItem{},
|
|
&CommunityBotConfig{},
|
|
&File{},
|
|
&Feedback{},
|
|
&Follow{},
|
|
&RefreshToken{},
|
|
}
|
|
}
|