develop #4

Merged
zeni merged 11 commits from develop into main 2024-10-16 00:00:21 -04:00
11 changed files with 202 additions and 48 deletions
Showing only changes of commit f80c062099 - Show all commits

View file

@ -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)

View file

@ -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)

View file

@ -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",
},
}

100
controllers/themedemo.go Normal file
View file

@ -0,0 +1,100 @@
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// 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)
}
}

View file

@ -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)
}

View file

@ -1,13 +1,15 @@
<!DOCTYPE html>
<html lang="en">
{{template "head" "Goffee"}}
{{template "page_head" "Sample page"}}
<body>
<main>
{{template "title" .TheTitle}}
</main>
<script src="/public/app.js"></script>
<div class="container">
<div class="row">
{{template "page_card" .PageCard}}
{{ define "page_card_content" }}
<img class="goffeelogo"src="/public/img/goffee.png" alt="Goffee logo" />
{{ end }}
</div>
</div>
{{template "page_footer"}}
</body>
</html>
</html>

View file

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
{{template "head" "Goffee"}}
<body>
<main>
{{template "title" .TheTitle}}
<div class="section">
Welcome to Goffee
</div>
<img class="goffeelogo"src="/public/img/goffee.png" alt="Goffee logo" />
</main>
<script src="/public/app.js"></script>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
{{template "page_head" "Goffee"}}
<body>
<div class="container">
{{template "page_card" .PageCard}}
</div>
{{template "page_footer"}}
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
{{template "page_head" "Goffee"}}
<body>
<div class="container">
<form>
<fieldset>
<legend>Legend</legend>
<div class="row">
{{template "form_input" .FormText}}
{{template "form_input" .FormEmail}}
</div>
</fieldset>
{{template "form_button" .FormButton}}
</form>
</div>
{{template "page_footer"}}
</body>
</html>

View file

@ -1,10 +1,9 @@
<!DOCTYPE html>
<html lang="en">
{{template "head" "Goffee"}}
{{template "page_head" "Goffee"}}
<body>
<main>
{{template "title" .TheTitle}}
<form method="POST" action="/signin">
<div>
<label for="email">Email:</label>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
{{template "page_head" "Sample page"}}
<body>
<div class="container">
<div class="row">
{{template "page_card" .PageCard}}
{{ define "page_card_content" }}
<img class="goffeelogo"src="/public/img/goffee.png" alt="Goffee logo" />
{{ end }}
</div>
</div>
{{template "page_footer"}}
</body>
</html>