Django User Authentication - Can't pass @login_required decorator

JackSac67

So I'm currently trying to implement an already existing application for payment processing via Braintree (https://github.com/Tivix/django-braintree for reference). It seems like all the meat of this application is placed at the /payments-billing/ directory but I can't seem to get into it to check it out. It seems like what's stopping me is a @login_required decorator placed just before the view since whenever I access the directory it sends me back to the defined LOGIN_URL. However I have set up a login feature at the LOGIN_URL that authenticates the user and then sends them to /payments-billing/ but it just redirects back again. Here is my code:

username = form.cleaned_data['username']
password = form.cleaned_data['password']

user = authenticate(username=username, password=password)
if user is not None:
    # Password verified for user
    if user.is_active:
       return redirect(self.success_url)
    else:
        return redirect('/')
else:
    return redirect('/')

Clearly the user is being authenticated and is active since it passes both tests when you try it, but it always just sends the user back to the LOGIN_URL rather than /payments-billing/. Anyone know what's the deal here?

Daniel Roseman

The authenticate function doesn't log a user in, it just checks their username/password. You also have to call django.contrib.auth.login() to do the actual logging in. See the example in the documentation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can't find "User" class for Dropwizard Authentication

Login_Required decorator not working properly in django

django @login_required decorator for a superuser

@method_decorator with login_required and permission_required

django testing views with login_required decorator respecting DRY

What is the difference between @login_required and @method_decorator(login_required) in django

django login_required decorator, always redirect to login page, even after logging in

django - Can't login after creating user

Django: testing with login_required

Why do Django have too many login redirects when using @login_required decorator?

In Django 1.10 authentication with allauth, login_required decorator does not work

django test cases can't get past the @login_required decorator on a view function

Django login_required decorator does not work with ip 127.0.0.1

Django @login_required decorator does not redirect to specific page

Login required decorator is not working properly in the django

Django 'User' object has no attribute 'user' when combining login_required with user_passes_test

Django can't login user in test with UserFactory

Can't access login_required routes with flask_login

How to disable next URL parameter while using login_required decorator in django?

django-cms login_required doesn't work

Using the @login_required decorator

Django request.user is anonymous in views without login_required decorator

login_required decorator in Django doesn't work

login_required decorator not redirecting to correct endpoint

Can I change the default `login_required value for all pages in Django-CMS?

Django user authentication and login problem

login_required decorator gives "object has no attribute 'user'" error

Is there a way I can extend Django login_required decorator to check for a boolean field in my custom model?

When using custom AuthBackend, unable to use request.user.is_authenticated or @login_required decorator