Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
a89a36d3
Commit
a89a36d3
authored
Nov 30, 2015
by
Daniel W Bond
Browse files
modified exception handling for pf failure and added default password
parent
304c9f55
Changes
1
Show whitespace changes
Inline
Side-by-side
roomlist/accounts/cas_callbacks.py
View file @
a89a36d3
...
@@ -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
)
except
Exception
as
e
:
print
(
"CAS callback unsuccessful:"
,
e
)
# error handling in pfinfo function
info_tuple
=
pfinfo
(
username
)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment