Added register route and template.
This commit is contained in:
parent
fe0fb8c801
commit
fc1d3cdc33
7 changed files with 69 additions and 8 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"goweb/msg"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,8 +19,7 @@ func (l *Login) Get(c echo.Context) error {
|
||||||
return l.RenderPage(c, p)
|
return l.RenderPage(c, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (a *Contact) Post(c echo.Context) error {
|
func (l *Login) Post(c echo.Context) error {
|
||||||
// msg.Set(c, msg.Success, "Thank you for contacting us!")
|
msg.Set(c, msg.Danger, "Invalid credentials. Please try again.")
|
||||||
// msg.Set(c, msg.Info, "We will respond to you shortly.")
|
return l.Get(c)
|
||||||
// return a.Redirect(c, "home")
|
}
|
||||||
//}
|
|
||||||
|
|
|
||||||
25
controllers/register.go
Normal file
25
controllers/register.go
Normal 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)
|
||||||
|
}
|
||||||
|
|
@ -63,4 +63,9 @@ func navRoutes(e *echo.Echo, ctr controllers.Controller) {
|
||||||
func userRoutes(e *echo.Echo, ctr controllers.Controller) {
|
func userRoutes(e *echo.Echo, ctr controllers.Controller) {
|
||||||
login := controllers.Login{Controller: ctr}
|
login := controllers.Login{Controller: ctr}
|
||||||
e.GET("/user/login", login.Get).Name = "login"
|
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"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="columns is-centered">
|
<div class="columns is-centered">
|
||||||
<div class="column is-half">
|
<div class="column is-half">
|
||||||
<h1 class="title">Log in</h1>
|
{{- if .Title}}
|
||||||
|
<h1 class="title">{{.Title}}</h1>
|
||||||
|
{{- end}}
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
{{template "messages" .}}
|
||||||
{{template "content" .}}
|
{{template "content" .}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form method="POST">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">Message</label>
|
<label class="label">Message</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form action="" class="">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="" class="label">Email</label>
|
<label for="" class="label">Email</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
|
@ -20,5 +20,7 @@
|
||||||
<a href="{{call .Reverse "home"}}" class="button is-light">Cancel</a>
|
<a href="{{call .Reverse "home"}}" class="button is-light">Cancel</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
{{template "csrf" .}}
|
||||||
</form>
|
</form>
|
||||||
|
<div class="content is-small"><a href="{{call .Reverse "register"}}">Create an account</a></div>
|
||||||
{{end}}
|
{{end}}
|
||||||
25
views/pages/register.gohtml
Normal file
25
views/pages/register.gohtml
Normal 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}}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue