MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / discourseCallback

Method discourseCallback

internal/panel/handler.go:493–521  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

491}
492
493func (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

Callers

nothing calls this directly

Calls 8

setSessionCookieFunction · 0.85
EnabledMethod · 0.80
ParseCallbackMethod · 0.80
IsAllowedMethod · 0.80
CreateSessionMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected