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, 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) logrus.Infof("error consent message: %+v", err)
return jsonerror.Unknown("unable to get consent URL") 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 email auth type
// TODO: Add MSISDN 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 uri := config.Global.BaseURL + "/_matrix/consent?v=" + config.Global.UserConsentOptions.Version
config.Derived.Registration.Params[authtypes.LoginTypeTerms] = Terms{ config.Derived.Registration.Params[authtypes.LoginTypeTerms] = Terms{
Policies: Policies{ Policies: Policies{
@ -314,7 +314,7 @@ func (config *Dendrite) Derive() error {
// prepend each flow with LoginTypeTerms or LoginTypeRecaptcha // prepend each flow with LoginTypeTerms or LoginTypeRecaptcha
for i, flow := range config.Derived.Registration.Flows { 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...) flow.Stages = append([]authtypes.LoginType{authtypes.LoginTypeTerms}, flow.Stages...)
} }
if config.ClientAPI.RecaptchaEnabled { 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 // The error message to display if the user hasn't given their consent yet
BlockEventsError string `yaml:"block_events_error"` BlockEventsError string `yaml:"block_events_error"`
// All loaded templates // All loaded templates
Templates *template.Template `yaml:"-"` Templates *template.Template `yaml:"-"`
BlockEventsTemplate *textTemplate.Template `yaml:"-"` TextTemplates *textTemplate.Template `yaml:"-"`
// // The BaseURL, used for building the consent URL
BaseURL string `yaml:"-"` BaseURL string `yaml:"-"`
} }
@ -298,7 +298,8 @@ func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool)
return 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 // Read all defined *.gohtml templates
t, err := template.ParseGlob(filepath.Join(p, "*.gohtml")) t, err := template.ParseGlob(filepath.Join(p, "*.gohtml"))