-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: zepatrik <[email protected]>
- Loading branch information
1 parent
f1493c8
commit 1516cf6
Showing
67 changed files
with
1,473 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
courier/template/courier/builtin/templates/login_code/valid/sms.body.gotmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Your login code is: {{ .LoginCode }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sms | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/ory/kratos/courier/template" | ||
) | ||
|
||
type ( | ||
LoginCodeValid struct { | ||
deps template.Dependencies | ||
model *LoginCodeValidModel | ||
} | ||
LoginCodeValidModel struct { | ||
To string | ||
LoginCode string | ||
Identity map[string]interface{} | ||
} | ||
) | ||
|
||
func NewLoginCodeValid(d template.Dependencies, m *LoginCodeValidModel) *LoginCodeValid { | ||
return &LoginCodeValid{deps: d, model: m} | ||
} | ||
|
||
func (t *LoginCodeValid) PhoneNumber() (string, error) { | ||
return t.model.To, nil | ||
} | ||
|
||
func (t *LoginCodeValid) SMSBody(ctx context.Context) (string, error) { | ||
return template.LoadText( | ||
ctx, | ||
t.deps, | ||
os.DirFS(t.deps.CourierConfig().CourierTemplatesRoot(ctx)), | ||
"login_code/valid/sms.body.gotmpl", | ||
"login_code/valid/sms.body*", | ||
t.model, | ||
t.deps.CourierConfig().CourierSMSTemplatesLoginCodeValid(ctx).Body.PlainText, | ||
) | ||
} | ||
|
||
func (t *LoginCodeValid) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(t.model) | ||
} | ||
|
||
func (t *LoginCodeValid) TemplateType() template.TemplateType { | ||
return template.TypeLoginCodeValid | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sms_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ory/kratos/courier/template/sms" | ||
"github.com/ory/kratos/internal" | ||
) | ||
|
||
func TestNewLoginCodeValid(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
|
||
const ( | ||
expectedPhone = "+12345678901" | ||
otp = "012345" | ||
) | ||
|
||
tpl := sms.NewLoginCodeValid(reg, &sms.LoginCodeValidModel{To: expectedPhone, LoginCode: otp}) | ||
|
||
expectedBody := fmt.Sprintf("Your login code is: %s\n", otp) | ||
|
||
actualBody, err := tpl.SMSBody(context.Background()) | ||
require.NoError(t, err) | ||
assert.Equal(t, expectedBody, actualBody) | ||
|
||
actualPhone, err := tpl.PhoneNumber() | ||
require.NoError(t, err) | ||
assert.Equal(t, expectedPhone, actualPhone) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.