summaryrefslogtreecommitdiffstats
path: root/users/decorators.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-06 13:48:04 -0700
committerAndrew Godwin2022-11-06 13:48:04 -0700
commitdbe57075d386d7474bafc208b654507d9a2d769e (patch)
tree96b779d17753669f42b7569ec4ec66834b0673f4 /users/decorators.py
parent8aec395331a1e9ec4ef1ea38aa20b8517131133b (diff)
downloadtakahe-dbe57075d386d7474bafc208b654507d9a2d769e.tar.gz
takahe-dbe57075d386d7474bafc208b654507d9a2d769e.tar.bz2
takahe-dbe57075d386d7474bafc208b654507d9a2d769e.zip
Rework to a domains model for better vhosting
Diffstat (limited to 'users/decorators.py')
-rw-r--r--users/decorators.py17
1 files changed, 3 insertions, 14 deletions
diff --git a/users/decorators.py b/users/decorators.py
index 77d633a..d373692 100644
--- a/users/decorators.py
+++ b/users/decorators.py
@@ -3,8 +3,6 @@ from functools import wraps
from django.contrib.auth.views import redirect_to_login
from django.http import HttpResponseRedirect
-from users.models import Identity
-
def identity_required(function):
"""
@@ -16,24 +14,15 @@ def identity_required(function):
# They do have to be logged in
if not request.user.is_authenticated:
return redirect_to_login(next=request.get_full_path())
- # Try to retrieve their active identity
- identity_id = request.session.get("identity_id")
- if not identity_id:
- identity = None
- else:
- try:
- identity = Identity.objects.get(id=identity_id)
- except Identity.DoesNotExist:
- identity = None
# If there's no active one, try to auto-select one
- if identity is None:
+ if request.identity is None:
possible_identities = list(request.user.identities.all())
if len(possible_identities) != 1:
# OK, send them to the identity selection page to select/create one
return HttpResponseRedirect("/identity/select/")
identity = possible_identities[0]
- request.identity = identity
- request.session["identity_id"] = identity.pk
+ request.session["identity_id"] = identity.pk
+ request.identity = identity
return function(request, *args, **kwargs)
return inner