(c *context.Context, f form.AddEmail)
| 241 | } |
| 242 | |
| 243 | func SettingsEmailPost(c *context.Context, f form.AddEmail) { |
| 244 | c.Title("settings.emails") |
| 245 | c.PageIs("SettingsEmails") |
| 246 | |
| 247 | if c.Query("_method") == "PRIMARY" { |
| 248 | err := database.Handle.Users().MarkEmailPrimary(c.Req.Context(), c.User.ID, c.Query("email")) |
| 249 | if err != nil { |
| 250 | c.Errorf(err, "make email primary") |
| 251 | return |
| 252 | } |
| 253 | |
| 254 | c.RedirectSubpath("/user/settings/email") |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | // Add Email address. |
| 259 | emails, err := database.Handle.Users().ListEmails(c.Req.Context(), c.User.ID) |
| 260 | if err != nil { |
| 261 | c.Errorf(err, "get email addresses") |
| 262 | return |
| 263 | } |
| 264 | c.Data["Emails"] = emails |
| 265 | |
| 266 | if c.HasError() { |
| 267 | c.HTML(http.StatusBadRequest, tmplUserSettingsEmail) |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | err = database.Handle.Users().AddEmail(c.Req.Context(), c.User.ID, f.Email, !conf.Auth.RequireEmailConfirmation) |
| 272 | if err != nil { |
| 273 | if database.IsErrEmailAlreadyUsed(err) { |
| 274 | c.RenderWithErr(c.Tr("form.email_been_used"), http.StatusUnprocessableEntity, tmplUserSettingsEmail, &f) |
| 275 | } else { |
| 276 | c.Errorf(err, "add email address") |
| 277 | } |
| 278 | return |
| 279 | } |
| 280 | |
| 281 | // Send confirmation email |
| 282 | if conf.Auth.RequireEmailConfirmation { |
| 283 | email.SendActivateEmailMail(c.Context, database.NewMailerUser(c.User), f.Email) |
| 284 | |
| 285 | if err := c.Cache.Put("MailResendLimit_"+c.User.LowerName, c.User.LowerName, 180); err != nil { |
| 286 | log.Error("Set cache 'MailResendLimit' failed: %v", err) |
| 287 | } |
| 288 | c.Flash.Info(c.Tr("settings.add_email_confirmation_sent", f.Email, conf.Auth.ActivateCodeLives/60)) |
| 289 | } else { |
| 290 | c.Flash.Success(c.Tr("settings.add_email_success")) |
| 291 | } |
| 292 | |
| 293 | c.RedirectSubpath("/user/settings/email") |
| 294 | } |
| 295 | |
| 296 | func DeleteEmail(c *context.Context) { |
| 297 | email := c.Query("id") // The "id" here is the actual email address |
nothing calls this directly
no test coverage detected