Comments (4)
I'm not that familiar with the test client, however I find it strange that request.user
would not be available. It should be set by the AuthenticationMiddleware
. Are you sure you've setup all middleware correctly?
from django-user-sessions.
It does, but in a typical Django setup, AuthenticationMiddleware
comes later in the stack than SessionMiddleware
. I agree that it's strange that request.user
isn't available, but I'm just working with defaults here and the test client isn't working, hence this issue report :-(
from django-user-sessions.
After snooping around in the code of Django's auth.login()
code, I found what you're referring to:
def login(request, user, backend=None):
# (...)
if hasattr(request, 'user'):
request.user = user
rotate_token(request)
user_logged_in.send(sender=user.__class__, request=request, user=user)
So the signal user_logged_in
will be passed the request that was passed to the login
method. Since this package's (and also upstream's) test client doesn't set request.user
, this property is also not available from your signal handler. The test client's login
method doesn't use any middleware, so that's why AuthenticationMiddleware
doesn't have any effect.
Could you test the fix that you propose in your initial comment? I think it should work fine.
from django-user-sessions.
It does. I just subclassed user_sessions.utils.tests.Client
and overrided login()
to change:
request = HttpRequest()
to
request = HttpRequest()
request.user = None
And everything works as expected.
Sorry, I'd submit a proper pull request, but I'm neck-deep in a legacy project I'm trying to bring up to speed, so this quick hack was all that I had time for. I just thought that upstream would like the heads-up.
from django-user-sessions.
Related Issues (20)
- Warnings about ugettext_lazy being deprecated
- This project is looking for maintainers! HOT 3
- Security issue with default URL suggestion HOT 2
- How would one go about measuring session length? HOT 1
- How to import the default Session ? HOT 1
- Bug: Opera browser is recognized as Chrome browser in template.
- Possibility of a new Release HOT 15
- Application does not works with Django 4.0 HOT 1
- django 4.0 support
- fails to build with django 4 HOT 2
- Slow UPDATE queries? HOT 2
- RuntimeError: Model class django.contrib.sessions.models.Session doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS HOT 5
- update readme links HOT 1
- It's no longer possible to properly detect the platform version, so we shouldn't try to HOT 3
- Not saving user_agent and ip even while using geoip
- Switch to using setuptools_scm HOT 1
- Utilize ruff
- Drop unsupported versions of Django
- Clean up some of the dev dependencies
- Handling session cookie delete on logout
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-user-sessions.