Admin is now able to add users

This commit is contained in:
Las Zenow 2018-04-08 11:11:27 +00:00
parent 6f906ccae4
commit 240a8a0430
3 changed files with 53 additions and 0 deletions

View file

@ -145,6 +145,30 @@ func userAdminPostHandler(h handler) {
userAdminHandler(h)
}
func addUserHandler(h handler) {
if !h.sess.IsAdmin() {
notFound(h)
return
}
username := h.r.FormValue("username")
password := h.r.FormValue("password")
role := h.r.FormValue("role")
err := h.db.AddUser(username, password)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
} else {
err := h.db.SetRole(username, role)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
} else {
h.sess.Notify("User created!", "", "success")
}
}
userAdminHandler(h)
}
type userAdminData struct {
S Status
Users []database.User