From 48a84eb03f6b17ee41d6f097c78d89488ba14e8c Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Tue, 30 Jul 2024 00:46:05 +0300 Subject: Обновил сессии MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/user.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'controllers') diff --git a/controllers/user.go b/controllers/user.go index a605c25..6685383 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -24,7 +24,13 @@ func (rt *Router) Login(w http.ResponseWriter, r *http.Request) { } sess := session.FromRequest(r) - (*sess)["user"] = u + values := sess.Values(r.Context()) + values["user"] = u + + if err := sess.Save(w, r, values); err != nil { + mux.Render(w, r, mux.DefaultErrorHandler(err)) + return + } mux.Redirect(w, 302, "/") return @@ -34,7 +40,8 @@ func (rt *Router) Login(w http.ResponseWriter, r *http.Request) { } func (rt *Router) Logout(w http.ResponseWriter, r *http.Request) { - session.Clear(w, r) + sess := session.FromRequest(r) + sess.Clear(w, r) mux.Redirect(w, 302, "/") } -- cgit v1.2.3