Chromium Code Reviews| Index: service/user/interface.go |
| diff --git a/service/user/interface.go b/service/user/interface.go |
| index 153ed6087789db40e6d8fa93061cbe47b818d4a6..1d0dd3b70c1f34f7b9b653efa5e1206209e559fa 100644 |
| --- a/service/user/interface.go |
| +++ b/service/user/interface.go |
| @@ -4,8 +4,12 @@ |
| package user |
| -// Interface provides access to the "appengine/users" API methods. |
| -type Interface interface { |
| +import ( |
| + "golang.org/x/net/context" |
| +) |
| + |
| +// RawInterface provides access to the "appengine/users" API methods. |
| +type RawInterface interface { |
| Current() *User |
| CurrentOAuth(scopes ...string) (*User, error) |
| @@ -21,5 +25,60 @@ type Interface interface { |
| // Testable object for this service, which will let you 'log in' virtual users |
| // in your test cases. If the implementation doesn't support it, it will |
| // return nil. |
| - Testable() Testable |
| + GetTestable() Testable |
| +} |
| + |
| +// Current returns the currently logged-in user, or nil if the user is not |
| +// signed in. |
|
dnj
2016/09/01 15:25:41
Comments! Basically copy/pasted from the real user
iannucci
2016/09/16 01:01:14
sgtm, we should probably do this in more places in
dnj
2016/09/16 05:44:43
Acknowledged.
|
| +func Current(c context.Context) *User { |
| + return Raw(c).Current() |
| +} |
| + |
| +// CurrentOAuth returns the user associated with the OAuth consumer making this |
| +// request. |
| +// |
| +// If the OAuth consumer did not make a valid OAuth request, or the scopes is |
| +// non-empty and the current user does not have at least one of the scopes, this |
| +// method will return an error. |
| +func CurrentOAuth(c context.Context, scopes ...string) (*User, error) { |
| + return Raw(c).CurrentOAuth(scopes...) |
| +} |
| + |
| +// IsAdmin returns true if the current user is an administrator for this |
| +// AppEngine project. |
| +func IsAdmin(c context.Context) bool { |
| + return Raw(c).IsAdmin() |
| +} |
| + |
| +// LoginURL returns a URL that, when visited, prompts the user to sign in, then |
| +// redirects the user to the URL specified by dest. |
| +func LoginURL(c context.Context, dest string) (string, error) { |
| + return Raw(c).LoginURL(dest) |
| +} |
| + |
| +// LoginURLFederated is like LoginURL but accepts a user's OpenID identifier. |
| +func LoginURLFederated(c context.Context, dest, identity string) (string, error) { |
| + return Raw(c).LoginURLFederated(dest, identity) |
| +} |
| + |
| +// LogoutURL returns a URL that, when visited, signs the user out, then redirects |
| +// the user to the URL specified by dest. |
| +func LogoutURL(c context.Context, dest string) (string, error) { |
| + return Raw(c).LogoutURL(dest) |
| +} |
| + |
| +// OAuthConsumerKey returns the OAuth consumer key provided with the current |
| +// request. |
| +// |
| +// This method will return an error if the OAuth request was invalid. |
| +func OAuthConsumerKey(c context.Context) (string, error) { |
| + return Raw(c).OAuthConsumerKey() |
| +} |
| + |
| +// GetTestable returns a Testable for the current task queue service in c, or |
| +// nil if it does not offer one. |
| +// |
| +// The Testable instance will let you 'log in' virtual users in your test cases. |
| +func GetTestable(c context.Context) Testable { |
| + return Raw(c).GetTestable() |
| } |