Exemplo n.º 1
0
def lti(request):
    if not get_timeslot():
        return HttpResponse(
            'Login is not available. The system is currently closed.',
            status=403)
    config = getattr(settings, 'PYLTI_CONFIG', dict())
    consumers = config.get('consumers', dict())
    params = dict(request.POST.items())
    headers = request.META
    headers['X-Forwarded-Proto'] = headers['HTTP_X_FORWARDED_PROTO']
    try:
        verify_request_common(consumers, request.build_absolute_uri(),
                              request.method, headers, params)
    except LTIException as e:
        logger.error('LTI exception from canvas; {}'.format(e))
        return HttpResponse("Signature Validation failed!", status=403)

    data = request.POST
    try:
        username = data['lis_person_sourcedid']
        email = data['lis_person_contact_email_primary']
        studentnumber = data['custom_canvas_user_login_id']
        coursecode = data['context_label']
    except KeyError as e:
        logger.error('Invalid post data from canvas; {}; {}'.format(data, e))
        return HttpResponse("Missing data in POST", status=400)

    user = get_user(email, username)
    if user is None:
        user = User(email=email, username=username)
        user.save()
    try:
        meta = user.usermeta
    except UserMeta.DoesNotExist:
        meta = UserMeta(User=user)

    meta.Studentnumber = studentnumber
    if not meta.Overruled:
        if settings.COURSE_CODE_BEP in coursecode:
            meta.EnrolledBEP = True
        elif settings.COURSE_CODE_EXT in coursecode:
            meta.EnrolledBEP = True
            meta.EnrolledExt = True
        else:
            logger.warning(
                'Course code not matched on BEP or EXT for user {}. Code was: {}'
                .format(user, coursecode))

    meta.save()
    meta.TimeSlot.add(get_timeslot())
    meta.save()
    user.save()

    log = CanvasLogin()
    log.Subject = user
    log.save()

    return redirect("{}/login/".format(settings.DOMAIN))
Exemplo n.º 2
0
def lti(request):
    config = getattr(settings, 'PYLTI_CONFIG', dict())
    consumers = config.get('consumers', dict())
    params = dict(request.POST.items())
    headers = request.META
    headers['X-Forwarded-Proto'] = headers['HTTP_X_FORWARDED_PROTO']
    try:
        verify_request_common(consumers, request.build_absolute_uri(),
                              request.method, headers, params)
    except LTIException:
        return HttpResponse("Signature Validation failed!", status=403)

    data = request.POST
    try:
        username = data['lis_person_sourcedid']
        email = data['lis_person_contact_email_primary']
        studentnumber = data['custom_canvas_user_login_id']
        coursecode = data['context_label']
    except KeyError:
        return HttpResponse("Missing data in POST", status=400)

    user = get_user(email, username)
    if user is None:
        user = User(email=email, username=username)
        user.save()
    try:
        meta = user.usermeta
    except UserMeta.DoesNotExist:
        meta = UserMeta(User=user)

    meta.Studentnumber = studentnumber
    if not meta.Overruled:
        if coursecode == '5XEC0':
            meta.EnrolledBEP = True
        elif coursecode == '5XED0':
            meta.EnrolledBEP = True
            meta.EnrolledExt = True

    meta.save()
    meta.TimeSlot.add(get_timeslot())
    meta.save()
    user.save()

    log = CanvasLogin()
    log.Subject = user
    log.save()

    return redirect("https://bep.ele.tue.nl/login")
Exemplo n.º 3
0
    try:
        std = User.objects.create_user('std{}'.format(i),
                                       'std{}@tue.nl'.format(i), 'marketplace')
        std.first_name = "std"
        std.last_name = str(i)
        std.save()
        stds.append(std)
    except:
        print(str(i) + " not created")
    std = User.objects.get(username='******'.format(i))
    try:
        mta = UserMeta()
        mta.Fullname = "student-" + str(i)
        mta.Studentnumber = str(i) + str(i) + str(i) + str(i) + str(i)
        mta.User = std
        mta.EnrolledBEP = True
        mta.save()
        mta.TimeSlot.add(ts)
        mta.save()
        print("usermeta" + str(i))
    except:
        print(str(i) + " usermeta not created")

print("creating the support user")
try:
    supp = User.objects.create_user('janedoe', '*****@*****.**', 'marketplace')
    supp.first_name = "Jane"
    supp.last_name = "Doe"
    supp.groups.add(type3staff)
    supp.save()
except: