Commit 3dc4fd75 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added additional error handling to the CAS callback

parent 661404b9
# standard library imports
from __future__ import absolute_import, print_function, unicode_literals
# core django imports
from django.conf import settings
from django.contrib.auth.models import User
......@@ -13,10 +15,12 @@ def pfinfo(u_name):
pf_url = settings.PF_URL
url = str(pf_url) + "basic/all/" + str(u_name)
metadata = requests.get(url)
metadata = requests.get(url, timeout=3)
print("Retrieving information from the peoplefinder api.")
except requests.exceptions.RequestException as e:
print e
print("Cannot resolve to peoplefinder api:", e)
return ['', '']
pf_json = metadata.json()
......@@ -25,19 +29,24 @@ def pfinfo(u_name):
# if the name is not in peoplefinder, return empty first and last name
except IndexError:
return ['', '']
except Exception as e:
print("Unknown peoplefinder error:", e)
return ['', '']
def create_user(tree):
print("Parsing CAS information.")
username = tree[0][0].text
print username
user, user_created = User.objects.get_or_create(username=username)
if user_created: = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
print("Added user email and default password.")
irrelevant_password = User.objects.make_random_password()
print("Added user email, %s, and created random password." %
print "Start peoplefinder parsing"
print("Start peoplefinder parsing")
name_list = pfinfo(str(username))
print name_list, "name_list"
......@@ -59,7 +68,6 @@ def create_user(tree):
print("User object already exists.")
# Student Creation Section
......@@ -76,4 +84,3 @@ def create_user(tree):
print("Created student object for user %s!" % username)
print("CAS callback completed.")
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