django-social-auth:连接成功,现在如何查询用户? [英] django-social-auth : connected successfully, how to query for users now?

查看:287
本文介绍了django-social-auth:连接成功,现在如何查询用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用 https://github.com/omab/django-social-auth ,并且能够通过Twitter,谷歌和Facebook成功登录。

I have started using https://github.com/omab/django-social-auth and been successfully able to login via twitter, google and facebook.

需要

我需要查询有关登录的用户才能做更多的事情,我将使用哪个模型?

I need to query about the logged in user in order to do more things, which Model I shall be using for that?

我没有看到任何例子

谢谢

更新

@Omab,我不明白这是如何工作的,请你帮忙。当我使用twitter登录时,回调转到以下代码

@Omab, I did not understand how this would work, can you please help. When I login with twitter, the callback goes to following code

@login_required
def done(request):
    """Login complete view, displays user data"""
    ctx = {
        'version': version,
        'last_login': request.session.get('social_auth_last_login_backend')
    }
    logging.warn('context - ' + str(ctx))
    logging.warn('request - ' + str(request))
    return render_to_response('home.html', ctx, RequestContext(request))

你能告诉我如何访问用户实例?

谢谢

推荐答案

p>应用程序使用 UserSocialAuth 模型存储社交帐户详细信息,以检索任何只需执行的实例:

The app stores the social account details using the UserSocialAuth model, to retrieve any instance just do:

user.social_auth.filter(provider="...")

其中:


  • 用户是一个

  • 提供者是一个带有提供者名称(facebook,twitter等)的字符串

  • user is a User instance (request.user for current logged in user)
  • provider is a string with the provider name (facebook, twitter, etc)

UserSocialAuth 实例存储所需的令牌来调用所需的API:

The UserSocialAuth instance stores the needed tokens to call the needed API:

print user_social_auth.tokens
{...}

这篇关于django-social-auth:连接成功,现在如何查询用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