diff --git a/controllers/authentication.go b/controllers/authentication.go index 9001544..a58b71d 100644 --- a/controllers/authentication.go +++ b/controllers/authentication.go @@ -452,35 +452,37 @@ func Signout(c *core.Context) *core.Response { // Show basic app login func AppLogin(c *core.Context) *core.Response { + // first, include all compoments + // first, include all compoments type templateData struct { - TheTitle components.Title + PageCard components.PageCard } + // now fill data of the components tmplData := templateData{ - TheTitle: components.Title{ - Label: "Login form", + PageCard: components.PageCard{ + CardTitle: "Card title", + CardBody: "Loerm ipsum at deim", }, } - return c.Response.Template("login.html", tmplData) - } // Show basic app sample func AppSample(c *core.Context) *core.Response { - title := "lorem" - + // first, include all compoments type templateData struct { - TheTitle components.Title + PageCard components.PageCard } + // now fill data of the components tmplData := templateData{ - TheTitle: components.Title{ - Label: title, + PageCard: components.PageCard{ + CardTitle: "Protected page", + CardBody: "If you can see this page, your are loggedin", }, } - //fmt.Printf("Outside cookie user is: %s", user.Email) return c.Response.Template("app.html", tmplData) diff --git a/controllers/home.go b/controllers/home.go index c359166..0a88e29 100644 --- a/controllers/home.go +++ b/controllers/home.go @@ -24,16 +24,22 @@ func WelcomeHome(c *core.Context) *core.Response { TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr) if TemplateEnable { + + // first, include all compoments type templateData struct { - TheTitle components.Title + PageCard components.PageCard } + + // now fill data of the components tmplData := templateData{ - TheTitle: components.Title{ - Label: "Welcome to Goffee", + PageCard: components.PageCard{ + CardTitle: "Golang Framework", + CardBody: "Welcome to Goffee", }, } - return c.Response.Template("basic.html", tmplData) + return c.Response.Template("welcome.html", tmplData) + } else { message := "{\"message\": \"Welcome to Goffee\"}" return c.Response.Json(message) diff --git a/controllers/sample.go b/controllers/sample.go index fca1eab..1243d5d 100644 --- a/controllers/sample.go +++ b/controllers/sample.go @@ -12,13 +12,16 @@ import ( // Show basic template func Sample(c *core.Context) *core.Response { + // first, include all compoments type templateData struct { - TheTitle components.Title + PageCard components.PageCard } + // now fill data of the components tmplData := templateData{ - TheTitle: components.Title{ - Label: "Lorem ipsum inside", + PageCard: components.PageCard{ + CardTitle: "Framework Goffee", + CardBody: "Powered by Golang", }, } diff --git a/controllers/themedemo.go b/controllers/themedemo.go new file mode 100644 index 0000000..e6678cc --- /dev/null +++ b/controllers/themedemo.go @@ -0,0 +1,100 @@ +// Copyright (c) 2024 Zeni Kim +// Use of this source code is governed by MIT-style +// license that can be found in the LICENSE file. + +package controllers + +import ( + "os" + "strconv" + + "git.smarteching.com/goffee/core" + "git.smarteching.com/goffee/core/template/components" +) + +// Show home page +func Themedemo(c *core.Context) *core.Response { + + // check if template engine is enabled + TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE") + if TemplateEnableStr == "" { + TemplateEnableStr = "false" + } + TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr) + + if TemplateEnable { + + // first, include all compoments + type templateData struct { + PageCard components.PageCard + } + + // now fill data of the components + tmplData := templateData{ + PageCard: components.PageCard{ + CardTitle: "Card title", + CardBody: "Loerm ipsum at deim", + }, + } + + return c.Response.Template("custom_theme_base.html", tmplData) + + } else { + + message := "{\"message\": \"Error, template not enabled\"}" + return c.Response.Json(message) + + } + +} + +// Show form element page +func Themeform(c *core.Context) *core.Response { + + // check if template engine is enabled + TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE") + if TemplateEnableStr == "" { + TemplateEnableStr = "false" + } + TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr) + + if TemplateEnable { + + // first, include all compoments + type templateData struct { + FormText components.FormInput + FormEmail components.FormInput + FormButton components.FormButton + } + + // now fill data of the components + tmplData := templateData{ + FormText: components.FormInput{ + ID: "text", + Label: "Name", + Type: "text", + Hint: "This is sample hint", + Placeholder: "Enter your name", + }, + FormEmail: components.FormInput{ + ID: "email", + Label: "Email", + Type: "email", + Placeholder: "Enter your email address", + }, + FormButton: components.FormButton{ + Text: "Login", + IsSubmit: true, + IsPrimary: true, + }, + } + return c.Response.Template("custom_theme_formpage.html", tmplData) + + } else { + + message := "{\"message\": \"Error, template not enabled\"}" + return c.Response.Json(message) + + } + +} diff --git a/routes.go b/routes.go index c32a746..df898d6 100644 --- a/routes.go +++ b/routes.go @@ -20,11 +20,23 @@ func registerRoutes() { // Define your routes here... controller.Get("/", controllers.WelcomeHome) + // Uncomment the lines below to enable theme demo + controller.Get("/themebase", controllers.Themedemo) + controller.Get("/themeform", controllers.Themeform) + controller.Get("/themepanel", controllers.Themedemo) + // Uncomment the lines below to enable authentication - // controller.Post("/signup", controllers.Signup) - // controller.Post("/signin", controllers.Signin) - // controller.Post("/signout", controllers.Signout) - // controller.Post("/reset-password", controllers.ResetPasswordRequest) - // controller.Post("/reset-password/code/:code", controllers.SetNewPassword) + controller.Post("/signup", controllers.Signup) + controller.Post("/signin", controllers.Signin) + controller.Post("/signout", controllers.Signout) + controller.Post("/reset-password", controllers.ResetPasswordRequest) + controller.Post("/reset-password/code/:code", controllers.SetNewPassword) + controller.Get("/dashboard", controllers.WelcomeToDashboard, hooks.AuthCheck) + + controller.Get("/appsample", controllers.AppSample, hooks.AuthCheck) + controller.Post("/appsample", controllers.AppSample, hooks.AuthCheck) + + controller.Get("/applogin", controllers.AppLogin, hooks.CheckSessionCookie) + controller.Post("/applogin", controllers.AppLogin, hooks.CheckSessionCookie) } diff --git a/storage/templates/app.html b/storage/templates/app.html index fa6f417..21831b7 100644 --- a/storage/templates/app.html +++ b/storage/templates/app.html @@ -1,13 +1,15 @@ - {{template "head" "Goffee"}} + {{template "page_head" "Sample page"}} -
- - {{template "title" .TheTitle}} - - -
- +
+
+ {{template "page_card" .PageCard}} + {{ define "page_card_content" }} + + {{ end }} +
+
+ {{template "page_footer"}} - \ No newline at end of file + \ No newline at end of file diff --git a/storage/templates/basic.html b/storage/templates/basic.html deleted file mode 100644 index f1114ad..0000000 --- a/storage/templates/basic.html +++ /dev/null @@ -1,14 +0,0 @@ - - - {{template "head" "Goffee"}} - -
- {{template "title" .TheTitle}} -
- Welcome to Goffee -
- -
- - - \ No newline at end of file diff --git a/storage/templates/custom_theme_base.html b/storage/templates/custom_theme_base.html new file mode 100644 index 0000000..9c28a1e --- /dev/null +++ b/storage/templates/custom_theme_base.html @@ -0,0 +1,10 @@ + + + {{template "page_head" "Goffee"}} + +
+ {{template "page_card" .PageCard}} +
+ {{template "page_footer"}} + + \ No newline at end of file diff --git a/storage/templates/custom_theme_formpage.html b/storage/templates/custom_theme_formpage.html new file mode 100644 index 0000000..afb61a4 --- /dev/null +++ b/storage/templates/custom_theme_formpage.html @@ -0,0 +1,19 @@ + + + {{template "page_head" "Goffee"}} + +
+
+
+ Legend +
+ {{template "form_input" .FormText}} + {{template "form_input" .FormEmail}} +
+
+ {{template "form_button" .FormButton}} +
+
+ {{template "page_footer"}} + + diff --git a/storage/templates/login.html b/storage/templates/login.html index 4bc9e4d..96ce987 100644 --- a/storage/templates/login.html +++ b/storage/templates/login.html @@ -1,10 +1,9 @@ - {{template "head" "Goffee"}} + {{template "page_head" "Goffee"}}
- {{template "title" .TheTitle}}
diff --git a/storage/templates/welcome.html b/storage/templates/welcome.html new file mode 100644 index 0000000..21831b7 --- /dev/null +++ b/storage/templates/welcome.html @@ -0,0 +1,15 @@ + + + {{template "page_head" "Sample page"}} + +
+
+ {{template "page_card" .PageCard}} + {{ define "page_card_content" }} + + {{ end }} +
+
+ {{template "page_footer"}} + + \ No newline at end of file