cas_callbacks.py 491 Bytes
Newer Older
1
from django.contrib.auth.models import User
Daniel W Bond's avatar
Daniel W Bond committed
2
3
4

from accounts.models import Student

5
6
7
8
9
10
11
12
13
14
from django.conf import settings

def create_user(tree):

    username = tree[0][0].text
    user, user_created = User.objects.get_or_create(username=username)

    if user_created:
        user.email = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
        user.save()
Jason D Yeomans's avatar
Jason D Yeomans committed
15
16
        new_student = Student.objects.create(user=user)
        new_student.save()
17
18

        print("Created user %s!" % username)