feat: merge registration invite and verification input

This commit is contained in:
richjohnrambo
2026-09-16 14:29:59 +08:00
parent 370e9878ed
commit 7461216c03
8 changed files with 157 additions and 29 deletions
+26 -1
View File
@@ -1073,7 +1073,8 @@ func serveIMVerificationCodeVerify(wrt http.ResponseWriter, req *http.Request) {
return
}
code := strings.TrimSpace(body.Code)
if len(code) != imVerificationCodeLength {
inviteCandidate := isValidIMInviteCode(code)
if len(code) != imVerificationCodeLength && !inviteCandidate {
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "code"})
return
}
@@ -1102,6 +1103,30 @@ func serveIMVerificationCodeVerify(wrt http.ResponseWriter, req *http.Request) {
writeIMError(wrt, req, http.StatusGone, 30030, imReasonChallengeExpired, "challenge expired", nil)
return
}
if inviteCandidate {
if vc.Scene != "register" {
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "code"})
return
}
if err := validateRegistrationInvite(tenant.ID, code, now); err != nil {
nextState := types.VerificationStatePending
if vc.Attempts+1 >= vc.MaxAttempts {
nextState = types.VerificationStateLocked
}
_ = store.Verifications.Fail(tenant.ID, challengeID, nextState)
if nextState == types.VerificationStateLocked {
writeIMError(wrt, req, http.StatusTooManyRequests, 30032, imReasonTooManyAttempts, "too many attempts", nil)
return
}
writeIMError(wrt, req, http.StatusUnauthorized, 30031, imReasonCodeInvalid, "code invalid", nil)
return
}
writeIMSuccess(wrt, req, map[string]any{
"verification_mode": "invite_code",
"invite_accepted": true,
})
return
}
if vc.CodeHash != hashIMSecret(tenant.ID, vc.Scene, vc.ChallengeID, vc.PhoneHash, code) {
nextState := types.VerificationStatePending
if vc.Attempts+1 >= vc.MaxAttempts {