当前位置: 首页>>代码示例>>Python>>正文


Python UserProfile.evernote_token_expires_time方法代码示例

本文整理汇总了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=[]))
开发者ID:amcglathery,项目名称:evernote_minihack,代码行数:41,代码来源:views.py


注:本文中的account.models.UserProfile.evernote_token_expires_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。