fixed up password reminder E-mail generation (and E-mail generation in general)

This commit is contained in:
2025-10-08 14:33:45 -06:00
parent e657e13509
commit 05dc2aa448
7 changed files with 23 additions and 10 deletions
+2
View File
@@ -47,6 +47,7 @@ func (*AmCLI) Version() string {
// AmConfig holds the configuration of the application as read from YAML. // AmConfig holds the configuration of the application as read from YAML.
type AmConfig struct { type AmConfig struct {
Site struct { Site struct {
BaseURL string `yaml:"baseURL"`
Title string `yaml:"title"` Title string `yaml:"title"`
TopRefresh int `yaml:"topRefresh"` TopRefresh int `yaml:"topRefresh"`
LoginCookieName string `yaml:"loginCookieName"` LoginCookieName string `yaml:"loginCookieName"`
@@ -129,6 +130,7 @@ func overlayInt(loaded int, defaulted int) int {
* defaults - Points to the default configuration structure. * defaults - Points to the default configuration structure.
*/ */
func overlayConfig(dest *AmConfig, loaded *AmConfig, defaults *AmConfig) { 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.Title = overlayString(loaded.Site.Title, defaults.Site.Title)
dest.Site.TopRefresh = overlayInt(loaded.Site.TopRefresh, defaults.Site.TopRefresh) dest.Site.TopRefresh = overlayInt(loaded.Site.TopRefresh, defaults.Site.TopRefresh)
dest.Site.LoginCookieName = overlayString(loaded.Site.LoginCookieName, defaults.Site.LoginCookieName) dest.Site.LoginCookieName = overlayString(loaded.Site.LoginCookieName, defaults.Site.LoginCookieName)
+1
View File
@@ -7,6 +7,7 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
# #
site: site:
baseURL: "http://localhost:1323"
title: "Amsterdam Web Communities System" title: "Amsterdam Web Communities System"
topRefresh: 300 topRefresh: 300
loginCookieName: AmsterdamAuth loginCookieName: AmsterdamAuth
+1 -1
View File
@@ -24,7 +24,7 @@ type ContactInfo struct {
ContactId int32 `db:"contactid"` ContactId int32 `db:"contactid"`
GivenName string `db:"given_name"` GivenName string `db:"given_name"`
FamilyName string `db:"family_name"` FamilyName string `db:"family_name"`
MiddleInit string `db:"middle_init"` MiddleInit *string `db:"middle_init"`
Prefix *string `db:"prefix"` Prefix *string `db:"prefix"`
Suffix *string `db:"suffix"` Suffix *string `db:"suffix"`
Company *string `db:"company"` Company *string `db:"company"`
+1 -1
View File
@@ -123,7 +123,7 @@ func AmNewEmailMessage(sender int32, ip string) Message {
rc := freeMessages.Get() rc := freeMessages.Get()
if rc == nil { if rc == nil {
rc = &amMessage{to: make([]string, 0), cc: make([]string, 0), bcc: make([]string, 0), 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.uid = sender
rc.ip = ip rc.ip = ip
+10 -1
View File
@@ -68,16 +68,22 @@ func formatMessage(m *amMessage) ([]byte, error) {
hdrs := make(map[string]string) hdrs := make(map[string]string)
maps.Copy(hdrs, m.headers) maps.Copy(hdrs, m.headers)
hdrs["From"] = m.from hdrs["From"] = m.from
if len(m.to) > 0 {
hdrs["To"] = strings.Join(m.to, ", ") hdrs["To"] = strings.Join(m.to, ", ")
}
if len(m.cc) > 0 {
hdrs["Cc"] = strings.Join(m.cc, ", ") hdrs["Cc"] = strings.Join(m.cc, ", ")
}
if len(m.bcc) > 0 {
hdrs["Bcc"] = strings.Join(m.bcc, ", ") hdrs["Bcc"] = strings.Join(m.bcc, ", ")
}
hdrs["Subject"] = m.subject hdrs["Subject"] = m.subject
hdrs["Content-Type"] = "text/plain; charset=UTF-8" hdrs["Content-Type"] = "text/plain; charset=UTF-8"
me, _ := os.Hostname() me, _ := os.Hostname()
hdrs["X-Amsterdam-Server-Info"] = fmt.Sprintf("%s (Amsterdam/%s)", me, config.AMSTERDAM_VERSION) 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) hdrs["X-Amsterdam-Sender-Info"] = fmt.Sprintf("uid %d, name %s, ip [%s]", m.uid, user.Username, m.ip)
for i, v := range disclaimerLines { 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. // Sort the header keys tro make for a better presentation.
@@ -208,6 +214,9 @@ func SetupMailSender() func() {
embedfs.NewLoader("templates/", emailTemplates), embedfs.NewLoader("templates/", emailTemplates),
jet.DevelopmentMode(true), jet.DevelopmentMode(true),
) )
emailRenderer.AddGlobal("AmsterdamVersion", config.AMSTERDAM_VERSION)
emailRenderer.AddGlobal("AmsterdamCopyright", config.AMSTERDAM_COPYRIGHT)
emailRenderer.AddGlobal("GlobalConfig", config.GlobalConfig)
// Start the recycler. // Start the recycler.
messageRecycleBin = make(chan *amMessage, 16) messageRecycleBin = make(chan *amMessage, 16)
+1 -1
View File
@@ -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 then the system can change your password for you. To do so, please visit
the following URL: 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 Your password will be changed and a new password will be E-mailed to you
at this address. at this address.
+4 -3
View File
@@ -369,10 +369,11 @@ func NewAccount(ctxt ui.AmContext) (string, any, error) {
ci := database.AmNewUserContactInfo(user.Uid) ci := database.AmNewUserContactInfo(user.Uid)
ci.Prefix = dlg.Field("prefix").ValPtr() ci.Prefix = dlg.Field("prefix").ValPtr()
ci.GivenName = dlg.Field("first").Value ci.GivenName = dlg.Field("first").Value
ci.MiddleInit = dlg.Field("mid").Value mid := dlg.Field("mid").Value
if ci.MiddleInit == "" { if mid == "" {
ci.MiddleInit = " " mid = " "
} }
ci.MiddleInit = &mid
ci.FamilyName = dlg.Field("last").Value ci.FamilyName = dlg.Field("last").Value
ci.Suffix = dlg.Field("suffix").ValPtr() ci.Suffix = dlg.Field("suffix").ValPtr()
ci.Locality = dlg.Field("loc").ValPtr() ci.Locality = dlg.Field("loc").ValPtr()