Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom url redirect option, and updated readme #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ To group by different period use the following setting:
```python
SESSION_EXPIRE_AFTER_LAST_ACTIVITY_GRACE_PERIOD = 60 # group by minute
```

To redirect to a custom url define the following setting:

```python
SESSION_TIMEOUT_CUSTOM_REDIRECT = 'your_redirect_url_here/'
```
...note the trailing slash.
6 changes: 5 additions & 1 deletion src/django_session_timeout/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.conf import settings
from django.contrib.auth.views import redirect_to_login
from django.shortcuts import redirect

try:
from django.utils.deprecation import MiddlewareMixin
Expand All @@ -27,7 +28,10 @@ def process_request(self, request):

if session_is_expired:
request.session.flush()
return redirect_to_login(next=request.path)
if settings.SESSION_TIMEOUT_CUSTOM_REDIRECT is not None:
return redirect(settings.SESSION_TIMEOUT_CUSTOM_REDIRECT)
else:
return redirect_to_login(next=request.path)

expire_since_last_activity = getattr(
settings, "SESSION_EXPIRE_AFTER_LAST_ACTIVITY", False
Expand Down