本文整理汇总了Python中models.Profile.from_name方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.from_name方法的具体用法?Python Profile.from_name怎么用?Python Profile.from_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.from_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: session_auth
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import from_name [as 别名]
def session_auth(session,request,this_url):
#Function that manages the session status.
if session.get('key'):
#If the cookie is found, get the key and look for the session data in the database
session_data = ndb.Key(urlsafe = session.get('key')).get()
#If the page is visited from the twitter authentication callback, it will receive the oauth_verifier parameter
if request.get('oauth_verifier'):
oauth_verifier = request.get('oauth_verifier')
oauth_token = request.get('oauth_token')
twitter = Twython(APP_KEY, APP_SECRET,
session_data.oauth_token,
session_data.oauth_token_secret)
#The twitter authentication returns oauth_token, and it is compared with the original token
if session_data.oauth_token == oauth_token:
final_step = twitter.get_authorized_tokens(oauth_verifier)
session_data.oauth_token = final_step['oauth_token']
session_data.oauth_token_secret = final_step['oauth_token_secret']
session_data.oauth_verifier = oauth_verifier
auth = Twython(APP_KEY, APP_SECRET,
session_data.oauth_token,
session_data.oauth_token_secret)
credentials = auth.verify_credentials()
session_data.username = credentials['screen_name']
session_data.credentials = credentials
#Check if profile exists
profile = Profile.from_name(credentials['screen_name'])
if not profile:
Profile(
name = credentials['screen_name'],
reputation = 0
).put()
key = session_data.put()
session['key'] = key.urlsafe()
return 'LOGGED_IN', credentials
# If the tokens are not equal, an exception is raised.
else:
return 'ERROR', None
elif session_data.oauth_verifier:
# auth = Twython(APP_KEY, APP_SECRET,
# session_data.oauth_token,
# session_data.oauth_token_secret)
# credentials = auth.verify_credentials()
credentials = session_data.credentials
return 'LOGGED_IN', credentials
else:
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(this_url)
session_data = Session(oauth_token = auth['oauth_token'],
oauth_token_secret = auth['oauth_token_secret'])
key = session_data.put()
session['key'] = key.urlsafe()
return 'ANONYMOUS', auth['auth_url']
else:
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(this_url)
session_data = Session(oauth_token = auth['oauth_token'],
oauth_token_secret = auth['oauth_token_secret'])
key = session_data.put()
session['key'] = key.urlsafe()
return 'ANONYMOUS', auth['auth_url']