diff --git a/router/router.go b/router/router.go index 3a55bb2..f7254c6 100644 --- a/router/router.go +++ b/router/router.go @@ -94,7 +94,22 @@ func (router *router) setup() http.Handler { r.Handle("/assets/", http.StripPrefix("/assets/", http.FileServerFS(router.assets))) - r.HandleFunc("/dashboard/", router.dashboard) + r.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) { + // TODO: Add a way to the user to bypass this check and see the landing page. + // Probably a query parameter to bypass like "?landing=true" + if userController.isLogged(r) { + err := router.templates.ExecuteTemplate(w, "dashboard", nil) + if err != nil { + exception.InternalServerError(err).ServeHTTP(w, r) + } + return + } + + err := router.templates.ExecuteTemplate(w, "landing", nil) + if err != nil { + exception.InternalServerError(err).ServeHTTP(w, r) + } + }) r.HandleFunc("/login/{$}", userController.login) r.HandleFunc("/register/{$}", userController.register) diff --git a/router/users.go b/router/users.go index d87183b..4c65e0d 100644 --- a/router/users.go +++ b/router/users.go @@ -128,3 +128,9 @@ func (c userController) register(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", http.StatusSeeOther) } + +func (ctrl userController) isLogged(r *http.Request) bool { + // TODO: Check if token in valid (depends on token service being implemented) + cs := r.CookiesNamed("token") + return len(cs) > 0 +}