Added auth layout and route for login.

This commit is contained in:
mikestefanello 2021-12-03 15:41:40 -05:00
parent 869fa82f14
commit fe0fb8c801
8 changed files with 124 additions and 32 deletions

View File

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

24
controllers/login.go Normal file
View File

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

View File

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

View File

@ -0,0 +1,16 @@
{{define "metatags"}}
<title>{{ .AppName }}{{ if .Title }} | {{ .Title }}{{ end }}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
{{- if .Metatags.Description}}
<meta name="description" content="{{.Metatags.Description}}">
{{- end}}
{{- if .Metatags.Keywords}}
<meta name="keywords" content="{{.Metatags.Keywords | join ", "}}">
{{- end}}
{{end}}
{{define "css"}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
{{end}}

23
views/layouts/auth.gohtml Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
{{template "metatags" .}}
{{template "css" .}}
</head>
<body>
<section class="hero is-info is-fullheight">
<div class="hero-body">
<div class="container">
<div class="columns is-centered">
<div class="column is-half">
<h1 class="title">Log in</h1>
<div class="box">
{{template "content" .}}
</div>
</div>
</div>
</div>
</div>
</section>
</body>
</html>

View File

@ -1,13 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ .AppName }}{{ if .Title }} | {{ .Title }}{{ end }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
</head>
<body>
<head>
{{template "metatags" .}}
{{template "css" .}}
</head>
<body>
<nav class="navbar is-dark">
<div class="container">
<div class="navbar-brand">
@ -18,6 +15,11 @@
{{link (call .Reverse "home") "Home" .Path "navbar-item"}}
{{link (call .Reverse "about") "About" .Path "navbar-item"}}
{{link (call .Reverse "contact") "Contact" .Path "navbar-item"}}
{{- if .IsAuth}}
{{- else}}
{{link (call .Reverse "login") "Login" .Path "navbar-item"}}
{{- end}}
</div>
</div>
</div>
@ -33,5 +35,5 @@
{{template "content" .}}
</div>
</section>
</body>
</body>
</html>

View File

@ -1,3 +1,3 @@
{{define "content"}}
<p>Click here to return home</p>
<p>Click {{link (call .Reverse "home") "here" .Path}} to return home</p>
{{end}}

24
views/pages/login.gohtml Normal file
View File

@ -0,0 +1,24 @@
{{define "content"}}
<form action="" class="">
<div class="field">
<label for="" class="label">Email</label>
<div class="control">
<input type="email" placeholder="e.g. bobsmith@gmail.com" class="input" required>
</div>
</div>
<div class="field">
<label for="" class="label">Password</label>
<div class="control">
<input type="password" placeholder="*******" class="input" required>
</div>
</div>
<div class="field is-grouped">
<p class="control">
<button class="button is-primary">Log in</button>
</p>
<p class="control">
<a href="{{call .Reverse "home"}}" class="button is-light">Cancel</a>
</p>
</div>
</form>
{{end}}