From f116991de264347536307838fe7df25f8692de8a Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Wed, 7 Feb 2024 12:40:54 -0800 Subject: [PATCH] lets-go:11.1 nav and fake auth --- snippetbox/cmd/web/handlers.go | 5 ++++- snippetbox/ui/html/partials/nav.tmpl | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/snippetbox/cmd/web/handlers.go b/snippetbox/cmd/web/handlers.go index 0af9a43..d6bfef5 100644 --- a/snippetbox/cmd/web/handlers.go +++ b/snippetbox/cmd/web/handlers.go @@ -184,6 +184,9 @@ func (app *application) userLoginPost(w http.ResponseWriter, r *http.Request) { return } + + app.sessionManager.Put(r.Context(), "authenticatedUserID", 1) + app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED IN USER %s! (not really)", form.Username)) http.Redirect(w, r, "/", http.StatusSeeOther) @@ -193,6 +196,6 @@ func (app *application) userLoginPost(w http.ResponseWriter, r *http.Request) { func (app *application) userLogoutPost(w http.ResponseWriter, r *http.Request) { id := app.sessionManager.PopInt(r.Context(), "authenticatedUserID") - app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED OUT USER %s! (not really)", id)) + app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED OUT USER %d! (not really)", id)) http.Redirect(w, r, "/", http.StatusSeeOther) } diff --git a/snippetbox/ui/html/partials/nav.tmpl b/snippetbox/ui/html/partials/nav.tmpl index d9fbcd8..d2f783b 100644 --- a/snippetbox/ui/html/partials/nav.tmpl +++ b/snippetbox/ui/html/partials/nav.tmpl @@ -1,6 +1,15 @@ {{define "nav"}} {{end}} \ No newline at end of file