feat(router): show landing page if user is not logged in
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user