Moved navigation to the left-side panel.
This commit is contained in:
parent
eafde27809
commit
0239f46247
6 changed files with 59 additions and 20 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"goweb/context"
|
"goweb/context"
|
||||||
|
"goweb/ent"
|
||||||
"goweb/htmx"
|
"goweb/htmx"
|
||||||
"goweb/msg"
|
"goweb/msg"
|
||||||
|
|
||||||
|
|
@ -68,6 +69,9 @@ type Page struct {
|
||||||
// IsAuth stores whether or not the user is authenticated
|
// IsAuth stores whether or not the user is authenticated
|
||||||
IsAuth bool
|
IsAuth bool
|
||||||
|
|
||||||
|
// AuthUser stores the authenticated user
|
||||||
|
AuthUser *ent.User
|
||||||
|
|
||||||
// StatusCode stores the HTTP status code that will be returned
|
// StatusCode stores the HTTP status code that will be returned
|
||||||
StatusCode int
|
StatusCode int
|
||||||
|
|
||||||
|
|
@ -137,6 +141,7 @@ func NewPage(ctx echo.Context) Page {
|
||||||
|
|
||||||
if u := ctx.Get(context.AuthenticatedUserKey); u != nil {
|
if u := ctx.Get(context.AuthenticatedUserKey); u != nil {
|
||||||
p.IsAuth = true
|
p.IsAuth = true
|
||||||
|
p.AuthUser = u.(*ent.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.HTMX.Request = htmx.GetRequest(ctx)
|
p.HTMX.Request = htmx.GetRequest(ctx)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
echomw "github.com/labstack/echo/v4/middleware"
|
echomw "github.com/labstack/echo/v4/middleware"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewPage(t *testing.T) {
|
func TestNewPage(t *testing.T) {
|
||||||
|
|
@ -29,13 +30,16 @@ func TestNewPage(t *testing.T) {
|
||||||
assert.False(t, p.Cache.Enabled)
|
assert.False(t, p.Cache.Enabled)
|
||||||
|
|
||||||
ctx, _ = tests.NewContext(c.Web, "/abc?def=123")
|
ctx, _ = tests.NewContext(c.Web, "/abc?def=123")
|
||||||
ctx.Set(context.AuthenticatedUserKey, 1)
|
usr, err := tests.CreateUser(c.ORM)
|
||||||
|
require.NoError(t, err)
|
||||||
|
ctx.Set(context.AuthenticatedUserKey, usr)
|
||||||
ctx.Set(echomw.DefaultCSRFConfig.ContextKey, "csrf")
|
ctx.Set(echomw.DefaultCSRFConfig.ContextKey, "csrf")
|
||||||
p = NewPage(ctx)
|
p = NewPage(ctx)
|
||||||
assert.Equal(t, "/abc", p.Path)
|
assert.Equal(t, "/abc", p.Path)
|
||||||
assert.Equal(t, "/abc?def=123", p.URL)
|
assert.Equal(t, "/abc?def=123", p.URL)
|
||||||
assert.False(t, p.IsHome)
|
assert.False(t, p.IsHome)
|
||||||
assert.True(t, p.IsAuth)
|
assert.True(t, p.IsAuth)
|
||||||
|
assert.Equal(t, usr, p.AuthUser)
|
||||||
assert.Equal(t, "csrf", p.CSRF)
|
assert.Equal(t, "csrf", p.CSRF)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ func (User) Edges() []ent.Edge {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hooks of the User.
|
||||||
func (User) Hooks() []ent.Hook {
|
func (User) Hooks() []ent.Hook {
|
||||||
return []ent.Hook{
|
return []ent.Hook{
|
||||||
hook.On(
|
hook.On(
|
||||||
|
|
|
||||||
|
|
@ -13,31 +13,48 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="navbarMenu" class="navbar-menu">
|
<div id="navbarMenu" class="navbar-menu">
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
{{link (call .ToURL "home") "Home" .Path "navbar-item"}}
|
|
||||||
{{link (call .ToURL "about") "About" .Path "navbar-item"}}
|
|
||||||
{{link (call .ToURL "contact") "Contact" .Path "navbar-item"}}
|
|
||||||
{{- if .IsAuth}}
|
|
||||||
{{link (call .ToURL "logout") "Logout" .Path "navbar-item"}}
|
|
||||||
{{- else}}
|
|
||||||
{{link (call .ToURL "login") "Login" .Path "navbar-item"}}
|
|
||||||
{{- end}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<section class="section">
|
<div class="container mt-5">
|
||||||
<div class="container">
|
<div class="columns">
|
||||||
|
<div class="column is-2">
|
||||||
|
<aside class="menu" hx-boost="true">
|
||||||
|
<p class="menu-label">General</p>
|
||||||
|
<ul class="menu-list">
|
||||||
|
<li>{{link (call .ToURL "home") "Dashboard" .Path}}</li>
|
||||||
|
<li>{{link (call .ToURL "about") "About" .Path}}</li>
|
||||||
|
<li>{{link (call .ToURL "contact") "Contact" .Path}}</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p class="menu-label">Account</p>
|
||||||
|
<ul class="menu-list">
|
||||||
|
{{- if .IsAuth}}
|
||||||
|
<li>{{link (call .ToURL "logout") "Logout" .Path}}</li>
|
||||||
|
{{- else}}
|
||||||
|
<li>{{link (call .ToURL "login") "Login" .Path}}</li>
|
||||||
|
<li>{{link (call .ToURL "register") "Register" .Path}}</li>
|
||||||
|
<li>{{link (call .ToURL "forgot_password") "Forgot password" .Path}}</li>
|
||||||
|
{{- end}}
|
||||||
|
</ul>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="column is-10">
|
||||||
|
{{template "messages" .}}
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
{{- if .Title}}
|
{{- if .Title}}
|
||||||
<h1 class="title">{{.Title}}</h1>
|
<h1 class="title">{{.Title}}</h1>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
{{template "messages" .}}
|
|
||||||
{{template "content" .}}
|
{{template "content" .}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form method="post">
|
<form method="post" hx-boost="true" action="{{call .ToURL "forgot_password.post"}}">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p>Enter your email address and we'll email you a link that allows you to reset your password.</p>
|
<p>Enter your email address and we'll email you a link that allows you to reset your password.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="email" class="label">Email address</label>
|
<label for="email" class="label">Email address</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="email" type="email" name="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}" required>
|
<input id="email" type="email" name="email" class="input {{.Form.Submission.GetFieldStatusClass "Email"}}" value="{{.Form.Email}}">
|
||||||
{{template "field-errors" (.Form.Submission.GetFieldErrors "Email")}}
|
{{template "field-errors" (.Form.Submission.GetFieldErrors "Email")}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,17 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "top-content"}}
|
{{define "top-content"}}
|
||||||
|
<section class="hero is-info welcome is-small">
|
||||||
|
<div class="hero-body">
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="title">
|
||||||
|
Hello{{if .IsAuth}}, {{.AuthUser.Name}}{{end}}
|
||||||
|
</h1>
|
||||||
|
<h2 class="subtitle">Welcome back!</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<h1 class="title">Recent posts</h1>
|
<h1 class="title">Recent posts</h1>
|
||||||
<h2 class="subtitle">
|
<h2 class="subtitle">
|
||||||
|
|
@ -56,7 +67,8 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "file-msg"}}
|
{{define "file-msg"}}
|
||||||
<article class="message is-small is-info mt-4" x-data="{show: true}" x-show="show">
|
<div class="block"></div>
|
||||||
|
<article class="message is-small is-warning" x-data="{show: true}" x-show="show">
|
||||||
<div class="message-header">
|
<div class="message-header">
|
||||||
<p>Serving files</p>
|
<p>Serving files</p>
|
||||||
<button class="delete is-small" aria-label="delete" @click="show = false"></button>
|
<button class="delete is-small" aria-label="delete" @click="show = false"></button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue