本文整理汇总了Python中account.models.UserProfile.evernote_token方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.evernote_token方法的具体用法?Python UserProfile.evernote_token怎么用?Python UserProfile.evernote_token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.evernote_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_evernote_token
# 需要导入模块: from account.models import UserProfile [as 别名]
# 或者: from account.models.UserProfile import evernote_token [as 别名]
def login_evernote_token(request):
""" as get_evernote_token(), but logs the user in as well
"""
everAuth = EvernoteAPI()
credentials = everAuth.get_user_token(request)
if not credentials:
return HttpResponseRedirect(reverse('account.views.login_page', args=[]))
if request.user.is_authenticated():
user = request.user
else:
evernoteHost = settings.EVERNOTE_HOST
userStoreUri = "https://" + evernoteHost + "/edam/user"
userStoreHttpClient = THttpClient.THttpClient(userStoreUri)
userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
userStore = UserStore.Client(userStoreProtocol)
evernoteUser = userStore.getUser(credentials['oauth_token'])
user = authenticate(username=evernoteUser.username, password=str(evernoteUser.id))
if not user:
newUser = User.objects.create_user(evernoteUser.username, evernoteUser.email, str(evernoteUser.id))
names = evernoteUser.name.split() if evernoteUser.name else None
newUser.first_name = names[0] if names and len(names) > 0 else ""
newUser.last_name = names[1] if names and len(names) > 1 else ""
newUser.save()
user = authenticate(username=evernoteUser.username, password=str(evernoteUser.id))
login(request, user)
try:
expires_time = datetime.fromtimestamp(int(credentials['expires']))
except TypeError:
logging.error("Error parsing token expires time")
expires_time = datetime.now()
profile = UserProfile()
profile.user = user
profile.evernote_token = credentials['oauth_token']
profile.evernote_token_expires_time = expires_time
profile.evernote_note_store_url = credentials['edam_noteStoreUrl']
profile.save()
return HttpResponseRedirect(reverse('base.views.index', args=[]))