Skip to content

Commit 88b1293

Browse files
refactor(web): logout button
1 parent fb3c04d commit 88b1293

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

web/controllers/auth.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func LoginPost(c *fiber.Ctx, cc core.Context, store *session.Store) error {
2121
err := procs.AuthHTTPLogin(cc, username, password)
2222
if err != nil {
2323
if h.IsHTMXRequest(c) {
24-
return h.Render(c, "login", loginData(err.Error()), "form")
24+
return h.Render(c, "login", loginData(username, err.Error()), "form")
2525
}
26-
return h.Render(c, "login", loginData(err.Error()))
26+
return h.Render(c, "login", loginData(username, err.Error()))
2727
}
2828

2929
// Response
@@ -54,8 +54,9 @@ func Logout(c *fiber.Ctx, cc core.Context, store *session.Store) error {
5454
return h.Redirect(c, "/login")
5555
}
5656

57-
func loginData(flash string) fiber.Map {
57+
func loginData(username, flash string) fiber.Map {
5858
return fiber.Map{
59-
"Flash": flash,
59+
"Username": username,
60+
"Flash": flash,
6061
}
6162
}

web/views/envelopes-new.html

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h2>New Envelope</h2>
1212

1313
<form method="post" enctype="multipart/form-data">
1414
<div class="grid">
15+
{{csrf $}}
1516
<label for="from">
1617
From
1718
<input type="text" id="from" name="from" placeholder="From" />

web/views/login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h2>Login</h2>
1212
{{csrf $}}
1313
<label for="username">
1414
Username
15-
<input type="text" id="username" name="username" placeholder="Username" />
15+
<input type="text" id="username" name="username" placeholder="Username" value="{{.Username}}" />
1616
</label>
1717

1818
<label for="password">

web/views/partials/header.html

+11-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ul>
1111
<ul class=" block lg:hidden">
1212
<li class="p-0 flex flex-items-center h-full">
13-
<details role="list" dir="rtl">
13+
<details role="list" dir="rtl" open>
1414
<summary aria-haspopup="listbox" class="block pico-no-chevron">
1515
<div class=" i-ri-align-justify h-6 w-6" />
1616
</summary>
@@ -45,16 +45,11 @@
4545
</li>
4646
{{if not .Meta.Anonymous}}
4747
<li>
48-
<form method="post" action="/logout" class="pico-form-reset">
49-
{{csrf $}}
50-
<button type="submit" class="pico-button-reset">
51-
<a href="#" class="contrast" hx-post="/logout">
52-
<div class="flex flex-items-center flex-row-reverse gap-2">
53-
<div class="i-ri-logout-box-r-fill"></div>Log out
54-
</div>
55-
</a>
56-
</button>
57-
</form>
48+
<a href="#" class="contrast" hx-post="/logout">
49+
<div class="flex flex-items-center flex-row-reverse gap-2">
50+
<div class="i-ri-logout-box-r-fill"></div>Log out
51+
</div>
52+
</a>
5853
</li>
5954
{{end}}
6055
</ul>
@@ -92,16 +87,11 @@
9287
</li>
9388
{{if not .Meta.Anonymous}}
9489
<li>
95-
<form method="post" action="/logout" class="pico-form-reset">
96-
{{csrf $}}
97-
<button type="submit" class="pico-button-reset">
98-
<a href="#" class="contrast" hx-post="/logout">
99-
<div class="flex flex-items-center gap-2">
100-
<div class="i-ri-logout-box-r-fill"></div>Log out
101-
</div>
102-
</a>
103-
</button>
104-
</form>
90+
<a href="#" class="contrast" hx-post="/logout">
91+
<div class="flex flex-items-center gap-2">
92+
<div class="i-ri-logout-box-r-fill"></div>Log out
93+
</div>
94+
</a>
10595
</li>
10696
{{end}}
10797
</ul>

0 commit comments

Comments
 (0)