Build invite-code user registration Django 4.0
i want build a invite-code registration user system in Django.
For registration a new user need to fill two fields of form 'INVITE'
(UUID getted from already exists user) and 'PASSWORD'
. After send data (requests.POST
) Django check invite-code (finds it in the database and correlates it with the user id) and if result is success Django generate 8-symbols username and add new user record in db with fill ID, USERNAME, PASSWORD, INVITER, UUID.
For example, the invitation code is the UUID of an existing user.
Look
# myapp/model.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
class Users(AbstractBaseUser):
def login_gen():
import uuid
uuid = uuid.uuid4()
return uuid[:8], uuid
id = models.BigAutoField(primary_key=True)
username = models.CharField("Username", max_length=8, null=False, blank=False, db_index=True, unique=True, default=login_gen[0])
password = models.CharField("Password", max_length=255, null=False, blank=False)
role = models.BooleanField("Right or Left", null=False, blank=False)
inviter = models.ForeignKey('Whos invite', self.id, null=False, blank=False)
#... other fields
UUID = models.UUIDField("UUID", null=False, blank=False, default=login_gen[1])
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['username', 'password', 'role']
def __str__(self):
return self.username
I would like to implement the task with authentication tools built into Django, but I can't cope with the user model (model.py
), form (forms.py
) and manager (managers.py
) in any way.