snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
69
courier/sms_templates.go
Normal file
69
courier/sms_templates.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package courier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/ory/kratos/courier/template"
|
||||
"github.com/ory/kratos/courier/template/sms"
|
||||
)
|
||||
|
||||
type SMSTemplate interface {
|
||||
Template
|
||||
SMSBody(context.Context) (string, error)
|
||||
PhoneNumber() (string, error)
|
||||
}
|
||||
|
||||
func NewSMSTemplateFromMessage(d template.Dependencies, m Message) (SMSTemplate, error) {
|
||||
switch m.TemplateType {
|
||||
case template.TypeVerificationCodeValid:
|
||||
var t sms.VerificationCodeValidModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewVerificationCodeValid(d, &t), nil
|
||||
case template.TypeRecoveryCodeValid:
|
||||
var t sms.RecoveryCodeValidModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewRecoveryCodeValid(d, &t), nil
|
||||
case template.TypeTestStub:
|
||||
var t sms.TestStubModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewTestStub(&t), nil
|
||||
case template.TypeLoginCodeValid:
|
||||
var t sms.LoginCodeValidModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewLoginCodeValid(d, &t), nil
|
||||
case template.TypeRegistrationCodeValid:
|
||||
var t sms.RegistrationCodeValidModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewRegistrationCodeValid(d, &t), nil
|
||||
case template.TypeVerifiableAddressChanged:
|
||||
var t sms.VerifiableAddressChangedModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewVerifiableAddressChanged(d, &t), nil
|
||||
case template.TypeAuthenticatorKeyAdded:
|
||||
var t sms.AuthenticatorKeyAddedModel
|
||||
if err := json.Unmarshal(m.TemplateData, &t); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sms.NewAuthenticatorKeyAdded(d, &t), nil
|
||||
default:
|
||||
return nil, errors.Errorf("received unexpected message template type: %s", m.TemplateType)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user