aboutsummaryrefslogtreecommitdiffstats
path: root/routers/admin/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/admin/user.go')
-rw-r--r--routers/admin/user.go66
1 files changed, 39 insertions, 27 deletions
diff --git a/routers/admin/user.go b/routers/admin/user.go
index 9f043507d1..fee692202e 100644
--- a/routers/admin/user.go
+++ b/routers/admin/user.go
@@ -16,14 +16,15 @@ import (
"github.com/gogits/gogs/modules/middleware"
)
-func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
+func NewUser(ctx *middleware.Context) {
ctx.Data["Title"] = "New Account"
ctx.Data["PageIsUsers"] = true
+ ctx.HTML(200, "admin/users/new")
+}
- if ctx.Req.Method == "GET" {
- ctx.HTML(200, "admin/users/new")
- return
- }
+func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
+ ctx.Data["Title"] = "New Account"
+ ctx.Data["PageIsUsers"] = true
if form.Password != form.RetypePasswd {
ctx.Data["HasError"] = true
@@ -55,7 +56,7 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
case models.ErrUserNameIllegal:
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form)
default:
- ctx.Handle(200, "admin.user.NewUser", err)
+ ctx.Handle(500, "admin.user.NewUser", err)
}
return
}
@@ -66,25 +67,39 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) {
ctx.Redirect("/admin/users")
}
-func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) {
+func EditUser(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)
+ ctx.Handle(404, "admin.user.EditUser", err)
return
}
u, err := models.GetUserById(int64(uid))
if err != nil {
- ctx.Handle(200, "admin.user.EditUser", err)
+ ctx.Handle(500, "admin.user.EditUser", err)
return
}
- if ctx.Req.Method == "GET" {
- ctx.Data["User"] = u
- ctx.HTML(200, "admin/users/edit")
+ ctx.Data["User"] = u
+ ctx.HTML(200, "admin/users/edit")
+}
+
+func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) {
+ ctx.Data["Title"] = "Edit Account"
+ ctx.Data["PageIsUsers"] = true
+
+ uid, err := base.StrTo(params["userid"]).Int()
+ if err != nil {
+ ctx.Handle(404, "admin.user.EditUser", err)
+ return
+ }
+
+ u, err := models.GetUserById(int64(uid))
+ if err != nil {
+ ctx.Handle(500, "admin.user.EditUser", err)
return
}
@@ -96,47 +111,44 @@ func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEdi
u.IsActive = form.Active == "on"
u.IsAdmin = form.Admin == "on"
if err := models.UpdateUser(u); err != nil {
- ctx.Handle(200, "admin.user.EditUser", err)
+ ctx.Handle(500, "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)
+
+ ctx.Data["User"] = u
+ ctx.Flash.Success("Account profile has been successfully updated.")
+ ctx.Redirect("/admin/users/" + params["userid"])
}
func DeleteUser(ctx *middleware.Context, params martini.Params) {
- ctx.Data["Title"] = "Edit Account"
+ ctx.Data["Title"] = "Delete Account"
ctx.Data["PageIsUsers"] = true
+ log.Info("delete")
uid, err := base.StrTo(params["userid"]).Int()
if err != nil {
- ctx.Handle(200, "admin.user.EditUser", err)
+ ctx.Handle(404, "admin.user.EditUser", err)
return
}
u, err := models.GetUserById(int64(uid))
if err != nil {
- ctx.Handle(200, "admin.user.EditUser", err)
+ ctx.Handle(500, "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")
+ ctx.Flash.Error("This account still has ownership of repository, owner has to delete or transfer them first.")
+ ctx.Redirect("/admin/users/" + params["userid"])
default:
- ctx.Handle(200, "admin.user.DeleteUser", err)
+ ctx.Handle(500, "admin.user.DeleteUser", err)
}
return
}
-
log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI,
ctx.User.LowerName, ctx.User.LowerName)