From c055260bb88fd407c81ad0d40dd288a5aae4fb17 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 7 Nov 2017 13:02:09 -0500 Subject: Updated middleware to force creation of user Identity. Fix issues with Identity creation. Added is_active to Django Admin UI for the dispatchAuth.models.User --- app/dispatch/middleware.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'app/dispatch/middleware.py') diff --git a/app/dispatch/middleware.py b/app/dispatch/middleware.py index 2b3e349..8ae0465 100644 --- a/app/dispatch/middleware.py +++ b/app/dispatch/middleware.py @@ -27,5 +27,21 @@ class LoginRequiredMiddleware(object): if path not in EXEMPT_URLS: login_uri = '%s?next=%s' % (settings.LOGIN_URL, request.path_info) return HttpResponseRedirect(login_uri) + else: + # I don't really like this but I don't really see a better + # way of checking for this + try: + identity = request.user.identity + except: + allowed_paths = [ reverse('identity_create', kwargs={'user_id': request.user.pk}) ] + allowed_paths.extend(EXEMPT_URLS) + print(allowed_paths) + if request.path_info not in allowed_paths: + return HttpResponseRedirect(allowed_paths[0]) + + return self.get_response(request) + + + # TODO: Have the middleware automatically set the default identity + # if not set and a superuser creates one - return self.get_response(request) \ No newline at end of file -- cgit v1.2.3