S
S
Sergey Simonov2021-12-30 20:35:38
Django
Sergey Simonov, 2021-12-30 20:35:38

How to make registration of new Django users by invites (invitations) from other users?

It is required to register a user using an invite code received from a previously registered user
61cde92a3c99c849471403.png
. The user enters an invite and a password. The system generates a nickname itself in case of a successfully found invite.
At the time of registration, the system checks the invite, in case of successful finding it generates a username, by invite it finds the nickname of the one who invited the registered user and creates a record about the new user (see code)

The model is as follows:

# 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 str(uuid)[:8], uuid

    id = models.BigAutoField(primary_key=True)
    username = models.CharField("Имя пользователя", max_length=8, null=False, blank=False, db_index=True, unique=True, default=login_gen()[0])
    password = models.CharField("Пароль", max_length=255, null=False, blank=False)
    role = models.BooleanField("Физ или юр", null=False, blank=False)
    inviter = models.ForeignKey(verbose_name='Кто пригласил', self.id, null=False, blank=False)
    #... другие поля
    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 the authentication tools built into Django, but I just can’t cope with the user model, form and manager, and possibly views

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question