本文整理汇总了Python中google.appengine.api.users.get_current_user方法的典型用法代码示例。如果您正苦于以下问题:Python users.get_current_user方法的具体用法?Python users.get_current_user怎么用?Python users.get_current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.users
的用法示例。
在下文中一共展示了users.get_current_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_email
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def get_user_email():
"""Retrieves the currently logged in user email.
Returns:
A string of the email address of the current user.
Raises:
UserNotFound: Raised if a user is not currently logged in.
"""
try:
current_user = endpoints.get_current_user() or users.get_current_user()
except endpoints.InvalidGetUserCall:
current_user = users.get_current_user()
if current_user:
return current_user.email()
raise UserNotFound('get_user_email failed: No user account detected.')
示例2: testGetTestSetFromResultString
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def testGetTestSetFromResultString(self):
current_user = users.get_current_user()
u = models.user_test.User.get_or_insert(current_user.user_id())
test = models.user_test.Test(user=u, name='Fake Test',
url='http://fakeurl.com/test.html',
description='stuff')
test.save()
results_str = 'test_1=0,test_2=1'
test_set_category = 'usertest_%s' % test.key()
test_set = models.user_test.Test.get_test_set_from_results_str(
test_set_category, results_str)
self.assertTrue(test_set != None)
self.assertEqual(test_set.category, test_set_category)
self.assertEqual(len(test_set.tests), 2)
self.assertEqual('test_1', test_set.tests[0].key)
self.assertEqual('test_2', test_set.tests[1].key)
示例3: get
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
items = Matrix.all()
for item in items:
logging.info('item key %s blob_key %s, filename %s ', item.key.urlsafe(), item.file_key, item.filename)
length = len(items)
upload_url = blobstore.create_upload_url("/test_upload_blob")
self.response.out.write(self.template_env.get_template("blobs.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url,
"top_form_url": "test_db_datastore"}))
示例4: get
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def get(self):
logging.info(os.path.abspath(os.path.curdir))
logging.info('Peer Belt Driver get method called!')
user = users.get_current_user()
username = user.nickname()
results = BlobDataset.query()
items = [result for result in results]
for item in items:
item.ds_key = item.key.urlsafe()
length = len(items)
upload_url = create_upload_url("upload_blob2")
self.response.out.write(self.template_env.get_template("blobs2.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url}))
示例5: get
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def get(self):
user = users.get_current_user()
username = user.nickname()
items = DatasetPB.all()
# items = [result for result in results.fetch(10)]
# for item in items:
# logging.info('fn %s', item.blob_key)
length = len(items)
upload_url = blobstore.create_upload_url("/upload_blob")
# Datazz.create(u'fn1', 'ol1')
# Datazz.all()
# Datazz.create('fn1', 'ol2')
# Datazz.create('fn2', 'ol3')
# Datazz.all()
self.response.out.write(self.template_env.get_template("blobs.html").render(
{"username": username,
"items": items,
"length": length,
"upload_url": upload_url,
"top_form_url": "blobs"}))
示例6: post
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def post(self):
source = "uploaded by user"
upload_files = self.get_uploads("file")
blob_key = upload_files[0].key()
name = self.request.get("name")
user = users.get_current_user()
username = user.nickname()
date = datetime.datetime.now()
str_blob_key = str(blob_key)
key = FileMetadata.getKeyName(username, date, str_blob_key)
m = FileMetadata(key_name = key)
m.owner = user
m.filename = name
m.uploadedOn = date
m.source = source
m.blobkey = str_blob_key
m.put()
self.redirect("/mr")
示例7: post
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def post(self):
user = users.get_current_user()
if not user:
# This should never happen, as AppEngine should only run this
# handler if the user is signed in. But defense in depth applies...
self.redirect(users.create_login_url(self.request.uri))
return
older_than_id = self.request.get('older_than')
older_than = datetime.datetime.strptime(older_than_id,
"%Y-%m-%dT%H:%M:%S.%f")
query = Message.query(ancestor=messages_key()).filter(Message.date <
older_than
).order(-Message.date)
# Limit query to 50 messages:
query_results = query.fetch(50)
if len(query_results) > 0:
broadcast = MessagesBroadcast(query_results)
broadcast.send_messages(user.user_id())
示例8: _SafelyGetCurrentUserEmail
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def _SafelyGetCurrentUserEmail():
"""Retrieve the current user's email or raise an exception.
We set 'login: required' in app.yaml so all users should be logged-in.
But, is has been observed that users.get_current_user() *can* return None.
Therefore, this must be checked.
Returns:
String email address of the currently logged-in user.
Raises:
MessageRecallAuthenticationError: If current user is noticed as None.
"""
user = None
get_user_attempts = 0
while not user and get_user_attempts < _GET_USER_MAX_RETRIES:
user = users.get_current_user()
get_user_attempts += 1
if not user:
raise recall_errors.MessageRecallAuthenticationError(
'A logged-in user was not retrieved. Please try again.')
return user.email()
示例9: get
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url('/account'))
return
email = user.email()
action = 'Create'
account, nickname = yield (get_account(user.user_id()),
get_nickname(user.user_id()))
if account is not None:
action = 'Update'
if account:
proposed_nickname = account.nickname or account.email
else:
proposed_nickname = email
values = {'email': email,
'nickname': nickname,
'proposed_nickname': proposed_nickname,
'login': users.create_login_url('/home'),
'logout': users.create_logout_url('/home'),
'action': action,
}
self.response.out.write(ACCOUNT_PAGE % values)
示例10: post
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def post(self):
# TODO: XSRF protection.
@ndb.tasklet
def helper():
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url('/account'))
return
account = yield get_account(user.user_id())
if self.request.get('delete'):
if account:
yield account.key.delete_async()
self.redirect('/account')
return
if not account:
account = Account(key=account_key(user.user_id()),
email=user.email(), userid=user.user_id())
nickname = self.request.get('nickname')
if nickname:
account.nickname = nickname
yield account.put_async()
self.redirect('/account')
yield ndb.transaction_async(helper)
示例11: post
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def post(self):
"""Handle post request."""
template_values = {
'back_url': '/showCredentials',
'back_msg': 'View Credentials',
'logout_url': users.create_logout_url('/'),
'user_nickname': users.get_current_user().nickname()
}
try:
UpdateUserCredentials(self.request.get('client_id'),
self.request.get('client_secret'),
self.request.get('refresh_token'),
self.request.get('adwords_manager_cid'),
self.request.get('dev_token'))
self.redirect('/showCredentials')
except Exception as e:
template_values['error'] = str(e)
# Use template to write output to the page.
path = os.path.join(os.path.dirname(__file__),
'../templates/base_template.html')
self.response.out.write(template.render(path, template_values))
示例12: InitUser
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def InitUser():
"""Initialize application user.
Retrieve existing user credentials from datastore or add new user.
Returns:
AppUser instance of the application user.
"""
result = AppUser.query(AppUser.user == users.get_current_user()).fetch()
if result:
app_user = result[0]
else:
app_user = AppUser(user=users.get_current_user(),
email=users.get_current_user().email())
app_user.put()
return app_user
示例13: UpdateUserCredentials
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def UpdateUserCredentials(client_id, client_secret, refresh_token,
adwords_manager_cid, developer_token):
"""Update the credentials associated with application user.
Args:
client_id: str Client Id retrieved from the developer's console.
client_secret: str Client Secret retrieved from the developer's console.
refresh_token: str Refresh token generated with the above client id/secret.
adwords_manager_cid: str Customer Id for the AdWords manager account.
developer_token: str Developer Token for the AdWords account.
"""
app_user = AppUser.query(AppUser.user == users.get_current_user()).fetch()[0]
app_user.client_id = client_id
app_user.client_secret = client_secret
app_user.refresh_token = refresh_token
app_user.adwords_manager_cid = adwords_manager_cid
app_user.developer_token = developer_token
app_user.put()
示例14: test_opened
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def test_opened(app, monkeypatch):
with mock.patch(
"google.auth.transport.requests.AuthorizedSession.request", autospec=True
) as auth_session:
data = {'access_token': '123'}
auth_session.return_value = MockResponse(data, http_client.OK)
firetactoe.Game(id='razem', userX=users.get_current_user()).put()
app.post('/opened?g=razem', status=200)
auth_session.assert_called_once_with(
mock.ANY, # AuthorizedSession object
method="PATCH",
url="http://firebase.com/test-db-url/channels/38razem.json",
body='{"winner": null, "userX": "38", "moveX": null, "winningBoard": null, "board": null, "userO": null}',
data=None,
)
示例15: test_move
# 需要导入模块: from google.appengine.api import users [as 别名]
# 或者: from google.appengine.api.users import get_current_user [as 别名]
def test_move(app, monkeypatch):
with mock.patch(
"google.auth.transport.requests.AuthorizedSession.request", autospec=True
) as auth_session:
data = {'access_token': '123'}
auth_session.return_value = MockResponse(data, http_client.OK)
firetactoe.Game(
id='razem', userX=users.get_current_user(), board=9*' ',
moveX=True).put()
app.post('/move?g=razem', {'i': 0}, status=200)
game = ndb.Key('Game', 'razem').get()
assert game.board == 'X' + (8 * ' ')
auth_session.assert_called_once_with(
mock.ANY, # AuthorizedSession object
method="PATCH",
url="http://firebase.com/test-db-url/channels/38razem.json",
body='{"winner": null, "userX": "38", "moveX": false, "winningBoard": null, "board": "X ", "userO": null}',
data=None,
)