[Google App Engine] User Objects (Japanese translation)

Original If you have any mistranslations, please let us know.

User Objects (Note: The OpenID features mentioned on this page are expected to be deprecated and removed. For more information, see OpenID 2.0 Support Turndown. See / open_id).)

An instance of the User class represents a user. User instances can be compared with their own. If the two instances are the same, then they belong to the same user. The application calls the users.get_current_user () function for that user. You can access the User instance.

from google.appengine.api import users

user = users.get_current_user()
if not user:
    # The user is not signed in.
else:
    print "Hello, %s!" % user.nickname()

You can use the users.get_current_user () function regardless of which authentication option you use for your application. A User instance can be said to consist of an email address.

user = users.User("[email protected]")

Alternatively, if you have federated_identity, you can also use the User instance as below.

user = users.User(federated_identity="http://example.com/id/ajohnson")

If User's content is called with an email address that does not match your existing Google account, a new User Object will be created, which will not match your actual Google account. This also happens when someone creates another Google account after their User Object is registered in the database. User information that has already been registered will not match when a new Google account is created. When running the development server, all registered User objects will be treated as valid Google accounts. A valid user's User object gives each user a unique ID that doesn't change until the user changes their email address. The user_id () method returns the ID as a string. No matter which authentication method you use in your application, the User object has the same form. If you change the authentication option from your Google account to OpenID, your existing User object will remain valid.

How to use User object in datastore

The user ID is fixed. The user ID can be used as a key name or a character string. Therefore, when using User information, you probably want to save your user ID (and maybe your most recent email address to communicate with the user by email). The example below shows how to match the user with the user ID.

from google.appengine.api import users
from google.appengine.ext import ndb

class UserPrefs(ndb.Model):
    userid = ndb.StringProperty()

user = users.get_current_user()
if user:
    q = ndb.gql("SELECT * FROM UserPrefs WHERE userid = :1", user.user_id())
    userprefs = q.get()

We strongly recommend that you do not store the UserProperty in the database as it contains your email address and your unique ID. If the user changes their email address, trying to match the saved old User with the new User will not match. Instead, it's better to provide a user-specific ID and match it.

Recommended Posts

[Google App Engine] User Objects (Japanese translation)
Save in Japanese to StringProperty in Google App Engine data store
Google App Engine development with Docker
Java 1 1 support from Google App Engine
Use ndb.tasklet on Google App Engine
[Python] Run Flask on Google App Engine
Use external modules on Google App Engine
I can't deploy with google app engine
Tweet (API 1.1) on Google App Engine for Python
sosreport Japanese translation
Google App Engine Datastore and Search API integration
Deploy a Django application on Google App Engine (Python3)
Google App Engine / Python development environment construction procedure (late 2014)
(Beginner) Basic usage of Datastore on Google App Engine
PIL with Python on Windows 8 (for Google App Engine)
Getting Started with Google App Engine for Python & PHP
How to use Django on Google App Engine / Python
Runtime version of Google App Engine / Python Standard Environment
man systemd Japanese translation
streamlit explanation Japanese translation
streamlit tutorial Japanese translation
man systemd.service Japanese translation
man nftables Japanese translation
Dockerfile reference Japanese translation
docker-compose --help Japanese translation
docker help Japanese translation
Hello World with Google App Engine (Java 8) + Spring Boot + Gradle
Hello World with Google App Engine (Java 8) + Servlet API 3.1 + Gradle
Pandas User Guide "Manipulating Missing Data" (Official Document Japanese Translation)
Deploy your Go app on Google App Engine with GitHub Actions
Hello World with Google App Engine (Java 11) + Spring Boot + Gradle