Ejemplo n.º 1
0
def auth_bind_for_qq(request,access_token,openid,bind_access_token,bind_openid):
    """论证qq开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://open.t.qq.com/api/user/info?format=json&oauth_consumer_key=%s&access_token=%s&openid=%s&oauth_version=2.a&scope=all' % (settings.QQ_APP_ID,access_token,openid)

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,msg,pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc = url_request.code
        res  = url_request.read()
        res = res.strip()
        res = res.replace('false','False')
        res = res.replace('true','True')
        res = res.replace('null','None')
        if rc == 200:
            exec('result = %s' % res)
            if not result['ret']:
                get_openid = str(result['data']['openid'])
                if get_openid == openid:
                    fg, pid, msg = _bind_new_platform(request, 'qq', openid, account, result)
                    return fg, pid, msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Ejemplo n.º 2
0
def auth_bind_for_qq(request, access_token, openid, bind_access_token,
                     bind_openid):
    """论证qq开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://open.t.qq.com/api/user/info?format=json&oauth_consumer_key=%s&access_token=%s&openid=%s&oauth_version=2.a&scope=all' % (
        settings.QQ_APP_ID, access_token, openid)

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login', 'invalid_bind')
        return fg, msg, pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc = url_request.code
        res = url_request.read()
        res = res.strip()
        res = res.replace('false', 'False')
        res = res.replace('true', 'True')
        res = res.replace('null', 'None')
        if rc == 200:
            exec('result = %s' % res)
            if not result['ret']:
                get_openid = str(result['data']['openid'])
                if get_openid == openid:
                    fg, pid, msg = _bind_new_platform(request, 'qq', openid,
                                                      account, result)
                    return fg, pid, msg
    else:
        msg = get_msg('login', 'invalid_bind')
    return fg, pid, msg
Ejemplo n.º 3
0
def auth_token_for_oc(request,access_token,openid,uuid,mktid,version,client_type,macaddr,idfa,ios_ver):
    """论证无账号用户
    """
    print "debug_guochen access_token, openid", access_token, openid
    fg = False
    pid = ''
    msg = ''
    subarea = request.REQUEST.get("subarea", "1") or '1'
    #没有openid时,检查后控制自动分配id的开头是否开启,如果已经关闭,返回提示
    if not openid:
       if game_config.system_config.get('account_assign_switch'):
           fg = True
           pid = get_uuid()
           #验证成功,安装用户
           request.rk_user = UserBase._install(pid,'oc',uuid,mktid,version,client_type,macaddr,idfa,ios_ver, subarea=subarea)
           access_token = get_upwd()
           request.rk_user.account.update_info(pid, access_token)
       else:
           msg = get_msg('login','cannot_register')
           return fg,pid,msg
    if not check_openid(openid):
        msg = get_msg('login','cannot_register')
        return fg,pid,msg
    #有openid时,检查access_token是否正确
    account = AccountMapping.get(openid)
    if not account: 
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = openid
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,'oc',uuid,mktid,version,client_type,macaddr,idfa,ios_ver, subarea=subarea)
            # debug 模式下,将传入的access_token 作为新用户taken
            if settings.DEBUG is True:
                access_token = access_token or get_upwd()
            else:
                access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
            account = request.rk_user.account
            print "debug_guochen_new_token pid, access_token, openid", pid, access_token, openid
        else:
            msg = get_msg('login','cannot_register')
            return fg,pid,msg

    elif account.access_token == access_token:
        fg = True
        pid = openid
        #验证成功,安装用户
        request.rk_user = UserBase._install(pid, 'oc', subarea=subarea)
    else:
        print "debug_guochen_erro_token pid, access_token, openid", pid, access_token, openid
        msg = get_msg('login','session_overdue')
    return fg,pid,msg
