Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(models.Model):
- # mandatory
- username = models.CharField(max_length=129, unique=True, db_index=True)
- password = models.CharField(max_length=256)
- REQUIRED_FIELDS = ('password',)
- USERNAME_FIELD = 'username'
- # properties
- name = models.CharField(max_length=60, blank=True)
- email = models.CharField(max_length=254, blank=True)
- birth_date = models.DateField(null=True, blank=True)
- profile_image = s3_field(blank=True)
- profile_background_image = s3_field(blank=True)
- profile_message = models.CharField(max_length=100, blank=True)
- couple = models.ForeignKey(Couple, blank=True, null=True, db_index=True)
- # metadata
- created = created_field()
- last_login = models.DateTimeField(auto_now=True)
- is_active = models.BooleanField(default=True)
- is_staff = models.BooleanField(default=False)
- is_superuser = models.BooleanField(default=False)
- social = JSONField(blank=True, null=True)
- @staticmethod
- def _digest_password(password):
- us = settings.USER_SECRET
- algorithm_ = us['algorithm']
- hkey = us['hkey']
- iteration = us['iteration']
- return hexlify(pbkdf2_hmac(algorithm_, password.encode(), hkey, iteration)).decode()
- @staticmethod
- def create_user(username, password):
- User.objects.create(username=username, password=User._digest_password(password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement