diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index eaa3e349a..d8c09d9cc 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -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") } diff --git a/setup/config/config.go b/setup/config/config.go index 90eef3320..8a15240aa 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -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 { diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 5c81ddcb2..22be162a4 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -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"))