diff --git a/controllers/users.go b/controllers/users.go index 039b59d..f33c758 100644 --- a/controllers/users.go +++ b/controllers/users.go @@ -58,9 +58,27 @@ func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) { http.Error(w, "Something went wrong.", http.StatusInternalServerError) return } + + // Bad cookie + cookie := http.Cookie{ + Name: "bad", + Value: user.Email, + Path: "/", + } + http.SetCookie(w, &cookie) + fmt.Fprintf(w, "User authenticated: %+v", user) } +func (u Users) CurrentUser(w http.ResponseWriter, r *http.Request) { + email, err := r.Cookie("bad") + if err != nil { + fmt.Fprint(w, "The bad cookie could not be read.") + return + } + fmt.Fprintf(w, "Bad cookie: %s\n", email.Value) +} + func WithTemplates(user_service *models.UserService, signup Template, signin Template) Users { u := Users{} u.Templates.Signup = signup diff --git a/main.go b/main.go index e98a240..73b6753 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,8 @@ func main() { r.Get("/signin", usersCtrlr.GetSignin) r.Post("/signin", usersCtrlr.PostSignin) + r.Get("/user", usersCtrlr.CurrentUser) + r.NotFound(notFoundHandler) fmt.Println("Starting the server on :3000...") http.ListenAndServe(":3000", r)