Changeset 10523


Ignore:
Timestamp:
22 Aug 2013, 06:52:16 (11 years ago)
Author:
Henrik Bettermann
Message:

Handling school markers in Moodle is a nightmare. We should think about giving up the option of handling several schools with only one Moodle instance.

Location:
main/waeup.cas/trunk/waeup/cas
Files:
2 edited

Legend:

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

    r10522 r10523  
    159159        """
    160160        for backend_name, backend in self.backends.items():
    161             if not re.match(backend['marker'], username):
    162                 continue
    163             # remove school marker
    164             username = RE_SCHOOL_MARKER.sub('', username)
     161            if backend['marker']:
     162                if not re.match(backend['marker'], username):
     163                    continue
     164                # remove school marker
     165                username = RE_SCHOOL_MARKER.sub('', username)
    165166            proxy = xmlrpclib.ServerProxy(
    166167                backend['url'], allow_none=True)
     
    204205        except xmlrpclib.Fault:
    205206            faultstring = sys.exc_info()[1].faultString
     207            if 'Email address already exists' in faultstring:
     208                return (False,
     209                    'Another Moodle user is using the same email address.'
     210                    ' Email addresses can\'t be used twice in Moodle.')
    206211            if not 'Username already exists' in faultstring:
    207212                return (False, faultstring)
     
    229234        """
    230235        for backend_name, backend in self.backends.items():
    231             if not re.match(backend['marker'], username):
    232                 continue
    233             # remove school marker
    234             username = RE_SCHOOL_MARKER.sub('', username)
     236            if backend['marker']:
     237                if not re.match(backend['marker'], username):
     238                    continue
     239                # remove school marker
     240                kofa_username = RE_SCHOOL_MARKER.sub('', username)
     241            else:
     242                kofa_username = username
    235243            proxy = xmlrpclib.ServerProxy(
    236244                backend['url'], allow_none=True)
    237245            moodle = xmlrpclib.ServerProxy(
    238246                backend['moodle_url'], allow_none=True)
    239             principal = proxy.check_applicant_credentials(username, password)
     247            principal = proxy.check_applicant_credentials(kofa_username, password)
    240248            if principal is None:
    241                 principal = proxy.check_student_credentials(username, password)
     249                principal = proxy.check_student_credentials(kofa_username, password)
    242250            if principal is None:
    243251                return (False, 'Invalid username or password')
    244252            if principal['type'] == 'student':
    245                 userdata = proxy.get_student_moodle_data(username)
     253                userdata = proxy.get_student_moodle_data(kofa_username)
    246254                return self._create_user(username, userdata, moodle)
    247255            if principal['type'] == 'applicant':
    248                 userdata = proxy.get_applicant_moodle_data(username)
     256                userdata = proxy.get_applicant_moodle_data(kofa_username)
    249257                return self._create_user(username, userdata, moodle)
    250258            return (False, 'User not eligible')
  • main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py

    r10522 r10523  
    1 # Tests for waeup.cas.authentictors
     13# Tests for waeup.cas.authentictors
    22import os
    33import threading
     
    229229    def _core_user_create_users(self, arg):
    230230        # fake Moodle core_user_create_users method.
    231         if arg[0]['username'] == 'fault1':
     231        if arg[0]['username'] == 'school1-fault1':
    232232            raise xmlrpclib.Fault('faultCode', 'faultString')
    233         if arg[0]['username'] in ('fault4', 'fault5'):
     233        if arg[0]['username'] in ('school1-fault4', 'school1-fault5'):
    234234            raise xmlrpclib.Fault('faultCode', 'Username already exists')
    235235        return None
     
    237237    def _core_user_get_users(self, arg):
    238238        # fake Moodle core_user_get_users method.
    239         if arg[0]['value'] == 'fault2':
     239        if arg[0]['value'] == 'SCHOOL1-fault2':
    240240            raise xmlrpclib.Fault('faultCode', 'faultString')
    241         if arg[0]['value'] == 'fault3':
    242             return {'users':[{'id':'fault3'}]}
     241        if arg[0]['value'] == 'SCHOOL1-fault3':
     242            return {'users':[{'id':'SCHOOL1-fault3'}]}
    243243        return {'users':[{'id':'any id'}]}
    244244
    245245    def _core_user_update_users(self, arg):
    246246        # fake Moodle core_user_update_users method.
    247         if arg[0]['id'] == 'fault3':
     247        if arg[0]['id'] == 'SCHOOL1-fault3':
    248248            raise xmlrpclib.Fault('faultCode', 'faultString')
    249249        return None
     
    318318        self.assertRaises(
    319319            xmlrpclib.Fault, proxy.core_user_create_users,
    320             [{'username': 'fault1'}])
     320            [{'username': 'school1-fault1'}])
    321321        # test core_user_get_users
    322322        result = proxy.core_user_get_users(
     
    325325        self.assertRaises(
    326326            xmlrpclib.Fault, proxy.core_user_get_users,
    327             [{'key': 'username', 'value': 'fault2'}])
     327            [{'key': 'username', 'value': 'SCHOOL1-fault2'}])
    328328        # test core_user_update_users
    329329        result = proxy.core_user_update_users(
     
    332332        self.assertRaises(
    333333            xmlrpclib.Fault, proxy.core_user_update_users,
    334             [{'id': 'fault3'}])
     334            [{'id': 'SCHOOL1-fault3'}])
    335335        return
    336336
     
    359359        assert result8 == (False, 'User not eligible')
    360360
    361         # exceptions are raised in the follwoing cases
     361        # exceptions are raised in the following cases
    362362        result4s = auth.check_credentials('SCHOOL1-fault1', 'biz')
    363363        assert result4s == (False, 'faultString')
Note: See TracChangeset for help on using the changeset viewer.