diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-22 06:20:00 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-22 06:20:00 -0400 |
commit | 76cd448e7925997b60a54e8d9431ffd0826cc24e (patch) | |
tree | 3c99d9a07e579559ee0ec49bcb355ce893b40f5f /routers/admin/user.go | |
parent | 19104f156fd91b7d2cdc84b86dd27e6dcfa11416 (diff) | |
download | gitea-76cd448e7925997b60a54e8d9431ffd0826cc24e.tar.gz gitea-76cd448e7925997b60a54e8d9431ffd0826cc24e.zip |
Add admin delete user
Diffstat (limited to 'routers/admin/user.go')
-rw-r--r-- | routers/admin/user.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/routers/admin/user.go b/routers/admin/user.go index d6f8523218..fa27d11664 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -107,3 +107,38 @@ func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEdi log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) } + +func DeleteUser(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Edit Account" + ctx.Data["PageIsUsers"] = true + + uid, err := base.StrTo(params["userid"]).Int() + if err != nil { + ctx.Handle(200, "admin.user.EditUser", err) + return + } + + u, err := models.GetUserById(int64(uid)) + if err != nil { + ctx.Handle(200, "admin.user.EditUser", err) + return + } + + if err = models.DeleteUser(u); err != nil { + ctx.Data["HasError"] = true + switch err { + case models.ErrUserOwnRepos: + ctx.Data["ErrorMsg"] = "This account still has ownership of repository, owner has to delete or transfer them first." + ctx.Data["User"] = u + ctx.HTML(200, "admin/users/edit") + default: + ctx.Handle(200, "admin.user.DeleteUser", err) + } + return + } + + log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, ctx.User.LowerName) + + ctx.Redirect("/admin/users", 302) +} |