lets-go:11.1 nav and fake auth

This commit is contained in:
tamsin johnson 2024-02-07 12:40:54 -08:00
parent 165ee77a72
commit f116991de2
2 changed files with 15 additions and 3 deletions

View File

@ -184,6 +184,9 @@ func (app *application) userLoginPost(w http.ResponseWriter, r *http.Request) {
return return
} }
app.sessionManager.Put(r.Context(), "authenticatedUserID", 1)
app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED IN USER %s! (not really)", form.Username)) app.sessionManager.Put(r.Context(), "flash", fmt.Sprintf("LOGGED IN USER %s! (not really)", form.Username))
http.Redirect(w, r, "/", http.StatusSeeOther) 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) { func (app *application) userLogoutPost(w http.ResponseWriter, r *http.Request) {
id := app.sessionManager.PopInt(r.Context(), "authenticatedUserID") 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) http.Redirect(w, r, "/", http.StatusSeeOther)
} }

View File

@ -1,6 +1,15 @@
{{define "nav"}} {{define "nav"}}
<nav> <nav>
<a href="/">Home</a> <div>
<a href="/snippet/create">Create Snippet</a> <a href="/">Home</a>
<a href="/snippet/create">Create Snippet</a>
</div>
<div>
<a href="/user/signup">Signup</a>
<a href="/user/login">Login</a>
<form action="/user/logout" method="POST">
<button>Logout</button>
</form>
</div>
</nav> </nav>
{{end}} {{end}}