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