Add cookie
This commit is contained in:
parent
951c081680
commit
faf9139d79
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user