aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/admin/emails.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/admin/emails.go')
-rw-r--r--routers/web/admin/emails.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go
index 2cf4035c6a..f0d8555070 100644
--- a/routers/web/admin/emails.go
+++ b/routers/web/admin/emails.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/context"
+ "code.gitea.io/gitea/services/user"
)
const (
@@ -150,3 +151,32 @@ func ActivateEmail(ctx *context.Context) {
redirect.RawQuery = q.Encode()
ctx.Redirect(redirect.String())
}
+
+// DeleteEmail serves a POST request for delete a user's email
+func DeleteEmail(ctx *context.Context) {
+ u, err := user_model.GetUserByID(ctx, ctx.FormInt64("Uid"))
+ if err != nil || u == nil {
+ ctx.ServerError("GetUserByID", err)
+ return
+ }
+
+ email, err := user_model.GetEmailAddressByID(ctx, u.ID, ctx.FormInt64("id"))
+ if err != nil || email == nil {
+ ctx.ServerError("GetEmailAddressByID", err)
+ return
+ }
+
+ if err := user.DeleteEmailAddresses(ctx, u, []string{email.Email}); err != nil {
+ if user_model.IsErrPrimaryEmailCannotDelete(err) {
+ ctx.Flash.Error(ctx.Tr("admin.emails.delete_primary_email_error"))
+ ctx.JSONRedirect("")
+ return
+ }
+ ctx.ServerError("DeleteEmailAddresses", err)
+ return
+ }
+ log.Trace("Email address deleted: %s %s", u.Name, email.Email)
+
+ ctx.Flash.Success(ctx.Tr("admin.emails.deletion_success"))
+ ctx.JSONRedirect("")
+}