Add user management interface

This commit is contained in:
Las Zenow 2018-04-08 10:55:13 +00:00
parent 6cd5b1bc5e
commit 6f906ccae4
8 changed files with 124 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package trantor
import (
log "github.com/cihub/seelog"
"gitlab.com/trantor/trantor/lib/database"
"net/http"
)
@ -95,3 +96,56 @@ func settingsHandler(h handler) {
data.S.Title = "Settings -- " + data.S.Title
h.load("settings", data)
}
func userAdminHandler(h handler) {
if !h.sess.IsAdmin() {
notFound(h)
return
}
users, err := h.db.ListUsers()
if err != nil {
log.Error("Something went wrong listing users: ", err)
notFound(h)
return
}
var data userAdminData
data.S = GetStatus(h)
data.S.Title = "Users admin -- " + data.S.Title
data.Users = users
h.load("user_admin", data)
}
func userAdminPostHandler(h handler) {
if !h.sess.IsAdmin() {
notFound(h)
return
}
username := h.r.FormValue("username")
password := h.r.FormValue("password")
role := h.r.FormValue("role")
if password != "" {
err := h.db.SetPassword(username, password)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
} else {
h.sess.Notify("Password updated!", "", "success")
}
} else if role != "" {
err := h.db.SetRole(username, role)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
} else {
h.sess.Notify("Role updated!", "", "success")
}
}
userAdminHandler(h)
}
type userAdminData struct {
S Status
Users []database.User
}