Current returns the currently logged-in user, or nil if the user is not signed in.
(c context.Context)
| 16 | // Current returns the currently logged-in user, |
| 17 | // or nil if the user is not signed in. |
| 18 | func Current(c context.Context) *User { |
| 19 | h := internal.IncomingHeaders(c) |
| 20 | u := &User{ |
| 21 | Email: h.Get("X-AppEngine-User-Email"), |
| 22 | AuthDomain: h.Get("X-AppEngine-Auth-Domain"), |
| 23 | ID: h.Get("X-AppEngine-User-Id"), |
| 24 | Admin: h.Get("X-AppEngine-User-Is-Admin") == "1", |
| 25 | FederatedIdentity: h.Get("X-AppEngine-Federated-Identity"), |
| 26 | FederatedProvider: h.Get("X-AppEngine-Federated-Provider"), |
| 27 | } |
| 28 | if u.Email == "" && u.FederatedIdentity == "" { |
| 29 | return nil |
| 30 | } |
| 31 | return u |
| 32 | } |
| 33 | |
| 34 | // IsAdmin returns true if the current user is signed in and |
| 35 | // is currently registered as an administrator of the application. |
searching dependent graphs…