An instance of the User class represents an authenticated user of the app.
User
is provided by the
google.appengine.api.users
module.
- Introduction
- User()
- Instance methods:
Introduction
An instance of the User class represents an authenticated user of the application. The user is authenticated using the authentication option set for the app: either Google Accounts, Google Apps account, or OpenID. (Note that the support for OpenID is experimental.) An app can get a User instance that represents the user currently signed in to the application by calling the constructor with no arguments, or by calling the users.get_current_user() function. If the current user is not signed in, the User constructor raises a UserNotFoundError . (users.get_current_user() does not raise an exception if the user is not signed in.)
User objects are comparable.
If two User objects are equal, then both objects represent the same user.
However, be careful: if you store a user's User object and then that user
changes their email address, a new User object won't match the stored one.
If you need an ID that represents the user regardless of account changes,
use
user_id()
.
Constructor
- class User ( email = None , federated_identity = None )
-
Represents an authenticated user of the app.
Arguments
-
The email address of the desired user. If omitted, the object will represent the current user (the user making the request). If no address is given and the current user is not signed in, a UserNotFoundError is raised.
Only RFC compliant email addresses can match a real user. You can, however, store non-RFC-compliant email addresses in the datastore.
- federated_identity
-
The OpenID identifier of the desired user.
Instance Methods
A User instance provides the following methods:
- nickname ()
-
Returns the "nickname" of the user, a displayable name. For Google Accounts users, the nickname is either the "name" portion of the user's email address if the address is in the same domain as the application, or the user's full email address otherwise. For OpenID users, the nickname is the OpenID identifier.
- email ()
-
Returns the email address of the user. If you use OpenID, you should not rely on this email address to be correct. Applications should use nickname for displayable names.
- user_id ()
-
If the email address is associated with a Google account,
user_id
returns the unique permanent ID of the user, astr
. This ID is always the same for the user regardless of whether the user changes her email address.If the email address is not associated with a Google account,
user_id
returnsNone
.Note: If your application constructs the
User
instance, the API will not set a value foruser_id
and it returnsNone
. - federated_identity ()
-
Returns the user's OpenID identifier.
- federated_provider ()
-
Returns the URL of the user's OpenID provider.