Py学习  »  公告

可以使用新浪微博帐号直接登陆社区啦

Py站长 • 12 年前 • 8114 次点击  

Django中国社区已经和新浪微博帐号打通,以后可以使用新浪微博帐号直接登录啦~~~

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/13
 
8114 次点击  
文章 [ 6 ]  |  最新文章 11 年前
Py站长
Reply   •   1 楼
Py站长    11 年前

@WyattWang 对的,你说的都对,需要对 https://github.com/bread-and-pepper/django-userena 进行修改,与新浪对接,看了你们站点,做得不错哈。与新浪对接关键就是在回调函数里。回调函数里采用Weibo客户端获取Id以及名字等信息,然后判断该用户是否在你的数据库里(可以使用id 加上一个type以标明他来自微博),底下的 _login_for_user 函数就是做这些事情。最后跳转就行了。

@secure_required
def weibo_callback(request):
    """
            微博callback

    """
    try:
        code = request.GET.get('code', None)
        client = _create_client()
        r = client.request_access_token(code)
        print 'access token: %s' % json.dumps(r)
        access_token, expires_in, uid = r.access_token, r.expires_in, r.uid
        client.set_access_token(access_token, expires_in)
        u = client.users.show.get(uid = uid)
        print 'got user: %s' % uid

        request.session['access_token'] = access_token
        request.session['expires_in'] = expires_in

        # 进行登录(用户不存在,则创建)
        new_user, is_new_user = _login_for_user(u, expires_in - r.expires, request)
        if is_new_user == True:
            redirect_to = reverse('userena_profile_edit',
                                    kwargs = {'username': new_user.username})
        else:
            redirect_to = signin_redirect(
                    None, new_user)

    except Exception, e:
        return HttpResponse('连接新浪账号时出错:%s <p>返回首页:<a href="/">首页</a>' % e)
return HttpResponseRedirect(redirect_to)
WyattWang
Reply   •   2 楼
WyattWang    11 年前

@Django中国社区 你好,我想请教下,你在使用新浪微博登录这一模块是如何处理的?

我欢迎你的登录系统,貌似是使用django-userena写的中,Weibo登录这功能,我不清楚你是使用什么App或是自己编写的吗?

如何能将现在已有的登录系统与新浪微博登录对接起来呢?

我现在在做http://joinwee.com这个站,需要解决下这个问题,麻烦指导出,如果能分享这一部份源码的话,那更好了。

谢谢。

我的邮箱:wwq0327@gmail.com

Py站长
Reply   •   3 楼
Py站长    12 年前

@linbo 如果是对社区有建议的话,在 http://django-china.cn/forum/feedback/ 这里提

如果是 提技术问题 可以先在 http://django-china.cn/forum/tech/ 这里提问啦

linbo
Reply   •   4 楼
linbo    12 年前

我怎么才可以提问题??

Py站长
Reply   •   5 楼
Py站长    12 年前

@LYcSon :)

有建议可以直接提哦,

LYcSon
Reply   •   6 楼
LYcSon    12 年前

鼓掌。

信任报到,祝社区快快成长、茁壮起来。