Index: main/waeup.cas/trunk/waeup/cas/authenticators.py
===================================================================
--- main/waeup.cas/trunk/waeup/cas/authenticators.py	(revision 10522)
+++ main/waeup.cas/trunk/waeup/cas/authenticators.py	(revision 10523)
@@ -159,8 +159,9 @@
         """
         for backend_name, backend in self.backends.items():
-            if not re.match(backend['marker'], username):
-                continue
-            # remove school marker
-            username = RE_SCHOOL_MARKER.sub('', username)
+            if backend['marker']:
+                if not re.match(backend['marker'], username):
+                    continue
+                # remove school marker
+                username = RE_SCHOOL_MARKER.sub('', username)
             proxy = xmlrpclib.ServerProxy(
                 backend['url'], allow_none=True)
@@ -204,4 +205,8 @@
         except xmlrpclib.Fault:
             faultstring = sys.exc_info()[1].faultString
+            if 'Email address already exists' in faultstring:
+                return (False,
+                    'Another Moodle user is using the same email address.'
+                    ' Email addresses can\'t be used twice in Moodle.')
             if not 'Username already exists' in faultstring:
                 return (False, faultstring)
@@ -229,22 +234,25 @@
         """
         for backend_name, backend in self.backends.items():
-            if not re.match(backend['marker'], username):
-                continue
-            # remove school marker
-            username = RE_SCHOOL_MARKER.sub('', username)
+            if backend['marker']:
+                if not re.match(backend['marker'], username):
+                    continue
+                # remove school marker
+                kofa_username = RE_SCHOOL_MARKER.sub('', username)
+            else:
+                kofa_username = username
             proxy = xmlrpclib.ServerProxy(
                 backend['url'], allow_none=True)
             moodle = xmlrpclib.ServerProxy(
                 backend['moodle_url'], allow_none=True)
-            principal = proxy.check_applicant_credentials(username, password)
+            principal = proxy.check_applicant_credentials(kofa_username, password)
             if principal is None:
-                principal = proxy.check_student_credentials(username, password)
+                principal = proxy.check_student_credentials(kofa_username, password)
             if principal is None:
                 return (False, 'Invalid username or password')
             if principal['type'] == 'student':
-                userdata = proxy.get_student_moodle_data(username)
+                userdata = proxy.get_student_moodle_data(kofa_username)
                 return self._create_user(username, userdata, moodle)
             if principal['type'] == 'applicant':
-                userdata = proxy.get_applicant_moodle_data(username)
+                userdata = proxy.get_applicant_moodle_data(kofa_username)
                 return self._create_user(username, userdata, moodle)
             return (False, 'User not eligible')
Index: main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py
===================================================================
--- main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py	(revision 10522)
+++ main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py	(revision 10523)
@@ -1,3 +1,3 @@
-# Tests for waeup.cas.authentictors
+3# Tests for waeup.cas.authentictors
 import os
 import threading
@@ -229,7 +229,7 @@
     def _core_user_create_users(self, arg):
         # fake Moodle core_user_create_users method.
-        if arg[0]['username'] == 'fault1':
+        if arg[0]['username'] == 'school1-fault1':
             raise xmlrpclib.Fault('faultCode', 'faultString')
-        if arg[0]['username'] in ('fault4', 'fault5'):
+        if arg[0]['username'] in ('school1-fault4', 'school1-fault5'):
             raise xmlrpclib.Fault('faultCode', 'Username already exists')
         return None
@@ -237,13 +237,13 @@
     def _core_user_get_users(self, arg):
         # fake Moodle core_user_get_users method.
-        if arg[0]['value'] == 'fault2':
+        if arg[0]['value'] == 'SCHOOL1-fault2':
             raise xmlrpclib.Fault('faultCode', 'faultString')
-        if arg[0]['value'] == 'fault3':
-            return {'users':[{'id':'fault3'}]}
+        if arg[0]['value'] == 'SCHOOL1-fault3':
+            return {'users':[{'id':'SCHOOL1-fault3'}]}
         return {'users':[{'id':'any id'}]}
 
     def _core_user_update_users(self, arg):
         # fake Moodle core_user_update_users method.
-        if arg[0]['id'] == 'fault3':
+        if arg[0]['id'] == 'SCHOOL1-fault3':
             raise xmlrpclib.Fault('faultCode', 'faultString')
         return None
@@ -318,5 +318,5 @@
         self.assertRaises(
             xmlrpclib.Fault, proxy.core_user_create_users,
-            [{'username': 'fault1'}])
+            [{'username': 'school1-fault1'}])
         # test core_user_get_users
         result = proxy.core_user_get_users(
@@ -325,5 +325,5 @@
         self.assertRaises(
             xmlrpclib.Fault, proxy.core_user_get_users,
-            [{'key': 'username', 'value': 'fault2'}])
+            [{'key': 'username', 'value': 'SCHOOL1-fault2'}])
         # test core_user_update_users
         result = proxy.core_user_update_users(
@@ -332,5 +332,5 @@
         self.assertRaises(
             xmlrpclib.Fault, proxy.core_user_update_users,
-            [{'id': 'fault3'}])
+            [{'id': 'SCHOOL1-fault3'}])
         return
 
@@ -359,5 +359,5 @@
         assert result8 == (False, 'User not eligible')
 
-        # exceptions are raised in the follwoing cases
+        # exceptions are raised in the following cases
         result4s = auth.check_credentials('SCHOOL1-fault1', 'biz')
         assert result4s == (False, 'faultString')
