SendRecordVerification sends a verification request email to the specified auth record.
(app core.App, authRecord *core.Record)
| 164 | |
| 165 | // SendRecordVerification sends a verification request email to the specified auth record. |
| 166 | func SendRecordVerification(app core.App, authRecord *core.Record) error { |
| 167 | token, tokenErr := authRecord.NewVerificationToken() |
| 168 | if tokenErr != nil { |
| 169 | return tokenErr |
| 170 | } |
| 171 | |
| 172 | mailClient := app.NewMailClient() |
| 173 | |
| 174 | subject, body, err := resolveEmailTemplate(app, authRecord, authRecord.Collection().VerificationTemplate, map[string]any{ |
| 175 | core.EmailPlaceholderToken: token, |
| 176 | }) |
| 177 | if err != nil { |
| 178 | return err |
| 179 | } |
| 180 | |
| 181 | message := &mailer.Message{ |
| 182 | From: mail.Address{ |
| 183 | Name: app.Settings().Meta.SenderName, |
| 184 | Address: app.Settings().Meta.SenderAddress, |
| 185 | }, |
| 186 | To: []mail.Address{{Address: authRecord.Email()}}, |
| 187 | Subject: subject, |
| 188 | HTML: body, |
| 189 | } |
| 190 | |
| 191 | event := new(core.MailerRecordEvent) |
| 192 | event.App = app |
| 193 | event.Mailer = mailClient |
| 194 | event.Message = message |
| 195 | event.Record = authRecord |
| 196 | event.Meta = map[string]any{"token": token} |
| 197 | |
| 198 | return app.OnMailerRecordVerificationSend().Trigger(event, func(e *core.MailerRecordEvent) error { |
| 199 | return e.Mailer.Send(e.Message) |
| 200 | }) |
| 201 | } |
| 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 { |
searching dependent graphs…