V
V
Vic Shostak2017-09-10 21:50:22
Django
Vic Shostak, 2017-09-10 21:50:22

Django. How to register a visitor (guest) after submitting an order form?

Good time!
There is Django 1.11.5 with an overridden user model ( client). Authorization occurs by email + password, some fields in the admin panel are removed, but otherwise it is the standard user model from Django (I use AbstractUser). Also, there is an application ( order_form) with many fields, which can be filled in by both guests and authorized visitors of the site.
How to make it so that when submitting this form, if the visitor is a GUEST (not authorized) and he does NOT yet have an account on the site (verification by email), then he is automatically registered (with the email that he specified in the form and a randomly generated password + sending a letter with this data to the mail)?
Also, I would like to immediately redirect to his personal account + authorize this user using his email and that generated password.
I will be glad for any help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Kuzmichev, 2017-09-11
@vikkyshostak

Leaving aside the controversial points in such a process, then:
The standard UserManager has a create_user method . If you have an overridden user model, make sure that the UserManager for your model is up to date. If you have changed the fields that appear in this method, you may need to create your own UserManager based on the stock one.
Surprisingly, it is quite easy to log in a user, there is a login function.
Well, you probably know how to do a redirect (to the personal account) after creating a user and successfully logging in.

O
oh, 2017-09-11
well @AnneSmith

in fact, it turns out that you are sending a password and possibly personal data to an unverified email address
people make mistakes, and before creating an account and sending passwords, this email needs to be confirmed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question