Ejemplo n.º 4
0
def auth_bind_for_sina(request, access_token, openid, bind_access_token,
                       bind_openid):
    """论证sina开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    SINA_OPEN_URL = 'https://api.weibo.com/2/account/get_uid.json'
    request_url = '%s?access_token=%s' % (SINA_OPEN_URL, str(access_token))
    user_info_url = 'https://api.weibo.com/2/users/show.json?access_token=%s&uid=%s'

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login', 'invalid_bind')
        return fg, msg, pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(request_url, timeout=12)
        rc = url_request.code
        res = url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false', 'False')
            res = res.replace('true', 'True')
            res = res.replace('null', 'None')
            exec('result = %s' % res)
            get_openid = str(result.get('uid'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'sina', openid,
                                                  account, result)

                #调用平台的api,取得用户名等信息,并且更新
                user_info_url = user_info_url % (str(access_token),
                                                 str(openid))
                #更新用户平台信息不影响绑定操作
                try:
                    res = urllib2.urlopen(str(user_info_url),
                                          timeout=12).read()
                    res = res.strip()
                    res = res.replace('false', 'False')
                    res = res.replace('true', 'True')
                    res = res.replace('null', 'None')
                    exec('result = %s' % res)
                    request.rk_user.update_user_from_sina(result)
                except:
                    pass
                return fg, pid, msg
    else:
        msg = get_msg('login', 'invalid_bind')
    return fg, pid, msg
Ejemplo n.º 5
0
def auth_bind_for_sina(request,access_token,openid,bind_access_token,bind_openid):
    """论证sina开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    SINA_OPEN_URL = 'https://api.weibo.com/2/account/get_uid.json'
    request_url = '%s?access_token=%s' % (SINA_OPEN_URL, str(access_token))
    user_info_url = 'https://api.weibo.com/2/users/show.json?access_token=%s&uid=%s'

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,msg,pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(request_url, timeout=12)
        rc = url_request.code
        res  = url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false','False')
            res = res.replace('true','True')
            res = res.replace('null','None')
            exec('result = %s' % res)
            get_openid = str(result.get('uid'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'sina', openid, account, result)

                #调用平台的api,取得用户名等信息,并且更新
                user_info_url = user_info_url % (str(access_token),str(openid))
                #更新用户平台信息不影响绑定操作
                try:
                    res = urllib2.urlopen(str(user_info_url), timeout=12).read()
                    res = res.strip()
                    res = res.replace('false','False')
                    res = res.replace('true','True')
                    res = res.replace('null','None')
                    exec('result = %s' % res)
                    request.rk_user.update_user_from_sina(result)
                except:
                    pass
                return fg,pid,msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Ejemplo n.º 6
0
def auth_bind_for_fb(request, access_token, openid, bind_access_token,
                     bind_openid):
    """论证fb开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://graph.facebook.com/me?access_token=%s' % str(
        access_token)

    #检查被绑定的oneclick账号是否合法
    url_request = urllib2.urlopen(str(user_info_url), timeout=12)
    rc, res = url_request.code, url_request.read()
    res = res.strip()
    res = res.replace('false', 'False')
    res = res.replace('true', 'True')
    res = res.replace('null', 'None')
    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login', 'invalid_bind')
        return fg, pid, msg
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc, res = url_request.code, url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false', 'False')
            res = res.replace('true', 'True')
            res = res.replace('null', 'None')
            exec('result = %s' % res)
            get_openid = str(result.get('id'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'fb', openid,
                                                  account, result)
                return fg, pid, msg
    else:
        msg = get_msg('login', 'invalid_bind')
    return fg, pid, msg
Ejemplo n.º 7
0
def auth_bind_for_fb(request,access_token,openid,bind_access_token,bind_openid):
    """论证fb开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://graph.facebook.com/me?access_token=%s' % str(access_token)

    #检查被绑定的oneclick账号是否合法
    url_request = urllib2.urlopen(str(user_info_url), timeout=12)
    rc,res = url_request.code, url_request.read()
    res = res.strip()
    res = res.replace('false','False')
    res = res.replace('true','True')
    res = res.replace('null','None')
    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,pid,msg
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc,res = url_request.code, url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false','False')
            res = res.replace('true','True')
            res = res.replace('null','None')
            exec('result = %s' % res)
            get_openid = str(result.get('id'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'fb', openid, account, result)
                return fg,pid,msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Ejemplo n.º 8
0
def auth_token_for_oc(request, access_token, openid, uuid, mktid, version,
                      client_type, macaddr, idfa, ios_ver):
    """论证无账号用户
    """
    print "debug_guochen access_token, openid", access_token, openid
    fg = False
    pid = ''
    msg = ''
    subarea = request.REQUEST.get("subarea", "1") or '1'
    #没有openid时,检查后控制自动分配id的开头是否开启,如果已经关闭,返回提示
    if not openid:
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = get_uuid()
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,
                                                'oc',
                                                uuid,
                                                mktid,
                                                version,
                                                client_type,
                                                macaddr,
                                                idfa,
                                                ios_ver,
                                                subarea=subarea)
            access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
        else:
            msg = get_msg('login', 'cannot_register')
            return fg, pid, msg
    if not check_openid(openid):
        msg = get_msg('login', 'cannot_register')
        return fg, pid, msg
    #有openid时,检查access_token是否正确
    account = AccountMapping.get(openid)
    if not account:
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = openid
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,
                                                'oc',
                                                uuid,
                                                mktid,
                                                version,
                                                client_type,
                                                macaddr,
                                                idfa,
                                                ios_ver,
                                                subarea=subarea)
            # debug 模式下,将传入的access_token 作为新用户taken
            if settings.DEBUG is True:
                access_token = access_token or get_upwd()
            else:
                access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
            account = request.rk_user.account
            print "debug_guochen_new_token pid, access_token, openid", pid, access_token, openid
        else:
            msg = get_msg('login', 'cannot_register')
            return fg, pid, msg

    elif account.access_token == access_token:
        fg = True
        pid = openid
        #验证成功,安装用户
        request.rk_user = UserBase._install(pid, 'oc', subarea=subarea)
    else:
        print "debug_guochen_erro_token pid, access_token, openid", pid, access_token, openid
        msg = get_msg('login', 'session_overdue')
    return fg, pid, msg