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


Python OAuth2Token.add方法代码示例

本文整理汇总了Python中past.model.user.OAuth2Token.add方法的典型用法代码示例。如果您正苦于以下问题:Python OAuth2Token.add方法的具体用法?Python OAuth2Token.add怎么用?Python OAuth2Token.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在past.model.user.OAuth2Token的用法示例。


在下文中一共展示了OAuth2Token.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_result

# 需要导入模块: from past.model.user import OAuth2Token [as 别名]
# 或者: from past.model.user.OAuth2Token import add [as 别名]
    def check_result(self, uri, resp, content):
        user_id = self.user_alias and self.user_alias.user_id or None
        excp = OAuthTokenExpiredError(user_id,
                config.OPENID_TYPE_DICT[config.OPENID_DOUBAN], content)
        jdata = json_decode(content) if content else None
        if str(resp.status) == "200":
            excp.clear_the_profile()
            return jdata

        log.warning("get %s fail, status code=%s, msg=%s. go to refresh token" \
            % (uri, resp.status, content))
        if jdata and isinstance(jdata, dict):
            error_code = jdata.get("code") 
            if str(error_code) == "103" or str(error_code) == "123":
                excp.set_the_profile()
                raise excp
            elif str(error_code) == "106" and self.user_alias:
                try:
                    new_tokens = super(Douban, self).refresh_tokens()
                    if new_tokens and isinstance(new_tokens, dict):
                        OAuth2Token.add(self.user_alias.id, 
                                new_tokens.get("access_token"), 
                                new_tokens.get("refresh_token"))
                        excp.clear_the_profile()
                except OAuthError, e:
                    log.warn("refresh token fail: %s" % e)
                    excp.set_the_profile()
                    raise e
开发者ID:EdwinHi,项目名称:thepast,代码行数:30,代码来源:douban.py

示例2: _save_user_and_token

# 需要导入模块: from past.model.user import OAuth2Token [as 别名]
# 或者: from past.model.user.OAuth2Token import add [as 别名]
def _save_user_and_token(token_dict, user_info, openid_type):
    ua = UserAlias.get(openid_type, user_info.get_user_id())
    if not ua:
        if not g.user:
            ua = UserAlias.create_new_user(openid_type,
                    user_info.get_user_id(), user_info.get_nickname())
        else:
            ua = UserAlias.bind_to_exists_user(g.user, 
                    openid_type, user_info.get_user_id())
    if not ua:
        return None

    ##设置个人资料(头像等等)
    u = User.get(ua.user_id)
    u.set_avatar_url(user_info.get_avatar())
    u.set_icon_url(user_info.get_icon())

    ##保存access token
    if openid_type == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("access_token_secret", ""))
    else:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("refresh_token", ""))
    ##set cookie,保持登录状态
    if not g.user:
        g.user = User.get(ua.user_id)
        set_user_cookie(g.user, session)
    
    return g.user
开发者ID:perryhau,项目名称:thepast,代码行数:32,代码来源:views.py

示例3: _save_user_and_token

# 需要导入模块: from past.model.user import OAuth2Token [as 别名]
# 或者: from past.model.user.OAuth2Token import add [as 别名]
def _save_user_and_token(token_dict, thirdparty_user, openid_type):
    first_connect = False
    ua = UserAlias.get(openid_type, thirdparty_user.get_user_id())
    if not ua:
        if not g.user:
            ua = UserAlias.create_new_user(openid_type,
                    thirdparty_user.get_user_id(), thirdparty_user.get_nickname())
        else:
            ua = UserAlias.bind_to_exists_user(g.user, 
                    openid_type, thirdparty_user.get_user_id())
        first_connect = True
    if not ua:
        return None

    ##设置个人资料(头像等等)
    u = User.get(ua.user_id)
    u.set_avatar_url(thirdparty_user.get_avatar())
    u.set_icon_url(thirdparty_user.get_icon())

    ##把各个第三方的uid保存到profile里面
    k = openid_type
    v = {
        "uid": thirdparty_user.get_uid(), 
        "name": thirdparty_user.get_nickname(), 
        "intro": thirdparty_user.get_intro(),
        "signature": thirdparty_user.get_signature(),
        "avatar": thirdparty_user.get_avatar(),
        "icon": thirdparty_user.get_icon(),
        "email": thirdparty_user.get_email(),
        "first_connect": "Y" if first_connect else "N",
    }
    u.set_profile_item(k, json_encode(v))

    ##保存access token
    if openid_type == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("access_token_secret", ""))
    else:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("refresh_token", ""))
    ##set cookie,保持登录状态
    if not g.user:
        g.user = User.get(ua.user_id)
        set_user_cookie(g.user, session)
    
    return g.user
开发者ID:loosky,项目名称:thepast,代码行数:48,代码来源:view.py

示例4: _request

# 需要导入模块: from past.model.user import OAuth2Token [as 别名]
# 或者: from past.model.user.OAuth2Token import add [as 别名]
    def _request(self, api, method="POST", extra_dict=None):
        if extra_dict is None:
            extra_dict = {}

        params = {
            "method": api,
            "v": "1.0",
            "access_token": self.access_token,
            "format": "json",
        }
        params.update(extra_dict)
        _, qs = Renren.sign(self.apikey_secret, **params)
        uri = "%s?%s" % (self.api_host, qs)

        log.info('getting %s...' % uri)
        resp, content = httplib2_request(uri, method)
        if resp.status == 200:
            user_id = self.user_alias and self.user_alias.user_id or None
            excp = OAuthTokenExpiredError(user_id=None,
                    openid_type=config.OPENID_TYPE_DICT[config.OPENID_RENREN], 
                    msg=content)
            jdata = json_decode(content) if content else None
            if jdata and isinstance(jdata, dict):
                error_code = jdata.get("error_code")
                error_msg = jdata.get("error_msg")
                if error_code:
                    if str(error_code) == "105":
                        ## 无效的token
                        excp.set_the_profile()
                        raise excp
                    elif str(error_code) == "106" and self.user_alias:
                        ## FIXME: 过期的token, 是不是106?
                        try:
                            new_tokens = super(Renren, self).refresh_tokens()
                            if new_tokens and isinstance(new_tokens, dict):
                                OAuth2Token.add(self.user_alias.id, 
                                        new_tokens.get("access_token"), 
                                        new_tokens.get("refresh_token"))
                                excp.clear_the_profile()
                        except OAuthError, e:
                            log.warn("refresh token fail: %s" % e)
                            excp.set_the_profile()
                            raise e
            return jdata
开发者ID:EdwinHi,项目名称:thepast,代码行数:46,代码来源:renren.py

示例5: update_tokens

# 需要导入模块: from past.model.user import OAuth2Token [as 别名]
# 或者: from past.model.user.OAuth2Token import add [as 别名]
    def update_tokens(self, refresh_token):
        qs = {}
        qs["client_id"] = self.apikey
        qs["client_secret"] = self.apikey_secret
        qs["redirect_uri"] = self.redirect_uri
        qs["grant_type"] = "refresh_token"
        qs["refresh_token"] = refresh_token

        resp, content = httplib2_request(self.access_token_uri, "POST", 
            body=urllib.urlencode(qs))
        if resp.status != 200:
            raise OAuthLoginError('refres_tokens fail, status=%s:reason=%s:content=%s' \
                    %(resp.status, resp.reason, content))
        r = json_decode(content)
        
        return OAuth2Token.add(r.get("douban_user_id"), r.get("access_token"), r.get("refresh_token"))
开发者ID:Ailocodjam,项目名称:thepast,代码行数:18,代码来源:oauth_login.py


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