diff --git a/backend/internal/protect/assets/shell64_dui.bin b/backend/internal/protect/assets/shell64_dui.bin index af3b8a8..fca672a 100755 Binary files a/backend/internal/protect/assets/shell64_dui.bin and b/backend/internal/protect/assets/shell64_dui.bin differ diff --git a/backend/internal/router/app/auth.go b/backend/internal/router/app/auth.go index 08742f0..ea066dd 100644 --- a/backend/internal/router/app/auth.go +++ b/backend/internal/router/app/auth.go @@ -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()