SendRecordChangeEmail sends a change email confirmation email to the specified auth record.
(app core.App, authRecord *core.Record, newEmail string)
| 202 | |
| 203 | // SendRecordChangeEmail sends a change email confirmation email to the specified auth record. |
| 204 | func SendRecordChangeEmail(app core.App, authRecord *core.Record, newEmail string) error { |
| 205 | token, tokenErr := authRecord.NewEmailChangeToken(newEmail) |
| 206 | if tokenErr != nil { |
| 207 | return tokenErr |
| 208 | } |
| 209 | |
| 210 | mailClient := app.NewMailClient() |
| 211 | |
| 212 | subject, body, err := resolveEmailTemplate(app, authRecord, authRecord.Collection().ConfirmEmailChangeTemplate, map[string]any{ |
| 213 | core.EmailPlaceholderToken: token, |
| 214 | }) |
| 215 | if err != nil { |
| 216 | return err |
| 217 | } |
| 218 | |
| 219 | message := &mailer.Message{ |
| 220 | From: mail.Address{ |
| 221 | Name: app.Settings().Meta.SenderName, |
| 222 | Address: app.Settings().Meta.SenderAddress, |
| 223 | }, |
| 224 | To: []mail.Address{{Address: newEmail}}, |
| 225 | Subject: subject, |
| 226 | HTML: body, |
| 227 | } |
| 228 | |
| 229 | event := new(core.MailerRecordEvent) |
| 230 | event.App = app |
| 231 | event.Mailer = mailClient |
| 232 | event.Message = message |
| 233 | event.Record = authRecord |
| 234 | event.Meta = map[string]any{ |
| 235 | "token": token, |
| 236 | "newEmail": newEmail, |
| 237 | } |
| 238 | |
| 239 | return app.OnMailerRecordEmailChangeSend().Trigger(event, func(e *core.MailerRecordEvent) error { |
| 240 | return e.Mailer.Send(e.Message) |
| 241 | }) |
| 242 | } |
| 243 | |
| 244 | var nonescapeTypes = []string{ |
| 245 | core.FieldTypeAutodate, |
searching dependent graphs…