M
M
marselabdullin2020-07-16 21:32:59
Django
marselabdullin, 2020-07-16 21:32:59

How to save user but user.is_authenticate must be false?

In my web application, I send an email to the user to activate his account and when I redirect him to the confirmation page from the email, the menu items that shouldn't be displayed are shown because he is authenticating without being logged in though such should not be

the Views function to activate the user:

def activate_user_account(request, signed_user=None):
        user, signature = decoder(request, signed_user)
    
        if user and signature:
            user.email_confirm = True
            user.save()
            return render(request, 'email_verify_done.html', {'user': user})

And after that, the function redirects the user to this template:
{% if user.is_active %} {% if user.is_authenticated %}
            <p class="text-center">{% trans 'Your email address confirmed' %}</p>
    
            {% else %}
            <p class="text-center">
                {% trans 'You can' %}
                <a href="{% url 'users:login' %}"> {% trans 'log in now' %}</a>
                {% trans 'or do it in your mobile app' %}
            </p>
            {% endif %} {% else %}
            <p>{% trans "Something went wrong." %}</p>
            {% endif %}


Here the user passes both conditions and all menu items are displayed although he should not have been authenticated

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
marselabdullin, 2020-07-18
@marselabdullin

Solved the problem like this:

{% if user.is_active %} 
    {% if request.user.is_authenticated %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question