(w http.ResponseWriter, r *http.Request, user *models.User, ttl time.Duration)
| 329 | } |
| 330 | |
| 331 | func (s *Server) createAuthSession(w http.ResponseWriter, r *http.Request, user *models.User, ttl time.Duration) (string, error) { |
| 332 | token, err := s.store.CreateSession(user.ID, "web", clientIP(r), r.UserAgent(), ttl) |
| 333 | if err != nil { |
| 334 | writeError(w, http.StatusInternalServerError, "internal_error", "Failed to create session") |
| 335 | return "", err |
| 336 | } |
| 337 | |
| 338 | http.SetCookie(w, &http.Cookie{ |
| 339 | Name: sessionCookieName(s.secureCookies), |
| 340 | Value: token, |
| 341 | Path: "/", |
| 342 | MaxAge: int(ttl.Seconds()), |
| 343 | HttpOnly: true, |
| 344 | Secure: s.secureCookies, |
| 345 | SameSite: http.SameSiteLaxMode, |
| 346 | }) |
| 347 | |
| 348 | // Set CSRF cookie alongside the session cookie |
| 349 | setCSRFCookie(w, int(ttl.Seconds()), s.secureCookies) |
| 350 | |
| 351 | return token, nil |
| 352 | } |
| 353 | |
| 354 | // handleBootstrap creates the first admin account for a fresh instance. |
| 355 | // |
no test coverage detected