Commit a89a36d3 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

modified exception handling for pf failure and added default password

parent 304c9f55
...@@ -36,6 +36,8 @@ def pfinfo(uname): ...@@ -36,6 +36,8 @@ def pfinfo(uname):
metadata.raise_for_status() metadata.raise_for_status()
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print("Cannot resolve to peoplefinder api:", e) print("Cannot resolve to peoplefinder api:", e)
print("Returning empty user info tuple.")
return ([u'', u''], u'')
else: else:
pfjson = metadata.json() pfjson = metadata.json()
try: try:
...@@ -67,6 +69,8 @@ def pfinfo(uname): ...@@ -67,6 +69,8 @@ def pfinfo(uname):
return final_tuple return final_tuple
except Exception as e: except Exception as e:
print("Unknown peoplefinder error:", e) print("Unknown peoplefinder error:", e)
print("Returning empty user info tuple.")
return ([u'', u''], u'')
def create_user(tree): def create_user(tree):
...@@ -75,14 +79,22 @@ def create_user(tree): ...@@ -75,14 +79,22 @@ def create_user(tree):
try: try:
username = tree[0][0].text username = tree[0][0].text
user, user_created = User.objects.get_or_create(username=username) user, user_created = User.objects.get_or_create(username=username)
info_tuple = pfinfo(username) except Exception as e:
print("CAS callback unsuccessful:", e)
# error handling in pfinfo function
info_tuple = pfinfo(username)
try:
if user_created: if user_created:
print("Created user object %s." % username) print("Created user object %s." % username)
# set and save the user's email # set and save the user's email
email_str = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN) email_str = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
user.email = email_str user.email = email_str
# Password is a required User object field, though doesn't matter for our
# purposes because all user auth is handled through CAS, not Django's login.
user.password = 'cas_used_instead'
user.save() user.save()
print("Added user's email, %s." % email_str) print("Added user's email, %s." % email_str)
...@@ -136,7 +148,6 @@ def create_user(tree): ...@@ -136,7 +148,6 @@ def create_user(tree):
print("Student object creation process completed.") print("Student object creation process completed.")
print("CAS callback successful.") print("CAS callback successful.")
# if all else fails...
except Exception as e: except Exception as e:
print("CAS callback unsuccessful:", e) print("Unhandled user creation error:", e)
# mail the administrators
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment