package calls import ( "net/http" "strconv" "strings" "unicode/utf8" "amadan.net/rastrillo/rastrillo/sessions" "github.com/go-chi/chi/v5" ) // Guest sessions use the ordinary revocable session store, with a distinct // identity method. They can never resolve to a verified address or team member. func (a *app) requireParticipant(next http.Handler) http.Handler { return a.requireSignedInPage(a.requirePerson(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p, _ := currentPerson(r) path := r.URL.Path if p.Anonymous && !strings.HasPrefix(path, "/m/") && path != "/native/authorize" && path != "/native/complete" && path != "/native/offer" { a.notFound(w, r) return } next.ServeHTTP(w, r) }))) } func (a *app) guestPage(w http.ResponseWriter, r *http.Request, m Meeting, token, name, message string) { nativeHeaders(w) title := a.store.title(m) f := onMeeting("", title) f.public = true render(w, "guest", a.page(r, f, map[string]any{"Title": title, "Token": token, "Name": name, "NameError": message, "NativeURL": nativeJoinURL(a.cfg.Origin + "/j/" + token)})) } func (a *app) joinGuest(w http.ResponseWriter, r *http.Request) { nativeHeaders(w) if _, signedIn := a.auth.SessionFrom(r); signedIn { a.followLink(w, r) return } token := chi.URLParam(r, "token") link, m, live, err := a.store.liveLink(r.Context(), token) if err != nil { a.ErrorPage(w, r, 500, "") return } if !live { a.ErrorPage(w, r, 404, "") return } if m.RequireSignin { a.setJoinCookie(w, link.TokenHash) http.Redirect(w, r, signinPath, 303) return } name := strings.TrimSpace(r.PostFormValue("name")) if name == "" || utf8.RuneCountInString(name) > 80 { w.WriteHeader(422) a.guestPage(w, r, m, token, name, "Enter your name (up to 80 characters).") return } p, err := a.store.createGuest(r.Context(), name) if err != nil { a.ErrorPage(w, r, 500, "") return } _, live, err = a.store.mintGrantViaLink(r.Context(), link.ID, p.ID) if err != nil { a.ErrorPage(w, r, 500, "") return } if !live { a.ErrorPage(w, r, 404, "") return } value, err := a.nativeAuth.sessions.Mint(sessions.Session{Subject: strconv.FormatInt(p.ID, 10), Method: "guest", AuthTime: a.store.now(), At: a.store.now()}) if err != nil { a.ErrorPage(w, r, 500, "") return } http.SetCookie(w, &http.Cookie{Name: a.auth.SessionCookie(), Value: value, Path: "/", HttpOnly: true, Secure: strings.HasPrefix(a.cfg.Origin, "https:"), SameSite: http.SameSiteLaxMode}) http.Redirect(w, r, "/m/"+m.Sqid+"/join", 303) }