diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index 768385d..834ad35 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -8,9 +8,12 @@ import ( "io" "log" "net/http" + "strings" "github.com/go-playground/validator/v10" jwtgo "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) @@ -83,8 +86,36 @@ func main() { // Routes handlers.SetupRoutes(protected, queries) + // Static files + e.Static("/static", "static") + // Page routes e.GET("/", func(c echo.Context) error { + // Check if user has valid JWT token + tokenString := c.Request().Header.Get("Authorization") + if tokenString != "" && strings.HasPrefix(tokenString, "Bearer ") { + tokenString = strings.TrimPrefix(tokenString, "Bearer ") + token, err := jwtgo.Parse(tokenString, func(token *jwtgo.Token) (interface{}, error) { + return []byte(cfg.JWTSecret), nil + }) + if err == nil && token.Valid { + // User is authenticated, get user info and serve dashboard + claims := token.Claims.(jwtgo.MapClaims) + userID := claims["user_id"].(string) + + user, err := queries.GetUser(c.Request().Context(), pgtype.UUID{Bytes: uuid.MustParse(userID), Valid: true}) + if err == nil { + return c.Render(http.StatusOK, "dashboard.html", map[string]interface{}{ + "User": map[string]string{ + "ID": uuid.UUID(user.ID.Bytes).String(), + "Username": user.Username, + "Email": user.Email, + }, + }) + } + } + } + // User not authenticated or token invalid, serve landing page return c.Render(http.StatusOK, "index.html", nil) }) e.GET("/login", func(c echo.Context) error { diff --git a/backend/static/placeholder-book.svg b/backend/static/placeholder-book.svg new file mode 100644 index 0000000..6544b09 --- /dev/null +++ b/backend/static/placeholder-book.svg @@ -0,0 +1,9 @@ + + + + Book Cover + + + + + \ No newline at end of file diff --git a/backend/templates/dashboard.html b/backend/templates/dashboard.html new file mode 100644 index 0000000..bdacf87 --- /dev/null +++ b/backend/templates/dashboard.html @@ -0,0 +1,457 @@ +{{template "base.html" .}} + +{{define "title"}}Dashboard - Bookmann{{end}} + +{{define "content"}} + + + +
+ +
+
+
+

Your Ebook Library

+

Manage your ebook collection and reading progress

+
+ +
+
+ + +
+
+ + +
+
+ + + + + +
+ +
+ + +
+ Loading your ebooks... +
+ + + + + + +
+ + + + + +{{end}} \ No newline at end of file