Changeset 10510 for main/waeup.cas/trunk


Ignore:
Timestamp:
20 Aug 2013, 08:08:12 (11 years ago)
Author:
Henrik Bettermann
Message:

Catch errors caused by Moodle and display them in the browser.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/authenticators.py

    r10509 r10510  
    22"""
    33import re
     4import sys
    45from pkg_resources import iter_entry_points
    56try:
     
    216217                             'email':student['email']}])
    217218                    except xmlrpclib.Fault:
     219                        faultstring = sys.exc_info()[1].faultString
     220                        if not 'Username already exists' in faultstring:
     221                            return (False, faultstring)
    218222                        # user exists
    219223                        pass
    220                     result = moodle.core_user_get_users([
    221                         {'key':'username', 'value':username}])
     224                    try:
     225                        result = moodle.core_user_get_users([
     226                            {'key':'username', 'value':username}])
     227                    except xmlrpclib.Fault:
     228                        faultstring = sys.exc_info()[1].faultString
     229                        return (False, faultstring)
    222230                    user_id = result['users'][0]['id']
    223231                    # Due to a lack of Moodle (Moodle requires an LDAP
     
    225233                    # be set when the user is created. It must be updated
    226234                    # after creation.
    227                     result = moodle.core_user_update_users([
    228                         {'id':user_id,'auth':'cas'}])
     235                    try:
     236                        result = moodle.core_user_update_users([
     237                            {'id':user_id,'auth':'cas'}])
     238                    except xmlrpclib.Fault:
     239                        faultstring = sys.exc_info()[1].faultString
     240                        return (False, faultstring)
    229241                return (True, '')
    230242        return (False, 'Invalid username or password.')
Note: See TracChangeset for help on using the changeset viewer.