本文整理匯總了Python中account.models.UserProfile.evernote_token_expires_time方法的典型用法代碼示例。如果您正苦於以下問題:Python UserProfile.evernote_token_expires_time方法的具體用法?Python UserProfile.evernote_token_expires_time怎麽用?Python UserProfile.evernote_token_expires_time使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類account.models.UserProfile
的用法示例。
在下文中一共展示了UserProfile.evernote_token_expires_time方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: login_evernote_token
# 需要導入模塊: from account.models import UserProfile [as 別名]
# 或者: from account.models.UserProfile import evernote_token_expires_time [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=[]))