Load templates into one variable

This commit is contained in:
Till Faelligen 2022-02-21 14:27:13 +01:00
parent fb95331aa2
commit 219a15c4c3
3 changed files with 8 additions and 7 deletions

View file

@ -134,7 +134,7 @@ func checkConsent(ctx context.Context, userID string, userAPI userapi.UserIntern
}{
ConsentURL: uri,
}
if err = userConsentCfg.BlockEventsTemplate.ExecuteTemplate(msg, "blockEventsError", c); err != nil {
if err = userConsentCfg.TextTemplates.ExecuteTemplate(msg, "blockEventsError", c); err != nil {
logrus.Infof("error consent message: %+v", err)
return jsonerror.Unknown("unable to get consent URL")
}

View file

@ -288,7 +288,7 @@ func (config *Dendrite) Derive() error {
// TODO: Add email auth type
// TODO: Add MSISDN auth type
if config.Global.UserConsentOptions.RequireAtRegistration {
if config.Global.UserConsentOptions.Enabled && config.Global.UserConsentOptions.RequireAtRegistration {
uri := config.Global.BaseURL + "/_matrix/consent?v=" + config.Global.UserConsentOptions.Version
config.Derived.Registration.Params[authtypes.LoginTypeTerms] = Terms{
Policies: Policies{
@ -314,7 +314,7 @@ func (config *Dendrite) Derive() error {
// prepend each flow with LoginTypeTerms or LoginTypeRecaptcha
for i, flow := range config.Derived.Registration.Flows {
if config.Global.UserConsentOptions.RequireAtRegistration {
if config.Global.UserConsentOptions.Enabled && config.Global.UserConsentOptions.RequireAtRegistration {
flow.Stages = append([]authtypes.LoginType{authtypes.LoginTypeTerms}, flow.Stages...)
}
if config.ClientAPI.RecaptchaEnabled {

View file

@ -266,9 +266,9 @@ type UserConsentOptions struct {
// The error message to display if the user hasn't given their consent yet
BlockEventsError string `yaml:"block_events_error"`
// All loaded templates
Templates *template.Template `yaml:"-"`
BlockEventsTemplate *textTemplate.Template `yaml:"-"`
//
Templates *template.Template `yaml:"-"`
TextTemplates *textTemplate.Template `yaml:"-"`
// The BaseURL, used for building the consent URL
BaseURL string `yaml:"-"`
}
@ -298,7 +298,8 @@ func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool)
return
}
c.BlockEventsTemplate = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError))
c.TextTemplates = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError))
c.TextTemplates = textTemplate.Must(c.TextTemplates.New("serverNoticeTemplate").Parse(c.ServerNoticeContent.Body))
// Read all defined *.gohtml templates
t, err := template.ParseGlob(filepath.Join(p, "*.gohtml"))