From fe0fb8c801e5b41fa881976ba8164a5d8466db5b Mon Sep 17 00:00:00 2001 From: mikestefanello Date: Fri, 3 Dec 2021 15:41:40 -0500 Subject: [PATCH] Added auth layout and route for login. --- controllers/home.go | 2 ++ controllers/login.go | 24 ++++++++++++++ router/router.go | 3 +- views/components/head.gohtml | 16 +++++++++ views/layouts/auth.gohtml | 23 +++++++++++++ views/layouts/main.gohtml | 62 ++++++++++++++++++----------------- views/pages/errors/404.gohtml | 2 +- views/pages/login.gohtml | 24 ++++++++++++++ 8 files changed, 124 insertions(+), 32 deletions(-) create mode 100644 controllers/login.go create mode 100644 views/components/head.gohtml create mode 100644 views/layouts/auth.gohtml create mode 100644 views/pages/login.gohtml diff --git a/controllers/home.go b/controllers/home.go index 8bab486..fc64c9d 100644 --- a/controllers/home.go +++ b/controllers/home.go @@ -13,6 +13,8 @@ func (h *Home) Get(c echo.Context) error { p.Layout = "main" p.Name = "home" p.Data = "Hello world" + p.Metatags.Description = "Welcome to the homepage." + p.Metatags.Keywords = []string{"Go", "MVC", "Web", "Software"} return h.RenderPage(c, p) } diff --git a/controllers/login.go b/controllers/login.go new file mode 100644 index 0000000..79c28e0 --- /dev/null +++ b/controllers/login.go @@ -0,0 +1,24 @@ +package controllers + +import ( + "github.com/labstack/echo/v4" +) + +type Login struct { + Controller +} + +func (l *Login) Get(c echo.Context) error { + p := NewPage(c) + p.Layout = "auth" + p.Name = "login" + p.Title = "Log in" + p.Data = "This is the login page" + return l.RenderPage(c, p) +} + +//func (a *Contact) Post(c echo.Context) error { +// msg.Set(c, msg.Success, "Thank you for contacting us!") +// msg.Set(c, msg.Info, "We will respond to you shortly.") +// return a.Redirect(c, "home") +//} diff --git a/router/router.go b/router/router.go index 0aa5714..559ce9f 100644 --- a/router/router.go +++ b/router/router.go @@ -61,5 +61,6 @@ func navRoutes(e *echo.Echo, ctr controllers.Controller) { } func userRoutes(e *echo.Echo, ctr controllers.Controller) { - // TODO + login := controllers.Login{Controller: ctr} + e.GET("/user/login", login.Get).Name = "login" } diff --git a/views/components/head.gohtml b/views/components/head.gohtml new file mode 100644 index 0000000..27479b5 --- /dev/null +++ b/views/components/head.gohtml @@ -0,0 +1,16 @@ +{{define "metatags"}} + {{ .AppName }}{{ if .Title }} | {{ .Title }}{{ end }} + + + + {{- if .Metatags.Description}} + + {{- end}} + {{- if .Metatags.Keywords}} + + {{- end}} +{{end}} + +{{define "css"}} + +{{end}} \ No newline at end of file diff --git a/views/layouts/auth.gohtml b/views/layouts/auth.gohtml new file mode 100644 index 0000000..3c5d811 --- /dev/null +++ b/views/layouts/auth.gohtml @@ -0,0 +1,23 @@ + + + + {{template "metatags" .}} + {{template "css" .}} + + +
+
+
+
+
+

Log in

+
+ {{template "content" .}} +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/views/layouts/main.gohtml b/views/layouts/main.gohtml index 5d7ea45..798fc78 100644 --- a/views/layouts/main.gohtml +++ b/views/layouts/main.gohtml @@ -1,37 +1,39 @@ - - - {{ .AppName }}{{ if .Title }} | {{ .Title }}{{ end }} - - - - - - + -
-
- {{- if .Title}} -

{{.Title}}

- {{- end}} +
+
+ {{- if .Title}} +

{{.Title}}

+ {{- end}} - {{template "messages" .}} - {{template "content" .}} -
-
- + {{template "messages" .}} + {{template "content" .}} +
+
+ \ No newline at end of file diff --git a/views/pages/errors/404.gohtml b/views/pages/errors/404.gohtml index 078d3d0..c62cb6b 100644 --- a/views/pages/errors/404.gohtml +++ b/views/pages/errors/404.gohtml @@ -1,3 +1,3 @@ {{define "content"}} -

Click here to return home

+

Click {{link (call .Reverse "home") "here" .Path}} to return home

{{end}} \ No newline at end of file diff --git a/views/pages/login.gohtml b/views/pages/login.gohtml new file mode 100644 index 0000000..408451c --- /dev/null +++ b/views/pages/login.gohtml @@ -0,0 +1,24 @@ +{{define "content"}} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+

+ +

+

+ Cancel +

+
+
+{{end}} \ No newline at end of file