Index: main/waeup.cas/trunk/waeup/cas/authenticators.py
===================================================================
--- main/waeup.cas/trunk/waeup/cas/authenticators.py	(revision 10516)
+++ main/waeup.cas/trunk/waeup/cas/authenticators.py	(revision 10517)
@@ -189,4 +189,37 @@
     name = 'kofa_moodle1'
 
+    def _create_user(self, username, userdata, moodle):
+        try:
+            # Usernames in Moodle must not contain uppercase
+            # letters even if extendedusernamechars is set True.
+            result = moodle.core_user_create_users([
+                {'username':username.lower(),
+                 'password':'dummy',
+                 'firstname':userdata['firstname'],
+                 'lastname':userdata['lastname'],
+                 'email':userdata['email']}])
+        except xmlrpclib.Fault:
+            faultstring = sys.exc_info()[1].faultString
+            if not 'Username already exists' in faultstring:
+                return (False, faultstring)
+        try:
+            result = moodle.core_user_get_users([
+                {'key':'username', 'value':username}])
+        except xmlrpclib.Fault:
+            faultstring = sys.exc_info()[1].faultString
+            return (False, faultstring)
+        user_id = result['users'][0]['id']
+        # Due to a lack of Moodle (Moodle requires an LDAP
+        # connection) the authentication method can't
+        # be set when the user is created. It must be updated
+        # after creation.
+        try:
+            result = moodle.core_user_update_users([
+                {'id':user_id,'auth':'cas'}])
+        except xmlrpclib.Fault:
+            faultstring = sys.exc_info()[1].faultString
+            return (False, faultstring)
+        return (True, '')
+
     def check_credentials(self, username='', password=''):
         """Do the real check.
@@ -206,35 +239,5 @@
             if principal is not None:
                 if principal['type'] == 'student':
-                    student = proxy.get_student_moodle_data(username)
-                    try:
-                        # Usernames in Moodle must not contain uppercase
-                        # letters even if extendedusernamechars is set True.
-                        result = moodle.core_user_create_users([
-                            {'username':username.lower(),
-                             'password':'dummy',
-                             'firstname':student['firstname'],
-                             'lastname':student['lastname'],
-                             'email':student['email']}])
-                    except xmlrpclib.Fault:
-                        faultstring = sys.exc_info()[1].faultString
-                        if not 'Username already exists' in faultstring:
-                            return (False, faultstring)
-                    try:
-                        result = moodle.core_user_get_users([
-                            {'key':'username', 'value':username}])
-                    except xmlrpclib.Fault:
-                        faultstring = sys.exc_info()[1].faultString
-                        return (False, faultstring)
-                    user_id = result['users'][0]['id']
-                    # Due to a lack of Moodle (Moodle requires an LDAP
-                    # connection) the authentication method can't
-                    # be set when the user is created. It must be updated
-                    # after creation.
-                    try:
-                        result = moodle.core_user_update_users([
-                            {'id':user_id,'auth':'cas'}])
-                    except xmlrpclib.Fault:
-                        faultstring = sys.exc_info()[1].faultString
-                        return (False, faultstring)
-                return (True, '')
+                    userdata = proxy.get_student_moodle_data(username)
+                    return self._create_user(username, userdata, moodle)
         return (False, 'Invalid username or password.')
