diff --git a/config/config.go b/config/config.go index 493c6b6..cf546a3 100644 --- a/config/config.go +++ b/config/config.go @@ -47,6 +47,7 @@ func (*AmCLI) Version() string { // AmConfig holds the configuration of the application as read from YAML. type AmConfig struct { Site struct { + BaseURL string `yaml:"baseURL"` Title string `yaml:"title"` TopRefresh int `yaml:"topRefresh"` LoginCookieName string `yaml:"loginCookieName"` @@ -129,6 +130,7 @@ func overlayInt(loaded int, defaulted int) int { * defaults - Points to the default configuration structure. */ func overlayConfig(dest *AmConfig, loaded *AmConfig, defaults *AmConfig) { + dest.Site.BaseURL = overlayString(loaded.Site.BaseURL, defaults.Site.BaseURL) dest.Site.Title = overlayString(loaded.Site.Title, defaults.Site.Title) dest.Site.TopRefresh = overlayInt(loaded.Site.TopRefresh, defaults.Site.TopRefresh) dest.Site.LoginCookieName = overlayString(loaded.Site.LoginCookieName, defaults.Site.LoginCookieName) diff --git a/config/default.yaml b/config/default.yaml index 6df8ca8..8f38d70 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -7,6 +7,7 @@ # file, You can obtain one at https://mozilla.org/MPL/2.0/. # site: + baseURL: "http://localhost:1323" title: "Amsterdam Web Communities System" topRefresh: 300 loginCookieName: AmsterdamAuth diff --git a/database/contactinfo.go b/database/contactinfo.go index d651f9b..12b6f58 100644 --- a/database/contactinfo.go +++ b/database/contactinfo.go @@ -24,7 +24,7 @@ type ContactInfo struct { ContactId int32 `db:"contactid"` GivenName string `db:"given_name"` FamilyName string `db:"family_name"` - MiddleInit string `db:"middle_init"` + MiddleInit *string `db:"middle_init"` Prefix *string `db:"prefix"` Suffix *string `db:"suffix"` Company *string `db:"company"` diff --git a/email/message.go b/email/message.go index 9ddb6c5..95b87a6 100644 --- a/email/message.go +++ b/email/message.go @@ -123,7 +123,7 @@ func AmNewEmailMessage(sender int32, ip string) Message { rc := freeMessages.Get() if rc == nil { rc = &amMessage{to: make([]string, 0), cc: make([]string, 0), bcc: make([]string, 0), - headers: make(map[string]string)} + headers: make(map[string]string), vars: make(jet.VarMap)} } rc.uid = sender rc.ip = ip diff --git a/email/sender.go b/email/sender.go index 32930f0..ec3bb56 100644 --- a/email/sender.go +++ b/email/sender.go @@ -68,16 +68,22 @@ func formatMessage(m *amMessage) ([]byte, error) { hdrs := make(map[string]string) maps.Copy(hdrs, m.headers) hdrs["From"] = m.from - hdrs["To"] = strings.Join(m.to, ", ") - hdrs["Cc"] = strings.Join(m.cc, ", ") - hdrs["Bcc"] = strings.Join(m.bcc, ", ") + if len(m.to) > 0 { + hdrs["To"] = strings.Join(m.to, ", ") + } + if len(m.cc) > 0 { + hdrs["Cc"] = strings.Join(m.cc, ", ") + } + if len(m.bcc) > 0 { + hdrs["Bcc"] = strings.Join(m.bcc, ", ") + } hdrs["Subject"] = m.subject hdrs["Content-Type"] = "text/plain; charset=UTF-8" me, _ := os.Hostname() hdrs["X-Amsterdam-Server-Info"] = fmt.Sprintf("%s (Amsterdam/%s)", me, config.AMSTERDAM_VERSION) hdrs["X-Amsterdam-Sender-Info"] = fmt.Sprintf("uid %d, name %s, ip [%s]", m.uid, user.Username, m.ip) for i, v := range disclaimerLines { - hdrs[fmt.Sprintf("X-Disclaimer-%d", i)] = v + hdrs[fmt.Sprintf("X-Disclaimer-%d", i+1)] = v } // Sort the header keys tro make for a better presentation. @@ -208,6 +214,9 @@ func SetupMailSender() func() { embedfs.NewLoader("templates/", emailTemplates), jet.DevelopmentMode(true), ) + emailRenderer.AddGlobal("AmsterdamVersion", config.AMSTERDAM_VERSION) + emailRenderer.AddGlobal("AmsterdamCopyright", config.AMSTERDAM_COPYRIGHT) + emailRenderer.AddGlobal("GlobalConfig", config.GlobalConfig) // Start the recycler. messageRecycleBin = make(chan *amMessage, 16) diff --git a/email/templates/pass_remind.jet b/email/templates/pass_remind.jet index d83bfa4..5ecb4b0 100644 --- a/email/templates/pass_remind.jet +++ b/email/templates/pass_remind.jet @@ -7,7 +7,7 @@ If this reminder is not sufficient for you to remember what your password is, then the system can change your password for you. To do so, please visit the following URL: -http://example.com/passrecovery/{{ change_uid }}/{{ change_auth }} +{{ GlobalConfig.Site.BaseURL }}/passrecovery/{{ change_uid }}/{{ change_auth }} Your password will be changed and a new password will be E-mailed to you at this address. diff --git a/login.go b/login.go index 60dd281..22040e0 100644 --- a/login.go +++ b/login.go @@ -369,10 +369,11 @@ func NewAccount(ctxt ui.AmContext) (string, any, error) { ci := database.AmNewUserContactInfo(user.Uid) ci.Prefix = dlg.Field("prefix").ValPtr() ci.GivenName = dlg.Field("first").Value - ci.MiddleInit = dlg.Field("mid").Value - if ci.MiddleInit == "" { - ci.MiddleInit = " " + mid := dlg.Field("mid").Value + if mid == "" { + mid = " " } + ci.MiddleInit = &mid ci.FamilyName = dlg.Field("last").Value ci.Suffix = dlg.Field("suffix").ValPtr() ci.Locality = dlg.Field("loc").ValPtr()