(tx *storage.Connection, u *models.User, mailer mailer.Mailer, email string, referrerURL string)
| 56 | } |
| 57 | |
| 58 | func (a *API) sendEmailChange(tx *storage.Connection, u *models.User, mailer mailer.Mailer, email string, referrerURL string) error { |
| 59 | oldToken := u.EmailChangeToken |
| 60 | oldEmail := u.EmailChange |
| 61 | u.EmailChangeToken = crypto.SecureToken() |
| 62 | u.EmailChange = email |
| 63 | now := time.Now() |
| 64 | if err := mailer.EmailChangeMail(u, referrerURL); err != nil { |
| 65 | u.EmailChangeToken = oldToken |
| 66 | u.EmailChange = oldEmail |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | u.EmailChangeSentAt = &now |
| 71 | return errors.Wrap(tx.UpdateOnly(u, "email_change_token", "email_change", "email_change_sent_at"), "Database error updating user for email change") |
| 72 | } |
| 73 | |
| 74 | func (a *API) validateEmail(ctx context.Context, email string) error { |
| 75 | if email == "" { |
no test coverage detected