Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. class CustomUserManager(BaseUserManager):
  2. use_in_migrations = True
  3.  
  4. def _create_user(self, email, password, **extra_fields):
  5. """
  6. Creates and saves a User with the given email and password.
  7. """
  8. print('creating user...')
  9. if not email:
  10. raise ValueError('Email must be set') #<--- Throws the error.
  11. email = self.normalize_email(email)
  12. user = self.model(email=email, **extra_fields)
  13. user.set_password(password)
  14. user.save(using=self._db)
  15. return user
  16.  
  17. def create_user(self, email=None, password=None, **extra_fields):
  18. extra_fields.setdefault('is_staff', False)
  19. extra_fields.setdefault('is_superuser', False)
  20. return self._create_user(email, password, **extra_fields)
  21.  
  22. def create_superuser(self, email, password, **extra_fields):
  23. extra_fields.setdefault('is_staff', True)
  24. extra_fields.setdefault('is_superuser', True)
  25.  
  26. if extra_fields.get('is_staff') is not True:
  27. raise ValueError('Superuser must have is_staff=True.')
  28. if extra_fields.get('is_superuser') is not True:
  29. raise ValueError('Superuser must have is_superuser=True.')
  30.  
  31. return self._create_user(email, password, **extra_fields)
  32.  
  33. class CustomUser(AbstractBaseUser, PermissionsMixin):
  34.  
  35. email = models.EmailField(
  36. max_length=250,
  37. unique=True,
  38. )
  39.  
  40. is_staff = models.BooleanField(
  41. _('staff status'),
  42. default=False,
  43. help_text=_('Designates whether the user can log into this admin site.'),
  44. )
  45. is_active = models.BooleanField(
  46. _('active'),
  47. default=True,
  48. help_text=_(
  49. 'Designates whether this user should be treated as active. '
  50. 'Unselect this instead of deleting accounts.'
  51. ),
  52. )
  53. date_joined = models.DateTimeField(_('date joined'), default=datetime.now)
  54.  
  55. objects = CustomUserManager()
  56.  
  57. REQUIRED_FIELDS = []
  58. USERNAME_FIELD = 'email'
  59.  
  60. def get_short_name(self):
  61. "Returns the short name for the user."
  62. return self.email
  63.  
  64. settings.py
  65.  
  66. SOCIAL_AUTH_PIPELINE = (
  67. 'social_core.pipeline.social_auth.social_details',
  68. 'social_core.pipeline.social_auth.social_uid',
  69. 'social_core.pipeline.social_auth.auth_allowed',
  70. 'social_core.pipeline.social_auth.social_user',
  71. #'social_core.pipeline.user.get_username', <-- Comment this one out and use below instead to create the acc.
  72. 'Eapp.facebook.creates' #<---
  73. 'social_core.pipeline.user.create_user',
  74. 'social_core.pipeline.social_auth.associate_user',
  75. 'social_core.pipeline.social_auth.load_extra_data',
  76. 'social_core.pipeline.user.user_details',
  77. )
  78.  
  79. def creates(*args, **kwargs):
  80.  
  81. print('##################################')
  82. print(args)
  83. print('##################################')
  84. print(kwargs)
  85. print('##################################')
  86.  
  87. No module named 'Eapp.facebook.createssocial_core'; 'Eapp.facebook' is not a package
  88.  
  89. SOCIAL_AUTH_PIPELINE = (
  90. 'home.pipeline.[function_name]',
  91. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement