|
|
@@ -3,38 +3,39 @@ package templatehelpers
|
|
|
import (
|
|
|
"github.com/kataras/iris"
|
|
|
"strings"
|
|
|
+ _ "fmt"
|
|
|
)
|
|
|
|
|
|
-type PageUserParams struct{
|
|
|
- NotificationType string
|
|
|
- Notification string
|
|
|
- ReqDir string
|
|
|
- Username string
|
|
|
- Admin string
|
|
|
- Custom []string
|
|
|
- } // TODO outsource
|
|
|
-
|
|
|
- // TODO error handler
|
|
|
-
|
|
|
- func ShowError(options []string, ctx *iris.Context) { // TODO: check if backend exploiteable, TODO: implement forwarding form values ?
|
|
|
- location := strings.TrimLeft(ctx.RequestPath(false), "/")
|
|
|
- if len(options) > 1 {
|
|
|
- if options[1] != "" {
|
|
|
- location = options[1]
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ctx.Render(location + "_box.html", PageUserParams{"1", options[0], location, "", "0", []string{}}) // TODO: Dynamic params
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- func ShowNotification(options []string, ctx *iris.Context) { // TODO: check if backend exploiteable, TODO: implement forwarding form values ?
|
|
|
- location := strings.TrimLeft(ctx.RequestPath(false), "/")
|
|
|
- if len(options) > 1 {
|
|
|
- if options[1] != "" {
|
|
|
- location = options[1]
|
|
|
- }
|
|
|
- }
|
|
|
- ctx.Render(location + "_box.html", PageUserParams{"2", options[0], location, "", "0", []string{}}) // TODO: Dynamic params
|
|
|
- return
|
|
|
- }
|
|
|
+// TODO outsource this and down to main template handler?
|
|
|
+// -> no ShowError/ShowNotification needed anymore?
|
|
|
+
|
|
|
+func ShowError(ctx *iris.Context) {
|
|
|
+ params := ctx.Get("params").(map[string]string)
|
|
|
+ ctx.Render(params["reqDir"] + "_box.html", params)
|
|
|
+}
|
|
|
+
|
|
|
+func ShowNotification(ctx *iris.Context) {
|
|
|
+ params := ctx.Get("params").(map[string]string)
|
|
|
+ ctx.Render(params["reqDir"] + "_box.html", params)
|
|
|
+}
|
|
|
+
|
|
|
+func InitPageParams(ctx *iris.Context) {
|
|
|
+ var params map[string]string
|
|
|
+ params = make(map[string]string)
|
|
|
+
|
|
|
+ loc := strings.TrimLeft(ctx.RequestPath(false), "/")
|
|
|
+ if loc == "" { // if requesting / -> home
|
|
|
+ loc = "home"
|
|
|
+ }
|
|
|
+
|
|
|
+ params["reqDir"] = loc
|
|
|
+
|
|
|
+ ctx.Set("params", params)
|
|
|
+ ctx.Next()
|
|
|
+}
|
|
|
+
|
|
|
+func UpdatePageParam(ctx *iris.Context, key string, value string) {
|
|
|
+ params := ctx.Get("params").(map[string]string)
|
|
|
+ params[key] = value
|
|
|
+ ctx.Set("params", params)
|
|
|
+}
|