Protecting our routes with auth middleware
This commit is contained in:
parent
68d9110cd2
commit
dedab91898
@ -37,5 +37,10 @@ func routes(app *config.AppConfig) http.Handler {
|
||||
fileServer := http.FileServer(http.Dir("./static/"))
|
||||
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
||||
|
||||
mux.Route("/admin", func(mux chi.Router) {
|
||||
mux.Use(Auth)
|
||||
mux.Get("/dashboard", handlers.Repo.AdminDashboard)
|
||||
})
|
||||
|
||||
return mux
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
m.App.Session.Put(r.Context(), "user_id", id)
|
||||
m.App.Session.Put(r.Context(), "flash", "Logged in successfully")
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/admin/dashboard", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// Logout logs a user out
|
||||
@ -502,3 +502,7 @@ func (m *Repository) Logout(w http.ResponseWriter, r *http.Request) {
|
||||
m.App.Session.RenewToken(r.Context())
|
||||
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (m *Repository) AdminDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
render.Template(w, r, "admin-dashboard.page.tmpl", &models.TemplateData{})
|
||||
}
|
||||
|
19
templates/admin-dashboard.page.tmpl
Normal file
19
templates/admin-dashboard.page.tmpl
Normal file
@ -0,0 +1,19 @@
|
||||
{{template "base" .}}
|
||||
{{define "content"}}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>Dashboard</h1>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sed convallis urna, vitae congue
|
||||
odio. Sed pulvinar diam a odio tristique, nec porta eros suscipit. Sed lacinia ut nisl ultrices
|
||||
condimentum. Vivamus imperdiet sapien sit amet mauris ornare accumsan. Proin varius imperdiet
|
||||
gravida. Suspendisse posuere velit leo, sit amet egestas quam porta quis. Duis in nulla eu quam
|
||||
iaculis iaculis. Etiam commodo gravida venenatis. Phasellus in vehicula est, aliquam condimentum
|
||||
nisi. In id ligula lacinia, varius leo vel, tincidunt libero. Nullam cursus vel lectus at consequat.
|
||||
Quisque malesuada efficitur sem et sollicitudin. Donec eget tincidunt arcu. Quisque ut posuere ex.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user