lets-go:11.0 very minimal first pass at logout

curious why `http.Redirect` does POST here? because i haven't handled any user input?
This commit is contained in:
tamsin johnson 2024-02-07 12:33:53 -08:00
parent c1bb129b87
commit 165ee77a72
2 changed files with 9 additions and 0 deletions

View File

@ -188,3 +188,11 @@ func (app *application) userLoginPost(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusSeeOther) http.Redirect(w, r, "/", http.StatusSeeOther)
} }
// userLoginPost ...
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))
http.Redirect(w, r, "/", http.StatusSeeOther)
}

View File

@ -33,6 +33,7 @@ func (app *application) routes() http.Handler {
router.Handler(http.MethodPost, "/user/signup", dynamic.ThenFunc(app.userSignupPost)) router.Handler(http.MethodPost, "/user/signup", dynamic.ThenFunc(app.userSignupPost))
router.Handler(http.MethodGet, "/user/login", dynamic.ThenFunc(app.userLogin)) router.Handler(http.MethodGet, "/user/login", dynamic.ThenFunc(app.userLogin))
router.Handler(http.MethodPost, "/user/login", dynamic.ThenFunc(app.userLoginPost)) router.Handler(http.MethodPost, "/user/login", dynamic.ThenFunc(app.userLoginPost))
router.Handler(http.MethodPost, "/user/logout", dynamic.ThenFunc(app.userLogoutPost))
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders) standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)