Jessica
Jessica

Reputation: 137

Account didn't active after I confirmed my email in django

I wrote some code in django about registration with a verification email and the email has sent to me and I confirmed it but my acc didn't activate. I don't know if the problem is with my activate function or what here is the error I get : enter image description here

and this is my activate function:

def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and acc_activation.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
    else:
        return HttpResponse('Activation link is invalid!')

and my activation_email.html code :

    {% autoescape off %}
Hi {{ user.username }},
pleace click here to confirm your registration,
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}

Upvotes: 0

Views: 140

Answers (1)

satyajit
satyajit

Reputation: 694

Add user.profile.email_confirmed = True in your logic.

    if user is not None and acc_activation.check_token(user, token):
        user.is_active = True
        user.profile.email_confirmed = True
        user.save()
        login(request, user)
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')

Upvotes: 1

Related Questions