Improving FE and setting up an admin menu

This commit is contained in:
vinchent 2024-08-21 21:39:59 +02:00
parent 6e3f283a64
commit ffa6b9a423
3 changed files with 59 additions and 18 deletions

View File

@ -40,6 +40,12 @@ func (app *application) addDefaultData(td *templateData, r *http.Request) *templ
td.API = app.config.api
td.StripePubKey = app.config.stripe.key
td.StripeSecretKey = app.config.stripe.secret
if app.Session.Exists(r.Context(), "userID") {
td.IsAuthenticated = 1
} else {
td.IsAuthenticated = 0
}
return td
}

View File

@ -50,10 +50,45 @@
<li id="vt-link" class="nav-item d-none">
<a class="nav-link" href="/admin/virtual-terminal">Virtual Terminal</a>
</li>
{{ if eq .IsAuthenticated 1 }}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
href="#"
role="button"
data-bs-toggle="dropdown"
aria-expanded="false">Admin</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="/admin/virtual-terminal">Virtual Terminal</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item" href="/admin/all-sales">All Sales</a>
</li>
<li>
<a class="dropdown-item" href="/admin/all-subscriptions">All Sales</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item" href="/logout">Logout</a>
</li>
</ul>
</li>
{{ end }}
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li id="login-link" class="nav-item d-none">
{{ if eq .IsAuthenticated 1 }}
<li id="logout-link" class="nav-item">
<a href="/logout" class="nav-link">Logout</a>
</li>
{{ else }}
<li id="login-link" class="nav-item">
<a href="/login" class="nav-link">Login</a>
</li>
{{ end }}
</ul>
</ul>
</div>

View File

@ -1,19 +1,19 @@
let loginLink = document.getElementById("login-link");
let vtLink = document.getElementById("vt-link");
// let loginLink = document.getElementById("login-link");
// let vtLink = document.getElementById("vt-link");
//
// document.addEventListener("DOMContentLoaded", function () {
// if (localStorage.getItem("token") !== null) {
// loginLink.innerHTML = '<a href="#!" onclick="logout()" class="nav-link">Logout</a>';
// vtLink.classList.remove('d-none');
// } else {
// loginLink.innerHTML = '<a href="/login" class="nav-link">Login</a>';
// }
// loginLink.classList.remove('d-none')
// });
document.addEventListener("DOMContentLoaded", function () {
if (localStorage.getItem("token") !== null) {
loginLink.innerHTML = '<a href="#!" onclick="logout()" class="nav-link">Logout</a>';
vtLink.classList.remove('d-none');
} else {
loginLink.innerHTML = '<a href="/login" class="nav-link">Login</a>';
}
loginLink.classList.remove('d-none')
});
function logout() {
localStorage.removeItem("token");
localStorage.removeItem("token_expiry");
location.href = "/logout";
}
// function logout() {
// localStorage.removeItem("token");
// localStorage.removeItem("token_expiry");
// location.href = "/logout";
// }