Exemplo n.º 1
0
    def obj_create(self, bundle, **kwargs):
        
        if 'username' not in bundle.data:
            raise BadRequest(_(u'Username missing'))
        
        if 'password' not in bundle.data:
            raise BadRequest(_(u'Password missing'))
        
        username = bundle.data['username']
        password = bundle.data['password']
        
        u = authenticate(username=username, password=password)
        if u is not None:
            if u.is_active:
                login(bundle.request,u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'login'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR','0.0.0.0')
                tracker.agent =bundle.request.META.get('HTTP_USER_AGENT','unknown')
                tracker.save()
            else:
                raise BadRequest(_(u'Authentication failure'))
        else:
            raise BadRequest(_(u'Authentication failure'))

        del bundle.data['password']
        key = ApiKey.objects.get(user = u)
        bundle.data['api_key'] = key.key
        bundle.obj = u 
        return bundle 
Exemplo n.º 2
0
def course_activity_view(request, course_id, activity_id):
    course = can_view_course(request, course_id)
    activity = Activity.objects.get(pk=activity_id)
    
    # log the activity in the tracker
    tracker = Tracker()
    tracker.user = request.user
    tracker.course = course
    tracker.type = activity.type 
    tracker.data = ""
    tracker.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
    tracker.agent = request.META.get('HTTP_USER_AGENT','unknown')
    tracker.activity_title = activity.title
    tracker.section_title = activity.section.title
    tracker.save()
    
    if activity.type == "page":
        activity_content_file = activity.get_content()
        
        with codecs.open(settings.MEDIA_ROOT + "courses/" + course.shortname + "/" + activity_content_file, "r", "utf-8") as f:
            s = f.read()
        
        template = re.compile('\<body(?P<body>.*?)>(?P<content>.*)\<\/body\>', re.DOTALL)
        
        activity_content = template.search(s).group('content')
        activity_content =  activity_content.replace("images/",settings.MEDIA_URL + "courses/" + course.shortname + "/images/")
        
        return render_to_response('oppia/preview/course_activity_page.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request))
    else:
        activity_content= None
        return render_to_response('oppia/preview/course_activity_not_supported.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request)) 
Exemplo n.º 3
0
    def obj_create(self, bundle, **kwargs):

        if "username" not in bundle.data:
            raise BadRequest(_(u"Username missing"))

        if "password" not in bundle.data:
            raise BadRequest(_(u"Password missing"))

        username = bundle.data["username"]
        password = bundle.data["password"]

        u = authenticate(username=username, password=password)
        if u is not None:
            if u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = "login"
                tracker.ip = bundle.request.META.get("REMOTE_ADDR", "0.0.0.0")
                tracker.agent = bundle.request.META.get("HTTP_USER_AGENT", "unknown")
                tracker.save()
            else:
                raise BadRequest(_(u"Authentication failure"))
        else:
            raise BadRequest(_(u"Authentication failure"))

        del bundle.data["password"]
        key = ApiKey.objects.get(user=u)
        bundle.data["api_key"] = key.key
        bundle.obj = u
        return bundle
Exemplo n.º 4
0
def course_activity_view(request, course_id, activity_id):
    course = check_can_view(request, course_id)
    activity = Activity.objects.get(pk=activity_id)
    
    # log the activity in the tracker
    tracker = Tracker()
    tracker.user = request.user
    tracker.course = course
    tracker.type = activity.type 
    tracker.data = ""
    tracker.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
    tracker.agent = request.META.get('HTTP_USER_AGENT','unknown')
    tracker.activity_title = activity.title
    tracker.section_title = activity.section.title
    tracker.save()
    
    if activity.type == "page":
        activity_content_file = activity.get_content()
        
        with codecs.open(settings.MEDIA_ROOT + "courses/" + course.shortname + "/" + activity_content_file, "r", "utf-8") as f:
            s = f.read()
        
        template = re.compile('\<body(?P<body>.*?)>(?P<content>.*)\<\/body\>', re.DOTALL)
        
        activity_content = template.search(s).group('content')
        activity_content =  activity_content.replace("images/",settings.MEDIA_URL + "courses/" + course.shortname + "/images/")
        
        return render_to_response('oppia/preview/course_activity_page.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request))
    else:
        activity_content= None
        return render_to_response('oppia/preview/course_activity_not_supported.html',
                                  {'course': course, 'activity': activity , 'content' : activity_content }, 
                                  context_instance=RequestContext(request)) 
Exemplo n.º 5
0
    def obj_create(self, bundle, **kwargs):

        if 'username' not in bundle.data:
            raise BadRequest(_(u'Username missing'))

        if 'password' not in bundle.data:
            raise BadRequest(_(u'Password missing'))

        username = bundle.data['username']
        password = bundle.data['password']

        u = authenticate(username=username, password=password)
        if u is not None:
            if u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'login'
                tracker.ip = bundle.request.META.get(
                    'REMOTE_ADDR', oppia.api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get(
                    'HTTP_USER_AGENT', 'unknown')
                tracker.save()
            else:
                raise BadRequest(_(u'Authentication failure'))
        else:
            raise BadRequest(_(u'Authentication failure'))

        del bundle.data['password']
        key = ApiKey.objects.get(user=u)
        bundle.data['api_key'] = key.key
        bundle.obj = u
        return bundle
Exemplo n.º 6
0
    def download_course(self, request, **kwargs):
        self.is_authenticated(request)
        self.throttle_check(request)
        
        pk = kwargs.pop('pk', None)
        try:
            if request.user.is_staff:
                course = self._meta.queryset.get(pk = pk,is_archived=False)
            else:
                course = self._meta.queryset.get(pk = pk, is_archived=False,is_draft=False)
        except Course.DoesNotExist:
            raise Http404(_(u"Course not found"))
        except ValueError:
            try:
                if request.user.is_staff:
                    course = self._meta.queryset.get(shortname = pk,is_archived=False)
                else:
                    course = self._meta.queryset.get(shortname = pk, is_archived=False,is_draft=False)
            except Course.DoesNotExist:
                raise Http404(_(u"Course not found"))
         
        file_to_download = course.getAbsPath();
        schedule = course.get_default_schedule()
        has_completed_trackers = Tracker.has_completed_trackers(course,request.user)
        cohort = Cohort.member_now(course,request.user)
        if cohort:
            if cohort.schedule:
                schedule = cohort.schedule
        
        # add scheduling XML file     
        if schedule or has_completed_trackers:
            file_to_download = settings.COURSE_UPLOAD_DIR +"temp/"+ str(request.user.id) + "-" + course.filename
            shutil.copy2(course.getAbsPath(), file_to_download)
            zip = zipfile.ZipFile(file_to_download,'a')
            if schedule:
                zip.writestr(course.shortname +"/schedule.xml",schedule.to_xml_string())
            if has_completed_trackers:
                zip.writestr(course.shortname +"/tracker.xml",Tracker.to_xml_string(course,request.user))
            zip.close()

        wrapper = FileWrapper(file(file_to_download))
        response = HttpResponse(wrapper, content_type='application/zip')
        response['Content-Length'] = os.path.getsize(file_to_download)
        response['Content-Disposition'] = 'attachment; filename="%s"' %(course.filename)
        
        # Add to tracker
        tracker = Tracker()
        tracker.user = request.user
        tracker.course = course
        tracker.type = 'download'
        tracker.data = json.dumps({'version':course.version })
        tracker.ip = request.META.get('REMOTE_ADDR','0.0.0.0')
        tracker.agent = request.META.get('HTTP_USER_AGENT','unknown')
        tracker.save()
                
        course_downloaded.send(sender=self, course=course, user=request.user)
        
        return response
Exemplo n.º 7
0
def course_downloaded_callback(sender, **kwargs):
    request = kwargs.get('request')
    course = kwargs.get('course')

    tracker = Tracker()
    tracker.user = request.user
    tracker.course = course
    tracker.type = 'download'
    tracker.data = json.dumps({'version': course.version})
    tracker.ip = request.META.get('REMOTE_ADDR', DEFAULT_IP_ADDRESS)
    tracker.agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    tracker.save()
Exemplo n.º 8
0
def record_mobile_tracker(request, course_id, type, page):
    t = Tracker()
    t.user = request.user
    t.ip = request.META.get("REMOTE_ADDR", "0.0.0.0")
    t.agent = request.META.get("HTTP_USER_AGENT", "unknown")
    t.digest = ""
    t.data = ""
    t.course = course_id
    t.type = type
    t.completed = True
    t.activity_title = page
    t.save()
    return
Exemplo n.º 9
0
def record_mobile_tracker(request, course_id, type, page):
    t = Tracker()
    t.user = request.user
    t.ip = request.META.get('REMOTE_ADDR', oppia.DEFAULT_IP_ADDRESS)
    t.agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    t.digest = ""
    t.data = ""
    t.course = course_id
    t.type = type
    t.completed = True
    t.activity_title = page
    t.save()
    return
Exemplo n.º 10
0
def record_mobile_tracker(request, course_id, type, page):
    t = Tracker()
    t.user = request.user
    t.ip = request.META.get('REMOTE_ADDR', oppia.DEFAULT_IP_ADDRESS)
    t.agent = request.META.get('HTTP_USER_AGENT', 'unknown')
    t.digest = ""
    t.data = ""
    t.course = course_id
    t.type = type
    t.completed = True
    t.activity_title = page
    t.save()
    return
Exemplo n.º 11
0
    def obj_create(self, bundle, **kwargs):

        if 'username' not in bundle.data:
            raise BadRequest(_(u'Username missing'))

        if 'password' not in bundle.data:
            raise BadRequest(_(u'Password missing'))

        username = bundle.data['username']
        password = bundle.data['password']

        u = authenticate(username=username, password=password)
        if u is not None and u.is_active:
            login(bundle.request, u)
            # Add to tracker
            tracker = Tracker()
            tracker.user = u
            tracker.type = 'login'
            tracker.ip = bundle.request.META.get('REMOTE_ADDR',
                                                 DEFAULT_IP_ADDRESS)
            tracker.agent = bundle.request.META.get('HTTP_USER_AGENT',
                                                    'unknown')
            tracker.save()
        else:
            raise BadRequest(_(u'Authentication failure'))

        del bundle.data['password']
        key = ApiKey.objects.get(user=u)
        bundle.data['api_key'] = key.key

        try:
            up = UserProfile.objects.get(user__username=username)
            job_title = up.job_title
            organisation = up.organisation
        except UserProfile.DoesNotExist:
            job_title = ""
            organisation = ""

        bundle.data['job_title'] = job_title
        bundle.data['organisation'] = organisation
        bundle.obj = u
        return bundle
Exemplo n.º 12
0
 def obj_create(self, bundle, **kwargs):
     if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
         raise BadRequest(_(u'Registration is disabled on this server.'))
     required = ['username','password','passwordagain', 'email', 'firstname', 'lastname']
     for r in required:
         try:
             bundle.data[r]
         except KeyError:
             raise BadRequest(_(u'Please enter your %s') % r)
     data = {'username': bundle.data['username'],
             'password': bundle.data['password'],
             'password_again': bundle.data['passwordagain'],
             'email': bundle.data['email'],
             'first_name': bundle.data['firstname'],
             'last_name': bundle.data['lastname'],}
     rf = RegisterForm(data)
     if not rf.is_valid():
         str = ""
         for key, value in rf.errors.items():
             for error in value:
                 str += error + "\n"
         raise BadRequest(str)
     else:
         username = bundle.data['username']
         password = bundle.data['password']
         email = bundle.data['email']
         first_name = bundle.data['firstname']
         last_name = bundle.data['lastname']
     try:
         bundle.obj = User.objects.create_user(username, email, password)
         bundle.obj.first_name = first_name
         bundle.obj.last_name = last_name
         bundle.obj.save()
         
         user_profile = UserProfile()
         user_profile.user = bundle.obj
         if 'jobtitle' in bundle.data:
             user_profile.job_title = bundle.data['jobtitle']
         if 'organisation' in bundle.data:
             user_profile.organisation = bundle.data['organisation']
         if 'phoneno' in bundle.data:
             user_profile.phone_number= bundle.data['phoneno']
         user_profile.save()
         
         u = authenticate(username=username, password=password)
         if u is not None:
             if u.is_active:
                 login(bundle.request, u)
                 # Add to tracker
                 tracker = Tracker()
                 tracker.user = u
                 tracker.type = 'register'
                 tracker.ip = bundle.request.META.get('REMOTE_ADDR','0.0.0.0')
                 tracker.agent =bundle.request.META.get('HTTP_USER_AGENT','unknown')
                 tracker.save()
         key = ApiKey.objects.get(user = u)
         bundle.data['api_key'] = key.key
     except IntegrityError:
         raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
     del bundle.data['passwordagain']
     del bundle.data['password']
     del bundle.data['firstname']
     del bundle.data['lastname']
     return bundle   
Exemplo n.º 13
0
    def obj_create(self, bundle, **kwargs):
        if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = ['username',
                    'password',
                    'passwordagain', 
                    'email', 
                    'firstname', 
                    'lastname',
                    'sex',
                    'age_range',
                    'role',
                    'location']

        check_required_params(bundle, required)

        data = {'username': bundle.data['username'],
                'password': bundle.data['password'],
                'password_again': bundle.data['passwordagain'],
                'email': bundle.data['email'],
                'sex': bundle.data['sex'],
                'age_range': bundle.data['age_range'],
                'role': bundle.data['role'],
                'location': bundle.data['location'],
                'first_name': bundle.data['firstname'],
                'last_name': bundle.data['lastname'], }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email']
            first_name = bundle.data['firstname']
            last_name = bundle.data['lastname']
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            user_profile.sex = bundle.data['sex']
            user_profile.age_range = bundle.data['age_range']
            user_profile.role = bundle.data['role']
            user_profile.location = bundle.data['location']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'register'
                tracker.ip = bundle.request.META.get('REMOTE_ADDR', oppia.api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get('HTTP_USER_AGENT', 'unknown')
                tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        del bundle.data['age_range'] 
        del bundle.data['role'] 
        del bundle.data['location'] 
        return bundle   
Exemplo n.º 14
0
    def obj_create(self, bundle, **kwargs):
        if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
            raise BadRequest(_(u"Registration is disabled on this server."))
        required = ["username", "password", "passwordagain", "email", "firstname", "lastname"]
        for r in required:
            try:
                bundle.data[r]
            except KeyError:
                raise BadRequest(_(u"Please enter your %s") % r)
        data = {
            "username": bundle.data["username"],
            "password": bundle.data["password"],
            "password_again": bundle.data["passwordagain"],
            "email": bundle.data["email"],
            "first_name": bundle.data["firstname"],
            "last_name": bundle.data["lastname"],
        }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data["username"]
            password = bundle.data["password"]
            email = bundle.data["email"]
            first_name = bundle.data["firstname"]
            last_name = bundle.data["lastname"]
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            if "jobtitle" in bundle.data:
                user_profile.job_title = bundle.data["jobtitle"]
            if "organisation" in bundle.data:
                user_profile.organisation = bundle.data["organisation"]
            if "phoneno" in bundle.data:
                user_profile.phone_number = bundle.data["phoneno"]
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None:
                if u.is_active:
                    login(bundle.request, u)
                    # Add to tracker
                    tracker = Tracker()
                    tracker.user = u
                    tracker.type = "register"
                    tracker.ip = bundle.request.META.get("REMOTE_ADDR", "0.0.0.0")
                    tracker.agent = bundle.request.META.get("HTTP_USER_AGENT", "unknown")
                    tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data["api_key"] = key.key
        except IntegrityError:
            raise BadRequest(_(u'Username "%s" already in use, please select another' % username))
        del bundle.data["passwordagain"]
        del bundle.data["password"]
        del bundle.data["firstname"]
        del bundle.data["lastname"]
        return bundle
Exemplo n.º 15
0
    def obj_create(self, bundle, **kwargs):
        if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = [
            'username', 'password', 'passwordagain', 'email', 'firstname',
            'lastname'
        ]

        check_required_params(bundle, required)

        data = {
            'username': bundle.data['username'],
            'password': bundle.data['password'],
            'password_again': bundle.data['passwordagain'],
            'email': bundle.data['email'],
            'first_name': bundle.data['firstname'],
            'last_name': bundle.data['lastname'],
        }
        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email']
            first_name = bundle.data['firstname']
            last_name = bundle.data['lastname']
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            if 'jobtitle' in bundle.data:
                user_profile.job_title = bundle.data['jobtitle']
            if 'organisation' in bundle.data:
                user_profile.organisation = bundle.data['organisation']
            if 'phoneno' in bundle.data:
                user_profile.phone_number = bundle.data['phoneno']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None and u.is_active:
                login(bundle.request, u)
                # Add to tracker
                tracker = Tracker()
                tracker.user = u
                tracker.type = 'register'
                tracker.ip = bundle.request.META.get(
                    'REMOTE_ADDR', oppia.api.DEFAULT_IP_ADDRESS)
                tracker.agent = bundle.request.META.get(
                    'HTTP_USER_AGENT', 'unknown')
                tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(
                _(u'Username "%s" already in use, please select another' %
                  username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        return bundle
Exemplo n.º 16
0
    def obj_create(self, bundle, **kwargs):
        self_register = SettingProperties \
            .get_bool(constants.OPPIA_ALLOW_SELF_REGISTRATION,
                      settings.OPPIA_ALLOW_SELF_REGISTRATION)
        if not self_register:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = [
            'username', 'password', 'passwordagain', 'first_name', 'last_name'
        ]
        check_required_params(bundle, required)

        data = {
            'username': bundle.data['username'],
            'password': bundle.data['password'],
            'password_again': bundle.data['passwordagain'],
            'email': bundle.data['email'] if 'email' in bundle.data else '',
            'first_name': bundle.data['first_name'],
            'last_name': bundle.data['last_name'],
        }

        custom_fields = CustomField.objects.all()
        for custom_field in custom_fields:
            try:
                data[custom_field.id] = bundle.data[custom_field.id]
            except KeyError:
                pass

        rf = RegisterForm(data)
        if not rf.is_valid():
            str = ""
            for key, value in rf.errors.items():
                for error in value:
                    str += error + "\n"
            raise BadRequest(str)
        else:
            username = bundle.data['username']
            password = bundle.data['password']
            email = bundle.data['email'] if 'email' in bundle.data else '',
            first_name = bundle.data['first_name']
            last_name = bundle.data['last_name']

        try:
            bundle.obj = User.objects.create_user(username=username,
                                                  password=password)
            bundle.obj.first_name = first_name
            bundle.obj.email = email
            bundle.obj.last_name = last_name
            bundle.obj.save()
        except IntegrityError:
            raise BadRequest(
                _(u'Username "%s" already in use, please select another' %
                  username))

        self.process_register_base_profile(bundle)

        self.process_register_custom_fields(bundle)

        u = authenticate(username=username, password=password)
        if u is not None and u.is_active:
            login(bundle.request, u)
            # Add to tracker
            tracker = Tracker()
            tracker.user = u
            tracker.type = 'register'
            tracker.ip = bundle.request.META.get('REMOTE_ADDR',
                                                 DEFAULT_IP_ADDRESS)
            tracker.agent = bundle.request.META.get('HTTP_USER_AGENT',
                                                    'unknown')
            tracker.save()
        key = ApiKey.objects.get(user=u)
        bundle.data['api_key'] = key.key

        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['first_name']
        del bundle.data['last_name']
        return bundle
Exemplo n.º 17
0
    def obj_create(self, bundle, **kwargs):
        if not settings.OPPIA_ALLOW_SELF_REGISTRATION:
            raise BadRequest(_(u'Registration is disabled on this server.'))
        required = [
            'username', 'password', 'passwordagain', 'email', 'firstname',
            'lastname', 'status', 'gender'
        ]
        for r in required:
            try:
                bundle.data[r]
            except KeyError:
                raise BadRequest(_(u'Please enter your %s') % r)
        data = {
            'username': bundle.data['username'],
            'password': bundle.data['password'],
            'password_again': bundle.data['passwordagain'],
            'email': bundle.data['email'],
            'first_name': bundle.data['firstname'],
            'last_name': bundle.data['lastname'],
            'phone_number': bundle.data['phone_number'],
            'status': bundle.data['status'],
            'year_group': bundle.data['year_group'],
            'home_town': bundle.data['home_town'],
            'program': bundle.data['program'],
            'school_code': bundle.data['school_code'],
        }
        #rf = RegisterForm(data)
        #if not rf.is_valid():
        #   str = ""
        #  for key, value in rf.errors.items():
        #     for error in value:
        #        str += error + "\n"
        #raise BadRequest(str)
        #else:
        username = bundle.data['username']
        password = bundle.data['password']
        email = bundle.data['email']
        first_name = bundle.data['firstname']
        last_name = bundle.data['lastname']
        school_code_existing = SchoolCode.objects.filter(
            school_code=bundle.data['school_code'], ).exists()

        if not school_code_existing and bundle.data['status'] != "Guest":
            raise BadRequest(_(u'This school code does not exist!'))
        if bundle.data['status'] == "Select":
            raise BadRequest(_(u'Status is required'))
        if bundle.data['year_group'] == "Select":
            raise BadRequest(_(u'Year group is required'))
        if bundle.data['program'] == "Select":
            raise BadRequest(_(u'Program is required'))
        if bundle.data['program'] == "":
            raise BadRequest(_(u'Program is required'))
        if bundle.data['status'] == "":
            raise BadRequest(_(u'Status is required'))
        if bundle.data['year_group'] == "":
            raise BadRequest(_(u'Year group is required'))
        try:
            bundle.obj = User.objects.create_user(username, email, password)
            bundle.obj.first_name = first_name
            bundle.obj.last_name = last_name
            bundle.obj.save()

            user_profile = UserProfile()
            user_profile.user = bundle.obj
            user_profile.phone_number = bundle.data['phone_number']
            user_profile.status = bundle.data['status']
            user_profile.year_group = bundle.data['year_group']
            user_profile.home_town = bundle.data['home_town']
            user_profile.program = bundle.data['program']
            user_profile.school_code = bundle.data['school_code']
            #if 'jobtitle' in bundle.data:
            #    user_profile.job_title = bundle.data['jobtitle']
            #if 'organisation' in bundle.data:
            #   user_profile.organisation = bundle.data['organisation']
            user_profile.save()

            u = authenticate(username=username, password=password)
            if u is not None:
                if u.is_active:
                    login(bundle.request, u)
                    # Add to tracker
                    tracker = Tracker()
                    tracker.user = u
                    tracker.type = 'register'
                    tracker.ip = bundle.request.META.get(
                        'REMOTE_ADDR', '0.0.0.0')
                    tracker.agent = bundle.request.META.get(
                        'HTTP_USER_AGENT', 'unknown')
                    tracker.save()
            key = ApiKey.objects.get(user=u)
            bundle.data['api_key'] = key.key
        except IntegrityError:
            raise BadRequest(
                _(u'Username "%s" already in use, please select another' %
                  username))
        del bundle.data['passwordagain']
        del bundle.data['password']
        del bundle.data['firstname']
        del bundle.data['lastname']
        return bundle