Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. class User(models.Model):
  2. # mandatory
  3. username = models.CharField(max_length=129, unique=True, db_index=True)
  4. password = models.CharField(max_length=256)
  5. REQUIRED_FIELDS = ('password',)
  6. USERNAME_FIELD = 'username'
  7.  
  8. # properties
  9. name = models.CharField(max_length=60, blank=True)
  10. email = models.CharField(max_length=254, blank=True)
  11. birth_date = models.DateField(null=True, blank=True)
  12. profile_image = s3_field(blank=True)
  13. profile_background_image = s3_field(blank=True)
  14. profile_message = models.CharField(max_length=100, blank=True)
  15. couple = models.ForeignKey(Couple, blank=True, null=True, db_index=True)
  16.  
  17. # metadata
  18. created = created_field()
  19. last_login = models.DateTimeField(auto_now=True)
  20. is_active = models.BooleanField(default=True)
  21. is_staff = models.BooleanField(default=False)
  22. is_superuser = models.BooleanField(default=False)
  23. social = JSONField(blank=True, null=True)
  24.  
  25. @staticmethod
  26. def _digest_password(password):
  27. us = settings.USER_SECRET
  28. algorithm_ = us['algorithm']
  29. hkey = us['hkey']
  30. iteration = us['iteration']
  31. return hexlify(pbkdf2_hmac(algorithm_, password.encode(), hkey, iteration)).decode()
  32.  
  33. @staticmethod
  34. def create_user(username, password):
  35. User.objects.create(username=username, password=User._digest_password(password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement