Added register route and template.

This commit is contained in:
mikestefanello 2021-12-03 16:35:11 -05:00
parent fe0fb8c801
commit fc1d3cdc33
7 changed files with 69 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package controllers
import (
"goweb/msg"
"github.com/labstack/echo/v4"
)
@ -17,8 +19,7 @@ func (l *Login) Get(c echo.Context) error {
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")
//}
func (l *Login) Post(c echo.Context) error {
msg.Set(c, msg.Danger, "Invalid credentials. Please try again.")
return l.Get(c)
}

25
controllers/register.go Normal file
View File

@ -0,0 +1,25 @@
package controllers
import (
"goweb/msg"
"github.com/labstack/echo/v4"
)
type Register struct {
Controller
}
func (r *Register) Get(c echo.Context) error {
p := NewPage(c)
p.Layout = "auth"
p.Name = "register"
p.Title = "Register"
p.Data = "This is the login page"
return r.RenderPage(c, p)
}
func (r *Register) Post(c echo.Context) error {
msg.Set(c, msg.Danger, "Registration is currently disabled.")
return r.Get(c)
}

View File

@ -63,4 +63,9 @@ func navRoutes(e *echo.Echo, ctr controllers.Controller) {
func userRoutes(e *echo.Echo, ctr controllers.Controller) {
login := controllers.Login{Controller: ctr}
e.GET("/user/login", login.Get).Name = "login"
e.POST("/user/login", login.Post).Name = "login.post"
register := controllers.Register{Controller: ctr}
e.GET("/user/register", register.Get).Name = "register"
e.POST("/user/register", register.Post).Name = "register.post"
}

View File

@ -10,8 +10,11 @@
<div class="container">
<div class="columns is-centered">
<div class="column is-half">
<h1 class="title">Log in</h1>
{{- if .Title}}
<h1 class="title">{{.Title}}</h1>
{{- end}}
<div class="box">
{{template "messages" .}}
{{template "content" .}}
</div>
</div>

View File

@ -1,5 +1,5 @@
{{define "content"}}
<form method="POST">
<form method="post">
<div class="field">
<label class="label">Message</label>
<div class="control">

View File

@ -1,5 +1,5 @@
{{define "content"}}
<form action="" class="">
<form method="post">
<div class="field">
<label for="" class="label">Email</label>
<div class="control">
@ -20,5 +20,7 @@
<a href="{{call .Reverse "home"}}" class="button is-light">Cancel</a>
</p>
</div>
{{template "csrf" .}}
</form>
<div class="content is-small"><a href="{{call .Reverse "register"}}">Create an account</a></div>
{{end}}

View File

@ -0,0 +1,25 @@
{{define "content"}}
<form method="post">
<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">Register</button>
</p>
<p class="control">
<a href="{{call .Reverse "home"}}" class="button is-light">Cancel</a>
</p>
</div>
{{template "csrf" .}}
</form>
{{end}}