summaryrefslogtreecommitdiffstats
path: root/routers/admin
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-21 06:15:58 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-21 06:15:58 -0400
commit30618b271aab40d29a6d34cb4e06c8d28fa74d18 (patch)
tree975ea9f2770c20f7b8b8f5ca2fffaf9deb95b0a5 /routers/admin
parente67653cf13857f671de9bf6279453f99cdd60d11 (diff)
downloadgitea-30618b271aab40d29a6d34cb4e06c8d28fa74d18.tar.gz
gitea-30618b271aab40d29a6d34cb4e06c8d28fa74d18.zip
Add admin edit user
Diffstat (limited to 'routers/admin')
-rw-r--r--routers/admin/user.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/routers/admin/user.go b/routers/admin/user.go
index 9dcc1499e3..47eec5c914 100644
--- a/routers/admin/user.go
+++ b/routers/admin/user.go
@@ -7,8 +7,11 @@ package admin
import (
"strings"
+ "github.com/codegangsta/martini"
+
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
+ "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
)
@@ -61,3 +64,44 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
ctx.Redirect("/admin/users")
}
+
+func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) {
+ ctx.Data["Title"] = "Edit Account"
+
+ 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 ctx.Req.Method == "GET" {
+ ctx.Data["User"] = u
+ ctx.HTML(200, "admin/users/edit")
+ return
+ }
+
+ u.Email = form.Email
+ u.Website = form.Website
+ u.Location = form.Location
+ u.Avatar = base.EncodeMd5(form.Avatar)
+ u.AvatarEmail = form.Avatar
+ u.IsActive = form.Active == "on"
+ u.IsAdmin = form.Admin == "on"
+ if err := models.UpdateUser(u); err != nil {
+ ctx.Handle(200, "admin.user.EditUser", err)
+ return
+ }
+
+ ctx.Data["IsSuccess"] = true
+ ctx.Data["User"] = u
+ ctx.HTML(200, "admin/users/edit")
+
+ log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI,
+ ctx.User.LowerName, ctx.User.LowerName)
+}