feat: complete registration invitation and auth redesign

This commit is contained in:
richjohnrambo
2026-08-19 00:30:11 +08:00
parent e063e7879e
commit 219ecadf4c
47 changed files with 9014 additions and 224 deletions
+25
View File
@@ -214,6 +214,31 @@ func (v *validator) ResetSecret(tenantID t.TenantID, phone, scheme, lang string,
return nil
}
// SendCode synchronously delivers a product verification code. Unlike the
// legacy credential flow, it fails when no real SMS provider is configured.
func (v *validator) SendCode(_ t.TenantID, phone, lang, scene, code string) error {
if v.Twilio == nil {
return t.ErrUnsupported
}
var template *textt.Template
if v.langMatcher != nil {
_, idx := i18n.MatchStrings(v.langMatcher, lang)
template = v.universalTempl[idx]
} else if len(v.universalTempl) > 0 {
template = v.universalTempl[0]
}
if template == nil {
return t.ErrInternal
}
content, err := validate.ExecuteTemplate(template, nil, map[string]any{
"Code": code, "HostUrl": v.HostUrl, "Scene": scene,
})
if err != nil {
return err
}
return twilioSend(v.Sender, phone, content[""])
}
// Check checks validity of user's response.
func (v *validator) Check(tenantID t.TenantID, user t.Uid, resp string) (string, error) {
cred, err := store.Users.GetActiveCred(tenantID, user, validatorName)