|
@@ -2,13 +2,27 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"github.com/kataras/iris"
|
|
"github.com/kataras/iris"
|
|
|
- "git.mmnx.de/Moe/go-template/html"
|
|
|
|
|
|
|
+ "github.com/kataras/go-template/html"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"git.mmnx.de/Moe/databaseutils"
|
|
"git.mmnx.de/Moe/databaseutils"
|
|
|
"git.mmnx.de/Moe/usermanager"
|
|
"git.mmnx.de/Moe/usermanager"
|
|
|
"git.mmnx.de/Moe/configutils"
|
|
"git.mmnx.de/Moe/configutils"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+type pageParams struct{
|
|
|
|
|
+ HasError string
|
|
|
|
|
+ Error string
|
|
|
|
|
+ ReqDir string
|
|
|
|
|
+ } // {Error: ""}
|
|
|
|
|
+
|
|
|
|
|
+type pageUserParams struct{
|
|
|
|
|
+ HasError string
|
|
|
|
|
+ Error string
|
|
|
|
|
+ ReqDir string
|
|
|
|
|
+ Username string
|
|
|
|
|
+ Email string
|
|
|
|
|
+ } // {Error: ""}
|
|
|
|
|
+
|
|
|
func main() {
|
|
func main() {
|
|
|
|
|
|
|
|
conf := configutils.ReadConfig("config.json") // read config
|
|
conf := configutils.ReadConfig("config.json") // read config
|
|
@@ -23,6 +37,14 @@ func main() {
|
|
|
fmt.Print("") // for not needing to remove fmt ...
|
|
fmt.Print("") // for not needing to remove fmt ...
|
|
|
|
|
|
|
|
iris.Config.IsDevelopment = true
|
|
iris.Config.IsDevelopment = true
|
|
|
|
|
+ //iris.Config.Render.Template.Gzip = true
|
|
|
|
|
+
|
|
|
|
|
+ /** HELPER FUNCTION EXAMPLE **/
|
|
|
|
|
+ /*config := html.DefaultConfig()
|
|
|
|
|
+ config.Layout = "layouts/main.html"
|
|
|
|
|
+ config.Helpers["boldme"] = func(input string) raymond.SafeString {
|
|
|
|
|
+ return raymond.SafeString("<b> " + input + "</b>")
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
/** ROUTING **/
|
|
/** ROUTING **/
|
|
|
|
|
|
|
@@ -30,53 +52,25 @@ func main() {
|
|
|
iris.Static("/css", "./static/css", 1)
|
|
iris.Static("/css", "./static/css", 1)
|
|
|
iris.Static("/img", "./static/img", 1)
|
|
iris.Static("/img", "./static/img", 1)
|
|
|
|
|
|
|
|
- //iris.Get("/test", usermanager.AuthHandler, testHandler)
|
|
|
|
|
-
|
|
|
|
|
iris.Post("/login", loginHandler) // login form handler
|
|
iris.Post("/login", loginHandler) // login form handler
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- iris.UseTemplate(html.New(html.Config{
|
|
|
|
|
- Layout: "layouts/main.html",
|
|
|
|
|
- }))
|
|
|
|
|
-
|
|
|
|
|
- /*config := html.DefaultConfig()
|
|
|
|
|
- config.Layout = "layouts/main.html"
|
|
|
|
|
- config.Helpers["boldme"] = func(input string) raymond.SafeString {
|
|
|
|
|
- return raymond.SafeString("<b> " + input + "</b>")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // set the template engine
|
|
|
|
|
- iris.UseTemplate(handlebars.New(config)).Directory("./templates", ".html")*/
|
|
|
|
|
-
|
|
|
|
|
- //iris.Config.Render.Template.Gzip = true
|
|
|
|
|
-
|
|
|
|
|
iris.Get("/", usermanager.AuthHandler, func(ctx *iris.Context) {
|
|
iris.Get("/", usermanager.AuthHandler, func(ctx *iris.Context) {
|
|
|
- if err := ctx.Render("notification_box.html", nil); err != nil {
|
|
|
|
|
- println(err.Error())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if err := ctx.Render("home_boxes.html", nil); err != nil {
|
|
|
|
|
|
|
+ params := pageParams{"0", "", ""}
|
|
|
|
|
+ if err := ctx.Render("home_boxes.html", params); err != nil {
|
|
|
println(err.Error())
|
|
println(err.Error())
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
iris.Get("/account", usermanager.AuthHandler, func(ctx *iris.Context) {
|
|
iris.Get("/account", usermanager.AuthHandler, func(ctx *iris.Context) {
|
|
|
- if err := ctx.Render("notification_box.html", nil); err != nil {
|
|
|
|
|
- println(err.Error())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if err := ctx.Render("account_box.html", nil); err != nil {
|
|
|
|
|
|
|
+ params := pageUserParams{"0", "", "account", "moe", "moritz@mmnx.de"}
|
|
|
|
|
+ if err := ctx.Render("account_box.html", params); err != nil {
|
|
|
println(err.Error())
|
|
println(err.Error())
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
iris.Get("/login", func(ctx *iris.Context) {
|
|
iris.Get("/login", func(ctx *iris.Context) {
|
|
|
- if err := ctx.Render("notification_box.html", struct{ Error string }{Error: ""}); err != nil { // TODO: do this only when there is a notification
|
|
|
|
|
- println(err.Error())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if err := ctx.Render("login.html", struct{ Error string }{Error: ""}); err != nil { // no error for normal login screen
|
|
|
|
|
|
|
+ params := pageParams{"0", "", "login"}
|
|
|
|
|
+ if err := ctx.Render("login.html", params); err != nil { // no error for normal login screen, struct{ Error string }{Error: ""}
|
|
|
println(err.Error())
|
|
println(err.Error())
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -90,10 +84,9 @@ func main() {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ iris.UseTemplate(html.New(html.Config{
|
|
|
|
|
+ Layout: "layouts/main.html",
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
/** OTHER **/
|
|
/** OTHER **/
|
|
|
|
|
|
|
@@ -108,11 +101,11 @@ func loginHandler(ctx *iris.Context) {
|
|
|
tokenString, err := user.Login(username, password) // try to login
|
|
tokenString, err := user.Login(username, password) // try to login
|
|
|
|
|
|
|
|
if err != nil { // TODO: template compatible error handling
|
|
if err != nil { // TODO: template compatible error handling
|
|
|
- ctx.Render("login.html", struct{ Error string }{Error: err.Error()})
|
|
|
|
|
|
|
+ ctx.Render("login.html", pageParams{"1", err.Error(), "login"})
|
|
|
} else {
|
|
} else {
|
|
|
ctx.SetCookieKV("token", tokenString)
|
|
ctx.SetCookieKV("token", tokenString)
|
|
|
ctx.Redirect("/")
|
|
ctx.Redirect("/")
|
|
|
- //ctx.Render("home.html", nil)
|
|
|
|
|
|
|
+ //ctx.Render("home.html", nil) // TODO: error-alternative success (main.html)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|