From 99dfb2c0e97bce2f8827a6e8eef79b4abb60297a Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Wed, 19 Aug 2020 11:00:50 -0400 Subject: LFID login for both projects Signed-off-by: Sean Smith Change-Id: I4a14dc75d7890a6d395b3f52177a7000ae1a2150 --- src/account/views.py | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'src/account') diff --git a/src/account/views.py b/src/account/views.py index f282369..08da918 100644 --- a/src/account/views.py +++ b/src/account/views.py @@ -61,15 +61,44 @@ class AccountSettingsView(UpdateView): class MyOIDCAB(OIDCAuthenticationBackend): def filter_users_by_claims(self, claims): - email = claims.get('email') - if not email: - return self.User.objects.none() + """ + 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: - profile = UserProfile.objects.get('email') - return profile - except UserProfile.DoesNotExist: - return self.User.objects.none() + # 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): -- cgit 1.2.3-korg