Update homepage: remove create account, hide login if logged in
This commit is contained in:
+11
-1
@@ -38,8 +38,18 @@ func main() {
|
|||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", func(c echo.Context) error {
|
||||||
|
tokenString := getToken(c)
|
||||||
|
loggedIn := false
|
||||||
|
if tokenString != "" {
|
||||||
|
token, err := jwtgo.Parse(tokenString, func(token *jwtgo.Token) (interface{}, error) {
|
||||||
|
return []byte(cfg.JWTSecret), nil
|
||||||
|
})
|
||||||
|
if err == nil && token.Valid {
|
||||||
|
loggedIn = true
|
||||||
|
}
|
||||||
|
}
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := templates.Index().Render(c.Request().Context(), &buf)
|
err := templates.Index(loggedIn).Render(c.Request().Context(), &buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-49
@@ -1,6 +1,6 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
templ Index() {
|
templ Index(loggedIn bool) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@@ -204,60 +204,39 @@ templ Index() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Auth Section -->
|
<!-- Auth Section -->
|
||||||
<div id="auth" class="py-16">
|
if !loggedIn {
|
||||||
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div id="auth" class="py-16">
|
||||||
<div class="text-center mb-12">
|
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
<h2 class="text-3xl font-extrabold" style="color: var(--text-primary)">Join Bookmann Today</h2>
|
<div class="text-center mb-12">
|
||||||
<p class="mt-4 text-lg" style="color: var(--text-secondary)">Create your account or sign in to start managing your ebook library</p>
|
<h2 class="text-3xl font-extrabold" style="color: var(--text-primary)">Join Bookmann Today</h2>
|
||||||
</div>
|
<p class="mt-4 text-lg" style="color: var(--text-secondary)">Sign in to start managing your ebook library</p>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
||||||
<div class="card p-8 rounded-xl border">
|
|
||||||
<h3 class="text-2xl font-semibold mb-6 text-center" style="color: var(--text-primary)">Login</h3>
|
|
||||||
<form hx-post="/api/auth/login" hx-target="#auth-result" hx-swap="innerHTML">
|
|
||||||
<div class="space-y-4">
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Email or Username</label>
|
|
||||||
<input type="text" name="login" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Password</label>
|
|
||||||
<input type="password" name="password" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="w-full btn-primary py-2 rounded-lg font-medium">
|
|
||||||
Sign In
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card p-8 rounded-xl border">
|
<div class="grid grid-cols-1 gap-8">
|
||||||
<h3 class="text-2xl font-semibold mb-6 text-center" style="color: var(--text-primary)">Create Account</h3>
|
<div class="card p-8 rounded-xl border">
|
||||||
<form hx-post="/api/auth/register" hx-target="#auth-result" hx-swap="innerHTML">
|
<h3 class="text-2xl font-semibold mb-6 text-center" style="color: var(--text-primary)">Login</h3>
|
||||||
<div class="space-y-4">
|
<form hx-post="/api/auth/login" hx-target="#auth-result" hx-swap="innerHTML">
|
||||||
<div>
|
<div class="space-y-4">
|
||||||
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Email</label>
|
<div>
|
||||||
<input type="email" name="email" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Email or Username</label>
|
||||||
|
<input type="text" name="login" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Password</label>
|
||||||
|
<input type="password" name="password" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="w-full btn-primary py-2 rounded-lg font-medium">
|
||||||
|
Sign In
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</form>
|
||||||
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Username</label>
|
</div>
|
||||||
<input type="text" name="username" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium mb-1" style="color: var(--text-secondary)">Password</label>
|
|
||||||
<input type="password" name="password" class="w-full px-3 py-2 border rounded-lg" style="background-color: var(--bg-primary); color: var(--text-primary); border-color: var(--border)" required>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="w-full btn-primary py-2 rounded-lg font-medium">
|
|
||||||
Sign Up
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="auth-result" class="mt-8 text-center"></div>
|
<div id="auth-result" class="mt-8 text-center"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function applyTheme(theme) {
|
function applyTheme(theme) {
|
||||||
|
|||||||
Reference in New Issue
Block a user