E
E
Egor2018-09-23 16:31:19
Django
Egor, 2018-09-23 16:31:19

Is it possible to organize user registration in Django this way?

Let's say I have a user model User (name, position). Django already has a User model from AUTHENTICATION AND AUTHORIZATION. Django also provides its ready-made registration forms: UserCreationForm. In the template, the form can be rendered like this: {{form}}. Three fields are displayed: username, password1, password2. The fact is that I did not understand what the condition checks: form.is_valid (), so I did without it (I check it manually). I found an option on the Internet where there is a Profile model that contains (I have this User):

user = models.OneToOneField(User, on_delete=models.CASCADE)
#+свои поля

That is, you need to add the OneToOneField field to communicate with the Django (User) registration model. I'm just scared to remake the user model and do the migration. Did it like this:
username = request.POST.get('username')
password1 = request.POST.get('password1')
password2 = request.POST.get('password2')

signup_f = request.POST.get('signup_f')
signup_i = request.POST.get('signup_i')
signup_o = request.POST.get('signup_o')
signup_post = request.POST.get('signup_post')
signup_email = request.POST.get('signup_email')

pattern = compile('(^|\s)[-a-z0-9_.][email protected]([-a-z0-9]+\.)+[a-z]{2,6}(\s|$)')

if(password1 == password2) and (pattern.match(signup_email)):
    user_auth = AuthUser.objects.create_user(username, signup_email, password1)
    user_auth.save()

    user = User(fio=signup_f+' '+signup_i+' '+signup_o, user_post=signup_post, group=1, email=signup_email)
    user.save()

I created an instance of the user's django, and my user. Django user will be used for authorization. Is there a place to be this method of registration? Second question: Is it normal that I send and receive login and password in this way?

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