用户登录后不会创建用户(可能是同志的情况) [英] Users are not created after login with facebook (probably an homonymy case)

查看:158
本文介绍了用户登录后不会创建用户(可能是同志的情况)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何将python社交认证整合到django项目中。



似乎有效,因为我可以登录到我的测试应用程序,但它用户从未存储到数据库的接缝,我无法理解为什么,因为我没有收到任何错误。



这是我的conf

  INSTALLED_APPS =(
...
'social.apps.django_app.default',
'messaging'


AUTHENTICATION_BACKENDS =(
'social.backends.facebook.FacebookOAuth2',
'social.backends.email.EmailAuth',
'django .contrib.auth.backends.ModelBackend',


SOCIAL_AUTH_FACEBOOK_KEY ='XX'
SOCIAL_AUTH_FACEBOOK_SECRET ='YYY'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

LOGIN_URL ='/ login /'
LOGIN_REDIRECT_URL ='/ home /'
LOGOUT_REDIRECT_URL ='/'
URL_PATH = ''
SOCIAL_AUTH_STRA TEGY ='social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE ='social.apps.django_app.default.models.DjangoStorage'

TEMPLATE_CONTEXT_PROCESSORS =(
'django.contrib。 auth.context_processors.auth',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',

我的想法只是为用户使用django默认模型,所以我没有为它定义任何扩展名。



你有什么想法为什么用户不是在登录时创建?



更新 p>

我注意到一些看起来很奇怪的东西,至少对我来说。在进行syncdb时创建的第一个管理员用户与我用来测试应用程序的Facebook帐户名称相同。我以为这是不会被使用,而另一个用户必须被创建,但是在检查数据库时,我看到 auth_user.last_login 被更新了相应的登录执行与Facebook有关。



所以我有这两个问题:


  1. 是正确的那个python社会认证会检查auth_user中是否已经存在具有相同姓名的用户,然后使用该特定用户而不是创建另一个用户?

  2. 如何避免这种情况, Facebook上的用户Foo Bar和Twitter上的用户Foo Bar不是同一个人?


解决方案

快速回答您的问题:



  1. 无需完成此任务。 >

对我来说,您似乎已经用该管理员用户登录,然后点击您的使用Facebook登录链接。 python-social-auth 将采用当前登录的用户并关联社交帐户(如果有任何用户登录),否则将创建一个新帐户。但是,如果您的网站已经使用了社交帐户,那么它将登录相关用户,或者删除一个例外,表明该社交帐户已被使用。



可以通过以下方式检查相关用户到社交帐户:

  from social.apps.django_app.default.models import UserSocialAuth 

在SocialSocialAuth.objects.all()中的社交:
print social.provider,social.user.id,social.user.username

这是我在你的情况下做的:


  1. 数据库或删除表中的内容 social_auth_usersocialauth

  2. 转到 / admin 并确保您退出

  3. 尝试再次使用Facebook登录

此次应创建一个新的用户帐户。


I am trying to learn how to integrate python social auth into a django project.

It seems to work, because I can log into my test application, but it seams that the user is never stored to the db and I can't understand why, since I don't get any error.

Here's my conf

INSTALLED_APPS = (
    ...
    'social.apps.django_app.default',
    'messaging'
)

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2',
    'social.backends.email.EmailAuth',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_FACEBOOK_KEY='XX'
SOCIAL_AUTH_FACEBOOK_SECRET='YYY'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/home/'
LOGOUT_REDIRECT_URL = '/'
URL_PATH = ''
SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)

My idea is just to use django default model for the user, so I haven't defined any extension for it.

Do you have any idea why users are not created at login?

UPDATE

I noticed something that looks weird, at least to me. The first admin user which is created when doing syncdb has the same first and last name of the facebook account I am using to test the application. I thought that it was not going to be used and that another user had to be created, but while checking the database i saw that auth_user.last_login was updated accordingly to the login performed with facebook.

So I have these two questions:

  1. is it correct that python social auth checks if a user with the same first and last name is already present in auth_user then it uses that particular user instead of creating another one?
  2. how can I avoid the situation where user Foo Bar on facebook and user Foo Bar on Twitter are not the same person?

解决方案

Quick answers to your questions:

  1. No
  2. Nothing is needed to accomplish that.

To me it looks like you were logged in with that admin user before clicking your Login with Facebook link. python-social-auth will take the current logged in user and associate the social account to it (if there's any user logged in), otherwise it will create a new account. But, if the social account was already used in your site, it will login the related user, or drop an exception indicating that the social account is already in use.

You can check the related user to a social account with this:

from social.apps.django_app.default.models import UserSocialAuth

for social in UserSocialAuth.objects.all():
  print social.provider, social.user.id, social.user.username

This is what I would do in your case:

  1. Trash the database, or delete the content in the table social_auth_usersocialauth
  2. Go to /admin and ensure that you are logged out
  3. Try to login with Facebook again

This time a new user account should be created.

这篇关于用户登录后不会创建用户(可能是同志的情况)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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