(w http.ResponseWriter, r *http.Request)
| 491 | } |
| 492 | |
| 493 | func (h *Handler) discourseCallback(w http.ResponseWriter, r *http.Request) { |
| 494 | if !h.discourse.Enabled() { |
| 495 | http.Redirect(w, r, "/login", http.StatusFound) |
| 496 | return |
| 497 | } |
| 498 | rawSSO := r.URL.Query().Get("sso") |
| 499 | sig := r.URL.Query().Get("sig") |
| 500 | username, err := h.discourse.ParseCallback(rawSSO, sig) |
| 501 | if err != nil { |
| 502 | http.Redirect(w, r, "/login?error=1", http.StatusFound) |
| 503 | return |
| 504 | } |
| 505 | if !h.discourse.IsAllowed(username) { |
| 506 | http.Redirect(w, r, "/login?error=1", http.StatusFound) |
| 507 | return |
| 508 | } |
| 509 | token, err := h.auth.CreateSession(username) |
| 510 | if err != nil { |
| 511 | http.Error(w, "创建 session 失败", http.StatusInternalServerError) |
| 512 | return |
| 513 | } |
| 514 | setSessionCookie(w, token) |
| 515 | if cookie, cErr := r.Cookie("discourse_spa"); cErr == nil && cookie.Value == "1" { |
| 516 | http.SetCookie(w, &http.Cookie{Name: "discourse_spa", Value: "", Path: "/", MaxAge: -1}) |
| 517 | http.Redirect(w, r, "/login#discourse_token="+token, http.StatusFound) |
| 518 | return |
| 519 | } |
| 520 | http.Redirect(w, r, "/dashboard", http.StatusFound) |
| 521 | } |
| 522 | |
| 523 | // ─── 节点管理 ───────────────────────────────────────────────────────────────── |
| 524 |
nothing calls this directly
no test coverage detected