SendRecordAuthAlert sends a new device login alert to the specified auth record.
(app core.App, authRecord *core.Record, info string)
| 13 | |
| 14 | // SendRecordAuthAlert sends a new device login alert to the specified auth record. |
| 15 | func SendRecordAuthAlert(app core.App, authRecord *core.Record, info string) error { |
| 16 | mailClient := app.NewMailClient() |
| 17 | |
| 18 | info = html.EscapeString(info) |
| 19 | |
| 20 | subject, body, err := resolveEmailTemplate(app, authRecord, authRecord.Collection().AuthAlert.EmailTemplate, map[string]any{ |
| 21 | core.EmailPlaceholderAlertInfo: info, |
| 22 | }) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | message := &mailer.Message{ |
| 28 | From: mail.Address{ |
| 29 | Name: app.Settings().Meta.SenderName, |
| 30 | Address: app.Settings().Meta.SenderAddress, |
| 31 | }, |
| 32 | To: []mail.Address{{Address: authRecord.Email()}}, |
| 33 | Subject: subject, |
| 34 | HTML: body, |
| 35 | } |
| 36 | |
| 37 | event := new(core.MailerRecordEvent) |
| 38 | event.App = app |
| 39 | event.Mailer = mailClient |
| 40 | event.Message = message |
| 41 | event.Record = authRecord |
| 42 | event.Meta = map[string]any{ |
| 43 | "info": info, |
| 44 | } |
| 45 | |
| 46 | return app.OnMailerRecordAuthAlertSend().Trigger(event, func(e *core.MailerRecordEvent) error { |
| 47 | return e.Mailer.Send(e.Message) |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | // SendRecordOTP sends OTP email to the specified auth record. |
| 52 | // |
searching dependent graphs…