Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Unified Diff: impl/prod/user.go

Issue 1500433002: Add User service. (Closed) Base URL: https://github.com/luci/gae.git@inner_ctx
Patch Set: method Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/prod/context.go ('k') | service/user/context.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/prod/user.go
diff --git a/impl/prod/user.go b/impl/prod/user.go
new file mode 100644
index 0000000000000000000000000000000000000000..7d8ad2a098ed68f8373e10af706326c675a8cd57
--- /dev/null
+++ b/impl/prod/user.go
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package prod
+
+import (
+ gae_user "github.com/luci/gae/service/user"
+ "golang.org/x/net/context"
+ "google.golang.org/appengine/user"
+)
+
+// useUser adds a user service implementation to context, accessible
+// by "github.com/luci/gae/service/user".Get(c)
+func useUser(c context.Context) context.Context {
+ return gae_user.SetFactory(c, func(ci context.Context) gae_user.Interface {
+ return userImpl{AEContext(ci)}
+ })
+}
+
+type userImpl struct {
+ aeCtx context.Context
+}
+
+func (u userImpl) IsAdmin() bool {
+ return user.IsAdmin(u.aeCtx)
+}
+
+func (u userImpl) LoginURL(dest string) (string, error) {
+ return user.LoginURL(u.aeCtx, dest)
+}
+
+func (u userImpl) LoginURLFederated(dest, identity string) (string, error) {
+ return user.LoginURLFederated(u.aeCtx, dest, identity)
+}
+
+func (u userImpl) LogoutURL(dest string) (string, error) {
+ return user.LogoutURL(u.aeCtx, dest)
+}
+
+func (u userImpl) Current() *gae_user.User {
+ return (*gae_user.User)(user.Current(u.aeCtx))
+}
+
+func (u userImpl) CurrentOAuth() (*gae_user.User, error) {
+ usr, err := user.CurrentOAuth(u.aeCtx)
+ if err != nil {
+ return nil, err
+ }
+ return (*gae_user.User)(usr), nil
+}
+
+func (u userImpl) OAuthConsumerKey() (string, error) {
+ return user.OAuthConsumerKey(u.aeCtx)
+}
« no previous file with comments | « impl/prod/context.go ('k') | service/user/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698