aboutsummaryrefslogtreecommitdiffstats
path: root/src/account
diff options
context:
space:
mode:
Diffstat (limited to 'src/account')
-rw-r--r--src/account/views.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/account/views.py b/src/account/views.py
index d11a199..08da918 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,48 @@ class AccountSettingsView(UpdateView):
return context
+class MyOIDCAB(OIDCAuthenticationBackend):
+ def filter_users_by_claims(self, claims):
+ """
+ Checks to see if user exists and create user if not
+
+ Linux foundation does not allow users to change their
+ username, so chose to match users based on their username.
+ If this changes we will need to match users based on some
+ other criterea.
+ """
+ username = claims.get(os.environ['CLAIMS_ENDPOINT'] + 'username')
+
+ if not username:
+ return HttpResponse('No username provided, contact support.')
+
+ try:
+ # For literally no (good) reason user needs to be a queryset
+ user = User.objects.filter(username=username)
+ return user
+ except User.DoesNotExist:
+ return self.UserModel.objects.none()
+
+ def create_user(self, claims):
+ """ This creates a user and user profile"""
+ user = super(MyOIDCAB, self).create_user(claims)
+ user.username = claims.get(os.environ['CLAIMS_ENDPOINT'] + 'username')
+ user.save()
+
+ up = UserProfile()
+ up.user = user
+ up.email_addr = claims.get('email')
+ up.save()
+ return user
+
+ def update_user(self, user, claims):
+ """ If their account has different email, change the email """
+ up = UserProfile.objects.get(user=user)
+ up.email_addr = claims.get('email')
+ up.save()
+ return user
+
+
class JiraLoginView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
consumer = oauth.Consumer(settings.OAUTH_CONSUMER_KEY, settings.OAUTH_CONSUMER_SECRET)