Comments (6)
When applying your proposal I'm facing ERR_TOO_MANY_REDIRECTS
.
from cookiecutter-django.
It is true, I did not realize that the first time...
Maybe it is a django-allauth
problem?
If I log in as a non staff member with the snippet from the allauth docs the too many redirects error is raised
If I take the current admin.site.login = decorators.login_required(admin.site.login)
snippet I can go around the allauth login flow.
from cookiecutter-django.
Perhaps we can destroy the current session when this occurs? The the user is redirected to the correct form with the correct redirect url.
from cookiecutter-django.
Something like this would work to check if the user is a staff member and if not automatically perform a logout, display an error message and redirect to the login page:
from django.contrib.auth import decorators, logout
from django.shortcuts import redirect
from django.contrib import messages
if settings.DJANGO_ADMIN_FORCE_ALLAUTH:
# Define a custom AdminSite class to check if the user is a staff member
class CustomAdminSite(admin.AdminSite):
def login(self, request, extra_context=None):
if request.user.is_authenticated and not request.user.is_staff:
logout(request)
storage = messages.get_messages(request)
# Clear all other messages first
storage.used = True
messages.error(
request, "You are not authorized and have been logged out."
)
return redirect("account_login")
return super().login(request, extra_context)
admin.site = CustomAdminSite()
# Force the `admin` sign in process to go through the `django-allauth` workflow:
# https://django-allauth.readthedocs.io/en/stable/advanced.html#admin
admin.site.login = decorators.login_required(admin.site.login) # type: ignore[method-assign]
Not sure if you meant somthing like that
from cookiecutter-django.
Exactly what I meant! Do you mind providing a PR (when you do, do not forget to translate the error message)?
from cookiecutter-django.
Perfect!
No worries I will do a PR in the next days :)
from cookiecutter-django.
Related Issues (20)
- Add `sphinxcontrib-django` for documentation
- ci.yml for running pytest is building docs image unnecessarily (run time 4:30m instead of 3:00m)
- Split the `docs` service out of `local.yml` HOT 2
- You probably don't need `get_user_model` HOT 1
- CI should test against production environment, not local HOT 2
- Allow multiple imports on one line HOT 6
- Incorrect Python version in Docker. HOT 1
- Use Astral's uv for pip installation in Docker + CI HOT 4
- Integrate PostgreSQL 16 Support in Django Cookiecutter HOT 1
- libpq-dev installation is repeated in Dockerfile HOT 1
- Adding django-ninja options to building REST APIs HOT 11
- S3 putObject fails when starting up project: What permissions are required.? HOT 3
- Selecting Whitenoise and AWS as cloud provider overrides STATIC_URL in a way that assumes Collectfast HOT 3
- Adopt Collectfasta HOT 2
- Drop support for runserver_plus & django_extensions HOT 2
- createdb and migrate using conda
- ruff hook fails with F405 issue in config/settings/production.py HOT 1
- Python: can't open file '/app/manage.py': [Errno 2] No such file or directory - Django - Docker Compose HOT 8
- Python: can't open file '/app/manage.py': [Errno 2] No such file or directory - Django - Docker Compose
- Why doesn't add RunServerPlus options for reload in windows when using docker? HOT 3
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 cookiecutter-django.