From dbe57075d386d7474bafc208b654507d9a2d769e Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 6 Nov 2022 13:48:04 -0700 Subject: Rework to a domains model for better vhosting --- users/decorators.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'users/decorators.py') 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 -- cgit v1.2.3