From 372d08353d407db046f02ca101c1eeafcf5409ea Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Fri, 31 Jul 2020 21:21:14 +0200 Subject: [PATCH] remove isAdmin API --- res/template/admin.html | 4 +--- res/template/fragments/page_wrap.html | 1 + webcontroller/admin_panel.go | 22 ++++++---------------- webcontroller/user_account.go | 10 +++------- webcontroller/web_controller.go | 2 +- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/res/template/admin.html b/res/template/admin.html index a7ef110..238b3cb 100644 --- a/res/template/admin.html +++ b/res/template/admin.html @@ -6,11 +6,9 @@ {{template "user_style" .}} - {{$isAdmin := .PixelAPI.UserIsAdmin}} {{template "page_top" .}}
- {{if $isAdmin}} - + {{if and .Authenticated .User.IsAdmin}}
Update global settings Block files diff --git a/res/template/fragments/page_wrap.html b/res/template/fragments/page_wrap.html index 880cc80..5c90a2c 100644 --- a/res/template/fragments/page_wrap.html +++ b/res/template/fragments/page_wrap.html @@ -6,6 +6,7 @@ {{if .Authenticated}}{{.User.Username}} My Files My Lists + {{if .User.IsAdmin}}Admin Panel{{end}} Log out {{else}} Login diff --git a/webcontroller/admin_panel.go b/webcontroller/admin_panel.go index a302e95..1828ff0 100644 --- a/webcontroller/admin_panel.go +++ b/webcontroller/admin_panel.go @@ -10,18 +10,13 @@ import ( ) func (wc *WebController) adminGlobalsForm(td *TemplateData, r *http.Request) (f Form) { - if isAdmin, err := td.PixelAPI.UserIsAdmin(); err != nil { - td.Title = err.Error() - return Form{Title: td.Title} - } else if !isAdmin { - td.Title = ";)" - return Form{Title: td.Title} + if !td.Authenticated || !td.User.IsAdmin { + return Form{Title: ";-)"} } - td.Title = "Pixeldrain global configuration" f = Form{ Name: "admin_globals", - Title: td.Title, + Title: "Pixeldrain global configuration", PreFormHTML: template.HTML("

Careful! The slightest typing error could bring the whole website down

"), BackLink: "/admin", SubmitLabel: "Submit", @@ -97,18 +92,13 @@ func (wc *WebController) adminGlobalsForm(td *TemplateData, r *http.Request) (f } func (wc *WebController) adminAbuseForm(td *TemplateData, r *http.Request) (f Form) { - if isAdmin, err := td.PixelAPI.UserIsAdmin(); err != nil { - td.Title = err.Error() - return Form{Title: td.Title} - } else if !isAdmin { - td.Title = ";)" - return Form{Title: td.Title} + if !td.Authenticated || !td.User.IsAdmin { + return Form{Title: ";-)"} } - td.Title = "Admin file removal" f = Form{ Name: "admin_file_removal", - Title: td.Title, + Title: "Admin file removal", PreFormHTML: template.HTML("

Paste any pixeldrain file links in here to remove them

"), Fields: []Field{ { diff --git a/webcontroller/user_account.go b/webcontroller/user_account.go index 1f99728..2be2adb 100644 --- a/webcontroller/user_account.go +++ b/webcontroller/user_account.go @@ -47,10 +47,9 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form } // Construct the form - td.Title = "Register a new pixeldrain account" f = Form{ Name: "register", - Title: td.Title, + Title: "Register a new pixeldrain account", Fields: []Field{ { Name: "username", @@ -128,7 +127,6 @@ func (wc *WebController) registerForm(td *TemplateData, r *http.Request) (f Form } func (wc *WebController) loginForm(td *TemplateData, r *http.Request) (f Form) { - td.Title = "Login" f = Form{ Name: "login", Title: "Log in to your pixeldrain account", @@ -186,10 +184,9 @@ func (wc *WebController) loginForm(td *TemplateData, r *http.Request) (f Form) { } func (wc *WebController) passwordResetForm(td *TemplateData, r *http.Request) (f Form) { - td.Title = "Recover lost password" f = Form{ Name: "password_reset", - Title: td.Title, + Title: "Recover lost password", Fields: []Field{ { Name: "email", @@ -233,10 +230,9 @@ func (wc *WebController) passwordResetForm(td *TemplateData, r *http.Request) (f } func (wc *WebController) passwordResetConfirmForm(td *TemplateData, r *http.Request) (f Form) { - td.Title = "Reset lost password" f = Form{ Name: "password_reset_confirm", - Title: td.Title, + Title: "Reset lost password", Fields: []Field{ { Name: "new_password", diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index ee85a1e..fd23664 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -260,7 +260,7 @@ func (wc *WebController) serveForm( // The handler retuns the form which will be rendered td.Form = handler(td, r) - + td.Title = td.Form.Title td.Form.Username = td.User.Username // Execute the extra actions if any