feat(card): 卡密用户直接用卡密改密码(无需旧密码、无需验证码)
Docker Build / Build and Push Docker Image (push) Successful in 31s
Docker Build / Deploy to Server (push) Successful in 3s

后端:
- POST /app/:key/card-set-password {card_key, password}:卡密即身份,直接重设该主体的登录密码;
  受 card_login_allow_password 开关约束,作废/未激活卡一律 401,写 card_set_password 日志

壳:「找回/绑定」面板一套输入两种用途
- 填了邮箱验证码 → 绑定邮箱(原有流程)
- 只填卡密 + 新密码、验证码留空 → 直接改密码(走 card-set-password)
- 提示行改成「填验证码 = 绑定邮箱找回;不填验证码 = 直接用卡密改密码」

实测:UI 填卡密 + uipass987(验证码留空)→ 库里 hash 从 $2a$10$D3… 变为 $2a$10$Tx…,
用 bind2@test.local + uipass987 登录成功、余额 200 不变;作废卡改密码返回 401。
壳资源 866,304 B,e2e 8 套全过。
This commit is contained in:
Hermes Agent
2026-11-23 11:42:10 +08:00
parent 6016886f48
commit 21e9e6ed6e
2 changed files with 47 additions and 0 deletions
Binary file not shown.
+47
View File
@@ -67,6 +67,7 @@ func SetupAuthUserRoutes(r *gin.RouterGroup) {
r.POST("/send-email-code", handleAppSendEmailCode)
r.POST("/reset-password", handleAppResetPassword)
r.POST("/card-bind", handleAppCardBind)
r.POST("/card-set-password", handleAppCardSetPassword)
}
func handleAppSendEmailCode(c *gin.Context) {
@@ -1053,6 +1054,52 @@ func handleAppCardBind(c *gin.Context) {
})
}
// handleAppCardSetPassword 卡密主体直接用卡密改(设)登录密码,不需要旧密码也不需要验证码。
// 卡密本身就是这主体的钥匙,能出示卡密就等于证明身份。
func handleAppCardSetPassword(c *gin.Context) {
appKey := c.Param("appKey")
var app model.Application
if err := database.DB.Where("app_key = ?", appKey).First(&app).Error; err != nil {
response.Error(c, 404, "应用不存在")
return
}
if !app.CardLoginAllowPassword {
response.Error(c, 400, "该应用未开启卡密用户设置密码")
return
}
var req struct {
CardKey string `json:"card_key" binding:"required"`
Password string `json:"password" binding:"required,min=6"`
}
if err := c.ShouldBindJSON(&req); err != nil {
response.Error(c, 400, "参数错误(密码至少 6 位)")
return
}
subject, _, err := resolveCardOwner(&app, strings.TrimSpace(req.CardKey))
if err != nil {
response.Error(c, 401, "卡密无效或已失效")
return
}
hash, herr := service.HashAppUserPassword(req.Password)
if herr != nil {
response.Error(c, 500, "密码加密失败")
return
}
if err := database.DB.Model(&model.AppUser{}).Where("id = ?", subject.ID).
Update("password", hash).Error; err != nil {
response.Error(c, 500, "设置密码失败")
return
}
service.LogVerification(c, &app.ID, &subject.ID, "card_set_password",
"卡密用户用卡密重设登录密码", "", nil)
response.Success(c, gin.H{"message": "密码已更新,可以用「邮箱/账号 + 新密码」登录"})
}
func checkRiskControl(c *gin.Context, appID uint, deviceID string, username string) (bool, string) {
clientIP := c.ClientIP()