本文整理汇总了Python中model.User.get_by_google_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_google_user方法的具体用法?Python User.get_by_google_user怎么用?Python User.get_by_google_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.get_by_google_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_google_user [as 别名]
def get_user(self, invite_code_name=None):
user = None
google_user = users.get_current_user()
# not logged in to google
if google_user == None:
self.redirect(users.create_login_url(self.request.uri))
return None
user = User.get_by_google_user(google_user)
# user was not in our database, so its a first-time login
if user == None:
user = User(google_user = google_user,
first_name='',
last_name='',
email=google_user.email()
)
user.put()
# now we have a user, but are they whitelisted
# or do they have an invite?
if invite_code_name != None:
invite_code = InviteCode.get_by_name(invite_code_name)
# is this code valid?
if invite_code != None and invite_code.use_code() == True:
user.is_whitelisted = True
user.put()
else:
user = None
elif user.is_whitelisted != True:
user = None
# this enables admins to see pages in any user's context
if self.request.get('admin', None) == 'true' and user.email in admins:
user_email = self.request.get('user_email')
user = User.get_by_email(user_email)
# if we've gotten this far and the user is none, it means this user is
# not whitelisted
if user == None:
self.redirect(users.create_logout_url('/no-invite'))
return user
示例2: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_google_user [as 别名]
def get(self):
google_user = users.get_current_user()
if google_user != None:
user = User.get_by_google_user(google_user)
if user != None and user.is_whitelisted:
self.redirect('/dashboard');
else:
self.redirect(users.create_logout_url('/no-invite'))
f = open('ui/html/home.html')
html = f.read()
login_url = users.create_login_url(self.request.uri)
params = {
'login_url': login_url,
'template_metrics': TemplateMetric.json_list()
}
html = html % params
self.response.out.write(html)