2021-06-10 13:49:10 +02:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2023-12-05 12:12:01 +01:00
|
|
|
zitadel_errs "github.com/zitadel/zitadel/internal/errors"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2021-06-10 13:49:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-08-02 15:24:58 +02:00
|
|
|
InitCodeMessageType = "InitCode"
|
|
|
|
PasswordResetMessageType = "PasswordReset"
|
|
|
|
VerifyEmailMessageType = "VerifyEmail"
|
|
|
|
VerifyPhoneMessageType = "VerifyPhone"
|
2023-08-09 07:49:12 +02:00
|
|
|
VerifySMSOTPMessageType = "VerifySMSOTP"
|
|
|
|
VerifyEmailOTPMessageType = "VerifyEmailOTP"
|
2021-08-02 15:24:58 +02:00
|
|
|
DomainClaimedMessageType = "DomainClaimed"
|
|
|
|
PasswordlessRegistrationMessageType = "PasswordlessRegistration"
|
2023-01-25 09:49:41 +01:00
|
|
|
PasswordChangeMessageType = "PasswordChange"
|
2021-08-02 15:24:58 +02:00
|
|
|
MessageTitle = "Title"
|
|
|
|
MessagePreHeader = "PreHeader"
|
|
|
|
MessageSubject = "Subject"
|
|
|
|
MessageGreeting = "Greeting"
|
|
|
|
MessageText = "Text"
|
|
|
|
MessageButtonText = "ButtonText"
|
|
|
|
MessageFooterText = "Footer"
|
2021-06-10 13:49:10 +02:00
|
|
|
)
|
|
|
|
|
2021-07-13 07:13:39 +02:00
|
|
|
type MessageTexts struct {
|
2021-08-02 15:24:58 +02:00
|
|
|
InitCode CustomMessageText
|
|
|
|
PasswordReset CustomMessageText
|
|
|
|
VerifyEmail CustomMessageText
|
|
|
|
VerifyPhone CustomMessageText
|
|
|
|
DomainClaimed CustomMessageText
|
|
|
|
PasswordlessRegistration CustomMessageText
|
2023-01-25 09:49:41 +01:00
|
|
|
PasswordChange CustomMessageText
|
2021-07-13 07:13:39 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:49:10 +02:00
|
|
|
type CustomMessageText struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
|
|
|
State PolicyState
|
|
|
|
Default bool
|
|
|
|
MessageTextType string
|
|
|
|
Language language.Tag
|
|
|
|
Title string
|
|
|
|
PreHeader string
|
|
|
|
Subject string
|
|
|
|
Greeting string
|
|
|
|
Text string
|
|
|
|
ButtonText string
|
|
|
|
FooterText string
|
|
|
|
}
|
|
|
|
|
2023-12-05 12:12:01 +01:00
|
|
|
func (m *CustomMessageText) IsValid(supportedLanguages []language.Tag) error {
|
|
|
|
if m.MessageTextType == "" {
|
|
|
|
return zitadel_errs.ThrowInvalidArgument(nil, "INSTANCE-kd9fs", "Errors.CustomMessageText.Invalid")
|
|
|
|
}
|
|
|
|
if err := LanguageIsDefined(m.Language); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return LanguagesAreSupported(supportedLanguages, m.Language)
|
2021-06-10 13:49:10 +02:00
|
|
|
}
|
2021-07-13 07:13:39 +02:00
|
|
|
|
2021-08-18 12:58:57 +02:00
|
|
|
func IsMessageTextType(textType string) bool {
|
|
|
|
return textType == InitCodeMessageType ||
|
|
|
|
textType == PasswordResetMessageType ||
|
|
|
|
textType == VerifyEmailMessageType ||
|
|
|
|
textType == VerifyPhoneMessageType ||
|
2023-08-09 07:49:12 +02:00
|
|
|
textType == VerifySMSOTPMessageType ||
|
|
|
|
textType == VerifyEmailOTPMessageType ||
|
2021-08-18 12:58:57 +02:00
|
|
|
textType == DomainClaimedMessageType ||
|
2023-01-25 09:49:41 +01:00
|
|
|
textType == PasswordlessRegistrationMessageType ||
|
|
|
|
textType == PasswordChangeMessageType
|
2021-08-18 12:58:57 +02:00
|
|
|
}
|