本文整理汇总了Python中webapp2_extras.appengine.auth.models.User.get_by_auth_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_auth_id方法的具体用法?Python User.get_by_auth_id怎么用?Python User.get_by_auth_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webapp2_extras.appengine.auth.models.User
的用法示例。
在下文中一共展示了User.get_by_auth_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_quote
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def add_quote(title1, user_id, user_anon, provider, quote1=None, url1=None, image=None, _created=None):
try:
now = datetime.datetime.now()
if isinstance(user_id, unicode):
auth_id = '%s:%s' % (provider, user_id)
user = User.get_by_auth_id(auth_id)
else:
user = user_id
unique_user = _unique_user(user)
if _created:
created = _created
else:
created = (now - datetime.datetime(2008, 10, 1)).days
q = Post(
title=title1,
quote=quote1,
created=created,
image=image,
creator_anonymous=user_anon,
creator=user.key,
creation_order=now.isoformat()[:19] + "|" + unique_user,
uri=url1
)
q.put()
add_search_index(q.key.id(), title1, quote1, url1, image, user, user_anon)
return q.key.id()
except db.Error:
return None
示例2: set_vote
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def set_vote(quote_id, user_id, newvote, provider):
if user_id is None:
return
if isinstance(user_id, unicode):
auth_id = '%s:%s' % (provider, user_id)
user = User.get_by_auth_id(auth_id)
else:
user = user_id
email = user.email
def txn():
quote = Post.get_by_id(quote_id)
vote = Vote.get_by_id(id=email, parent=quote.key)
if vote is None:
vote = Vote(id=email, parent=quote.key)
if vote.vote == newvote:
return
quote.votesum = quote.votesum - vote.vote + newvote
vote.vote = newvote
quote.rank = "%020d|%s" % (
long(quote.created * DAY_SCALE + quote.votesum),
quote.creation_order
)
quote.put()
vote.put()
memcache.set("vote|" + email + "|" + str(quote_id), vote.vote)
ndb.transaction(txn)
示例3: add_comment
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def add_comment(user, user_anon, quote_id, text, provider):
try:
if user is None:
return
if isinstance(user, unicode):
auth_id = '%s:%s' % (provider, user)
user = User.get_by_auth_id(auth_id)
else:
user = user
quote = Post.get_by_id(long(quote_id))
comment = Comment(
parent=quote.key,
author_anonymous=user_anon,
author=user.key,
text=text
)
quote.comments += 1
quote.put()
comment.put()
memcache.set("comment|" + user.email + "|" + str(quote_id), comment.text)
except db.Error:
return None
示例4: get
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def get(self, username, term, syllabus):
# Deal with possible trailing slash
if syllabus[-1] == '/':
syllabus = syllabus[:-1]
user = User.get_by_auth_id(username)
terms = user.terms
if terms:
for t in terms:
if t.url == term.upper():
syllabi = t.syllabi
for syl in syllabi:
if syl.info.url.lower() == syllabus.lower():
if not syl.isActive:
currentUser = None
if self.user:
currentUser = ndb.Key(User, self.user['user_id']).get()
if not currentUser or username not in currentUser.auth_ids:
self.abort(403)
self.render(t, syl)
return
# Raise HTTP 404 error for syllabi that don't exist
self.abort(404)
示例5: get_user
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def get_user(self):
"""
Return the current :class:`google.appengine.api.users.User` or
``None``.
"""
user = None
auth_id = get_param(self.request.headers, _AUTH_ID_HEADER_KEY)
if auth_id:
try:
user = User.get_by_auth_id(auth_id)
except BadRequestError:
_log.exception('Error getting user by auth_id: {}'.format(
auth_id))
return user
示例6: get
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def get(self, username, term):
# TODO: Render weekly calendar template
term = term.upper()
user = User.get_by_auth_id(username)
if user:
terms = Term.query(ancestor = user.key).fetch()
for t in terms:
if t.url == term:
return self.render(user, t)
# Raise HTTP 404 error for terms not yet available
self.abort(404)
示例7: post
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def post(self):
email = self.request.POST.get('email')
auth_id = "own:%s" % email
user = User.get_by_auth_id(auth_id)
if user is not None:
# Send Message Received Email
taskqueue.add(url='/emails/password/reset', params={
'recipient_id': user.key.id(),
})
_message = 'Password reset instruction have been sent to %s. Please check your inbox.' % email
self.add_message(_message, 'success')
return self.redirect_to('login')
_message = 'Your email address was not found. Please try another or <a href="/register">create an account</a>.'
self.add_message(_message, 'error')
return self.redirect_to('password-reset')
示例8: user
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_id [as 别名]
def user(self):
auth_id = self.session.get('user', None)
if auth_id:
return User.get_by_auth_id(auth_id)