2018-10-15 21:24:53 +02:00
|
|
|
from django.db import models
|
2019-02-20 00:25:51 +01:00
|
|
|
from django.contrib.auth.hashers import make_password
|
|
|
|
|
from django.contrib.auth.models import User
|
2018-10-15 21:24:53 +02:00
|
|
|
|
|
|
|
|
# Basic DB to correlate tokens, users and creation time
|
|
|
|
|
|
|
|
|
|
class ResetToken(models.Model):
|
|
|
|
|
|
|
|
|
|
# users wouldn't use usernames >100 chars
|
|
|
|
|
user = models.CharField(max_length=100)
|
|
|
|
|
# Not so sure about tokens, better make it big
|
|
|
|
|
# should be <100, but big usernames make bigger tokens
|
|
|
|
|
# if I read that correctly
|
|
|
|
|
token = models.CharField(max_length=255)
|
2018-10-16 20:25:50 +02:00
|
|
|
# creation time in epoch (UTC)
|
|
|
|
|
# BigInt just so we are save for the next few decades ;)
|
2018-10-15 21:24:53 +02:00
|
|
|
creation = models.BigIntegerField()
|
2019-02-20 00:25:51 +01:00
|
|
|
|
|
|
|
|
|
2026-11-06 15:02:41 +03:00
|
|
|
class PendingRegistration(models.Model):
|
|
|
|
|
"""A sign-up waiting for its email to be confirmed.
|
|
|
|
|
|
|
|
|
|
Only the {SSHA} hash of the password is kept, and the activation link
|
|
|
|
|
carries nothing but the random token.
|
|
|
|
|
"""
|
|
|
|
|
token = models.CharField(max_length=64, unique=True)
|
|
|
|
|
username = models.CharField(max_length=100)
|
|
|
|
|
email = models.EmailField(max_length=254)
|
|
|
|
|
firstname = models.CharField(max_length=255)
|
|
|
|
|
lastname = models.CharField(max_length=255)
|
|
|
|
|
password_hash = models.CharField(max_length=255)
|
|
|
|
|
# creation time in epoch (UTC), like ResetToken
|
|
|
|
|
creation = models.BigIntegerField()
|
|
|
|
|
|
|
|
|
|
|
2019-02-20 00:25:51 +01:00
|
|
|
def get_validation_slug():
|
|
|
|
|
return make_password(None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserAccountValidationDetail(models.Model):
|
|
|
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
|
|
|
|
VALIDATED_CHOICES = ((0, 'Not validated'), (1, 'Validated'))
|
|
|
|
|
validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
|
|
|
|
|
validation_slug = models.CharField(
|
|
|
|
|
db_index=True, unique=True, max_length=50,
|
|
|
|
|
default=get_validation_slug
|
|
|
|
|
)
|
|
|
|
|
date_validation_started = models.DateTimeField(auto_now_add=True)
|