Django Social Auth不使用自定义用户设置

时间:2013-09-20 20:45:55

标签: python django django-socialauth

我一直有一段时间让django和django-social-auth与自定义用户和自定义用户管理器很好地配合。我发现了很多关于此的帖子,但似乎没有任何工作。

以下是设置:

LOGIN_URL                         = '/login/'
LOGIN_ERROR_URL                   = '/login/error/'
LOGIN_REDIRECT_URL                = '/'
LOGOUT_REDIRECT_URL               = '/'

SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_FORCE_POST_DISCONNECT = True
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

AUTH_USER_MODEL                   = 'auth.MyUser'
SOCIAL_AUTH_USER_MODEL            = 'auth.MyUser'

FACEBOOK_APP_ID                   = 'xxxx'
FACEBOOK_API_SECRET               = 'xxxx'
FACEBOOK_EXTENDED_PERMISSIONS     = ['user_birthday','email','user_about_me','user_education_history','user_events','user_likes','user_subscriptions','user_groups','publish_actions','read_friendlists','user_relationships','user_relationship_details','publish_stream']

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.facebook.FacebookBackend',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_PIPELINE = (
  'social_auth.backends.pipeline.social.social_auth_user',
  'social_auth.backends.pipeline.social.load_extra_data',
  'social_auth.backends.pipeline.user.get_username',
  'social_auth.backends.pipeline.user.create_user',
  'social_auth.backends.pipeline.social.associate_user',
  'social_auth.backends.pipeline.user.update_user_details'
)

这是我的模特

from django.db import models
from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser
)

class MyUserManager(BaseUserManager):
    def create_user(self, username, email, password=None):
        """
        Creates and saves a User with the given email and password.
        """
        if not email:
           raise ValueError('Users must have an email address')

        user = self.model(
            email=MyUserManager.normalize_email(email),
        )

        user.set_password(password)
        user.save(using=self._db)
        return user

class MyUser(AbstractBaseUser):
    email = models.EmailField(
        verbose_name='Email address',
        max_length=255,
        unique=True,
        db_index=True,
    )
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    objects = MyUserManager()

    def has_perm(self, perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, app_label):
        "Does the user have permissions to view the app `app_label`?"
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_staff(self):
        "Is the user a member of staff?"
        # Simplest possible answer: All admins are staff
        return self.is_admin

    class Meta:
        db_table = 'customUser'

从我可以收集的内容来看,用户的创建是错误的,并且强制django auth插件寻找不存在的错误后端。如果我不使用自定义用户/管理器,此问题将自行解决。

对于我在这里可能缺少的任何帮助将不胜感激。

0 个答案:

没有答案