Download this file
| 1 | package calendar |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/home/connect" |
| 5 | rauth "amadan.net/rastrillo/rastrillo/auth" |
| 6 | "amadan.net/rastrillo/rastrillo/sessions" |
| 7 | "net/http" |
| 8 | ) |
| 9 | |
| 10 | // viewer is the signed-in identity on r, if any. |
| 11 | // |
| 12 | // auth.From, never sessions.UserID: under the magic-link plugin the |
| 13 | // session Subject is a verified email address, so UserID returns |
| 14 | // (0, false) and every owner-scoped query built on it would silently |
| 15 | // filter to person_id = 0 — a calendar that looks empty rather than |
| 16 | // broken, which is the more expensive failure. |
| 17 | func viewer(r *http.Request) (rauth.Identity, bool) { |
| 18 | if s, ok := sessions.Current(r); ok && s.Method == connect.HomeMethod { |
| 19 | p, found := CurrentPerson(r) |
| 20 | if !found { |
| 21 | return rauth.Identity{}, false |
| 22 | } |
| 23 | return rauth.Identity{Address: p.Address}, true |
| 24 | } |
| 25 | if s, ok := sessions.Current(r); ok && (s.Method == "magiclink" || s.Method == "keymail") { |
| 26 | return rauth.Identity{Address: normalizeAddress(s.Subject)}, s.Subject != "" |
| 27 | } |
| 28 | return rauth.From(r) |
| 29 | } |
| 30 | |