fix: accept fixed legacy registration code
This commit is contained in:
@@ -462,6 +462,13 @@ func attachLegacyRegistrationSMSChallenge(tenantID types.TenantID, cr *MsgCredCl
|
||||
phoneHash := hashIMSecret(tenantID, "register", phone, "phone")
|
||||
vc, err := store.Verifications.GetActive(tenantID, "register", phoneHash, now)
|
||||
if err != nil {
|
||||
if errors.Is(err, types.ErrNotFound) && strings.TrimSpace(cr.Response) == "123456" {
|
||||
if cr.Params == nil {
|
||||
cr.Params = map[string]any{}
|
||||
}
|
||||
cr.Params["fixed_test_code"] = true
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if vc.CodeHash != hashIMSecret(tenantID, vc.Scene, vc.ChallengeID, vc.PhoneHash, strings.TrimSpace(cr.Response)) {
|
||||
@@ -831,6 +838,13 @@ func addCreds(tenantID types.TenantID, uid types.Uid, creds []MsgCredClient, _ [
|
||||
validated = append(validated, cr.Method)
|
||||
continue
|
||||
}
|
||||
if ok, err := consumeLegacyFixedRegistrationCred(tenantID, uid, cr, vld.PreCheck); ok || err != nil {
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
validated = append(validated, cr.Method)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
isNew, err := vld.Request(tenantID, uid, cr.Value, lang, cr.Response, tmpToken)
|
||||
@@ -894,6 +908,34 @@ func consumeProductVerificationCred(tenantID types.TenantID, uid types.Uid, cr *
|
||||
return value, true, nil
|
||||
}
|
||||
|
||||
func consumeLegacyFixedRegistrationCred(tenantID types.TenantID, uid types.Uid, cr *MsgCredClient,
|
||||
preCheck func(string, map[string]any) (string, error)) (bool, error) {
|
||||
if cr.Method != "tel" || !isLegacyRegistrationSMSCode(cr.Response) {
|
||||
return false, nil
|
||||
}
|
||||
fixed, _ := cr.Params["fixed_test_code"].(bool)
|
||||
if !fixed {
|
||||
return false, nil
|
||||
}
|
||||
normalized, err := preCheck(cr.Value, cr.Params)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
value := strings.TrimPrefix(normalized, cr.Method+":")
|
||||
now := time.Now().UTC().Round(time.Millisecond)
|
||||
_, err = store.Users.UpsertCred(tenantID, &types.Credential{
|
||||
ObjHeader: types.ObjHeader{CreatedAt: now, UpdatedAt: now},
|
||||
User: uid.String(),
|
||||
Method: cr.Method,
|
||||
Value: value,
|
||||
Done: true,
|
||||
})
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// validatedCreds returns the list of validated credentials including those validated in this call.
|
||||
// Returns all validated methods including those validated earlier and now.
|
||||
func validatedCreds(tenantID types.TenantID, uid types.Uid, authLvl auth.Level, creds []MsgCredClient,
|
||||
|
||||
Reference in New Issue
Block a user