2
\$\begingroup\$

I intend to send validating message to User's email to complete a registration with the following codes:

def register(request):
    """1. register a new user
       2. generate activating code
       3. send validating email
       4. prompt to check activating email.
    """
    if request.method == "GET":
        form = UserForm()
    if request.method == "POST":
        form = UserForm(request.POST)
        print(vars(form))
        if form.is_valid():
            #1. Create User and save to sever
            user = User.objects.create_user(
                      form.cleaned_data['username'],
                      first_name=form.cleaned_data['first_name'],
                      last_name=form.cleaned_data['last_name'],
                      email=form.cleaned_data['email'],
                      password=form.cleaned_data['password'])
            user.is_active = False
            user.save()

            #2. Create activate code and save to server.
            uuid_code = str(uuid.uuid4()).replace("-", '')
            activate_code = ActivateCode(user=user, code=uuid_code)
            activate_code.save()

            #3. Send Validation Email
            activate_link = "http://%s/user/activate/%s" %(request.get_host(), uuid_code)
            activate_message = """\
            You're almost done!
            <a href="%s">Click here to complete your registration</a>
            """ % activate_link
            send_mail(subject="Complete Registration With Code Journey",
                      message="Click here to complete your registration: %s" %activate_link,
                      html_message=activate_message,
                      from_email="anexmaple@mail.com",
                      recipient_list=[form.cleaned_data['email'],],
                      fail_silently=False)

           #4. Prompt user to check his email.
            context = {'email': form.cleaned_data['email'],}
            return render(request, "user/validate.html", context)

The problem is that the user/validate.html feedbacks to me very slowly after formulated form was submittd.
I guess it's send_email consuming lots of my patience.

How could I implement step 4 in advance which immediately show prompt message then send mail unhurried.

\$\endgroup\$

closed as off-topic by 409_Conflict, Stephen Rauch, Billal Begueradj, t3chb0t, Dannnno Jun 4 '18 at 13:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 409_Conflict, Stephen Rauch, Billal Begueradj, Dannnno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ I don't understand... You don't send a response if the form is invalid or if the user send the GET verb. How do you display the form in the first place? How do you explain there were errors? \$\endgroup\$ – 409_Conflict Jun 2 '18 at 12:15