Esempio n. 1
0
def weblogin(request,logintype):
    """
    网站接入登录
    跳转到授权页面
    """
    if logintype in ['qq','weibo']:
        client = APIClient(logintype=logintype)
        url = client.get_authorize_url()
        return HttpResponseRedirect(url)
    else:
        raise Http404()
Esempio n. 2
0
def webcallback(request,logintype):
    """
    回调函数,获取access_token
    创建user,保存uid。查找用户,登录。
    userid:接入网站登录的唯一标识  新浪:uid  腾讯:openid
    """
    if logintype in ['qq','weibo']:
        if 'code' in request.GET:
            code = request.GET['code']
        client = APIClient(logintype=logintype)
        r = client.request_access_token(code)
        access_token = r.access_token
        expires_in = r.expires_in
        if logintype == 'qq':
            userid = client.request_qq_uid(access_token)    
        else:
            userid = r.uid
        # TODO: 在此可保存access token
        client.set_access_token(access_token, expires_in, userid)
        
        return HttpResponse(access_token+'   '+str(expires_in)+'   '+userid)
        return HttpResponseRedirect(url)
    else:
        raise Http404()