add user config page and admin menu

This commit is contained in:
2019-12-17 19:28:30 +01:00
parent 4c33b0841e
commit 7653470a7c
16 changed files with 648 additions and 107 deletions

View File

@@ -1,5 +1,7 @@
package pixelapi
import "net/url"
// IsAdmin is the response to the /admin/is_admin API
type IsAdmin struct {
Success bool `json:"success"`
@@ -14,3 +16,31 @@ func (p *PixelAPI) UserIsAdmin() (resp IsAdmin, err error) {
}
return resp, nil
}
// AdminGlobal is a global setting in pixeldrain's back-end
type AdminGlobal struct {
Key string `json:"key"`
Value string `json:"value"`
}
// AdminGlobals is an array of globals
type AdminGlobals struct {
Success bool `json:"success"`
Globals []AdminGlobal `json:"globals"`
}
// AdminGetGlobals returns if the logged in user is an admin user
func (p *PixelAPI) AdminGetGlobals() (resp AdminGlobals, err error) {
if err = p.jsonRequest("GET", p.apiEndpoint+"/admin/globals", &resp); err != nil {
return resp, err
}
return resp, nil
}
// AdminSetGlobals returns if the logged in user is an admin user
func (p *PixelAPI) AdminSetGlobals(key, value string) (resp SuccessResponse, err error) {
var form = url.Values{}
form.Add("key", key)
form.Add("value", value)
return resp, p.form("POST", p.apiEndpoint+"/admin/globals", form, &resp, true)
}