1// Copyright 2015 Google Inc. All rights reserved. 2// Use of this source code is governed by the Apache 2.0 3// license that can be found in the LICENSE file. 4 5// +build appengine 6 7package user 8 9import ( 10 "appengine/user" 11 12 "golang.org/x/net/context" 13 14 "google.golang.org/appengine/internal" 15) 16 17func Current(ctx context.Context) *User { 18 c, err := internal.ClassicContextFromContext(ctx) 19 if err != nil { 20 panic(err) 21 } 22 u := user.Current(c) 23 if u == nil { 24 return nil 25 } 26 // Map appengine/user.User to this package's User type. 27 return &User{ 28 Email: u.Email, 29 AuthDomain: u.AuthDomain, 30 Admin: u.Admin, 31 ID: u.ID, 32 FederatedIdentity: u.FederatedIdentity, 33 FederatedProvider: u.FederatedProvider, 34 } 35} 36 37func IsAdmin(ctx context.Context) bool { 38 c, err := internal.ClassicContextFromContext(ctx) 39 if err != nil { 40 panic(err) 41 } 42 43 return user.IsAdmin(c) 44} 45