diff --git a/pages/index.go b/pages/index.go index f3a3a28c..78876360 100644 --- a/pages/index.go +++ b/pages/index.go @@ -203,6 +203,7 @@ func Configure(app *aero.Application) { l.Page("/user/:nick/animelist/anime/:id", animelistitem.Get) l.Page("/user/:nick/recommended/anime", recommended.Anime) l.Page("/user/:nick/notifications", notifications.ByUser) + l.Page("/user/:nick/edit", user.Edit) // Anime list l.Page("/user/:nick/animelist/watching", animelist.FilterByStatus(arn.AnimeListStatusWatching)) diff --git a/pages/user/edit.go b/pages/user/edit.go new file mode 100644 index 00000000..988bb31a --- /dev/null +++ b/pages/user/edit.go @@ -0,0 +1,28 @@ +package user + +import ( + "net/http" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/utils" + "github.com/animenotifier/notify.moe/utils/editform" +) + +// Edit user. +func Edit(ctx *aero.Context) string { + nick := ctx.Get("nick") + user := utils.GetUser(ctx) + + if user == nil || user.Role != "admin" { + return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this user", nil) + } + + viewUser, err := arn.GetUserByNick(nick) + + if err != nil { + return ctx.Error(http.StatusNotFound, "User not found", err) + } + + return ctx.HTML(editform.Render(viewUser, "Edit user", user)) +} diff --git a/utils/routetests/All.go b/utils/routetests/All.go index 4c4d641d..4185d0ba 100644 --- a/utils/routetests/All.go +++ b/utils/routetests/All.go @@ -354,6 +354,7 @@ var routeTests = map[string][]string{ "/animelist/dropped": nil, "/notifications": nil, "/user/:nick/notifications": nil, + "/user/:nick/edit": nil, "/api/test/notification": nil, "/api/paypal/payment/create": nil, "/api/userfollows/:id/get/:item": nil,