( app core.App, authRecord *core.Record, emailTemplate core.EmailTemplate, placeholders map[string]any, )
| 249 | } |
| 250 | |
| 251 | func resolveEmailTemplate( |
| 252 | app core.App, |
| 253 | authRecord *core.Record, |
| 254 | emailTemplate core.EmailTemplate, |
| 255 | placeholders map[string]any, |
| 256 | ) (subject string, body string, err error) { |
| 257 | if placeholders == nil { |
| 258 | placeholders = map[string]any{} |
| 259 | } |
| 260 | |
| 261 | // register default system placeholders |
| 262 | if _, ok := placeholders[core.EmailPlaceholderAppName]; !ok { |
| 263 | placeholders[core.EmailPlaceholderAppName] = app.Settings().Meta.AppName |
| 264 | } |
| 265 | if _, ok := placeholders[core.EmailPlaceholderAppURL]; !ok { |
| 266 | placeholders[core.EmailPlaceholderAppURL] = app.Settings().Meta.AppURL |
| 267 | } |
| 268 | |
| 269 | // register default auth record placeholders |
| 270 | for _, field := range authRecord.Collection().Fields { |
| 271 | if field.GetHidden() { |
| 272 | continue |
| 273 | } |
| 274 | |
| 275 | fieldPlacehodler := "{RECORD:" + field.GetName() + "}" |
| 276 | if _, ok := placeholders[fieldPlacehodler]; !ok { |
| 277 | val := authRecord.GetString(field.GetName()) |
| 278 | |
| 279 | // note: the escaping is not strictly necessary but for just in case |
| 280 | // the user decide to store and render the email as plain html |
| 281 | if !slices.Contains(nonescapeTypes, field.Type()) { |
| 282 | val = html.EscapeString(val) |
| 283 | } |
| 284 | |
| 285 | placeholders[fieldPlacehodler] = val |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | subject, rawBody := emailTemplate.Resolve(placeholders) |
| 290 | |
| 291 | params := struct { |
| 292 | HTMLContent template.HTML |
| 293 | }{ |
| 294 | HTMLContent: template.HTML(rawBody), |
| 295 | } |
| 296 | |
| 297 | body, err = resolveTemplateContent(params, templates.Layout, templates.HTMLBody) |
| 298 | if err != nil { |
| 299 | return "", "", err |
| 300 | } |
| 301 | |
| 302 | return subject, body, nil |
| 303 | } |
no test coverage detected
searching dependent graphs…