aboutsummaryrefslogtreecommitdiffstats
path: root/src/account
diff options
context:
space:
mode:
authorSean Smith <ssmith@iol.unh.edu>2020-08-19 11:00:50 -0400
committerAdam Hassick <ahassick@iol.unh.edu>2020-12-04 14:20:41 -0500
commit99dfb2c0e97bce2f8827a6e8eef79b4abb60297a (patch)
tree1027fd9493400f9d1f545153f94d68ed3d27fd4b /src/account
parent2418587ae1a7ad463988c14cc9b0d9a2f9cf0e95 (diff)
LFID login for both projects2.1.0-rc1
Signed-off-by: Sean Smith <ssmith@iol.unh.edu> Change-Id: I4a14dc75d7890a6d395b3f52177a7000ae1a2150
Diffstat (limited to 'src/account')
-rw-r--r--src/account/views.py43
1 files changed, 36 insertions, 7 deletions
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):