diff options
Diffstat (limited to 'src/account')
-rw-r--r-- | src/account/tasks.py | 5 | ||||
-rw-r--r-- | src/account/views.py | 21 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/account/tasks.py b/src/account/tasks.py index fe51974..53fbaf5 100644 --- a/src/account/tasks.py +++ b/src/account/tasks.py @@ -26,7 +26,10 @@ def sync_jira_accounts(): except JIRAError: # User can be anonymous (local django admin account) continue - user.email = user_dict['emailAddress'] + try: + user.email = user_dict['emailAddress'] + except: + pass user.userprofile.url = user_dict['self'] user.userprofile.full_name = user_dict['displayName'] diff --git a/src/account/views.py b/src/account/views.py index d1cc813..912a432 100644 --- a/src/account/views.py +++ b/src/account/views.py @@ -28,6 +28,7 @@ from django.views.generic import RedirectView, TemplateView, UpdateView from django.shortcuts import render from jira import JIRA from rest_framework.authtoken.models import Token +from mozilla_django_oidc.auth import OIDCAuthenticationBackend from account.forms import AccountSettingsForm @@ -58,6 +59,20 @@ class AccountSettingsView(UpdateView): return context +class MyOIDCAB(OIDCAuthenticationBackend): + def filter_users_by_claims(self, claims): + email = claims.get(email=email) + if not email: + return self.UserModel.objects.none() + + try: + profile = Profile.objects.get(email=email) + return profile.user + + except Profile.DoesNotExist: + return self.UserModel.objects.none() + + class JiraLoginView(RedirectView): def get_redirect_url(self, *args, **kwargs): consumer = oauth.Consumer(settings.OAUTH_CONSUMER_KEY, settings.OAUTH_CONSUMER_SECRET) @@ -127,7 +142,11 @@ class JiraAuthenticatedView(RedirectView): jira = JIRA(server=settings.JIRA_URL, oauth=oauth_dict) username = jira.current_user() - email = jira.user(username).emailAddress + email = "" + try: + email = jira.user(username).emailAddress + except: + email = "" url = '/' # Step 3. Lookup the user or create them if they don't exist. try: |