Ejemplo n.º 1
0
def render_signup_form(request):
    invalid_form = False

    teacher_signup_form = TeacherSignupForm(prefix='teacher_signup')
    student_signup_form = StudentSignupForm(prefix='student_signup')

    if request.method == 'POST':
        if 'teacher_signup' in request.POST:
            teacher_signup_form = TeacherSignupForm(request.POST,
                                                    prefix='teacher_signup')
            if teacher_signup_form.is_valid():
                data = teacher_signup_form.cleaned_data
                return process_signup_form(request, data)

        else:
            student_signup_form = StudentSignupForm(request.POST,
                                                    prefix='student_signup')
            if student_signup_form.is_valid():
                data = student_signup_form.cleaned_data
                return process_student_signup_form(request, data)

    res = render(
        request, 'portal/register.html', {
            'teacher_signup_form': teacher_signup_form,
            'student_signup_form': student_signup_form,
        })

    res.count = invalid_form
    return res
Ejemplo n.º 2
0
def render_signup_form(request):
    invalid_form = False
    limits = getattr(request, "limits", {"ip": [0]})
    captcha_limit = 5
    should_use_captcha = (limits["ip"][0] >= captcha_limit) and captcha.CAPTCHA_ENABLED

    teacher_signup_form = TeacherSignupForm(prefix="teacher_signup")
    independent_student_signup_form = IndependentStudentSignupForm(
        prefix="independent_student_signup"
    )

    if request.method == "POST":
        if "teacher_signup" in request.POST:
            teacher_signup_form = TeacherSignupForm(
                request.POST, prefix="teacher_signup"
            )

            if not should_use_captcha:
                remove_captcha_from_forms(teacher_signup_form)

            if teacher_signup_form.is_valid():
                data = teacher_signup_form.cleaned_data
                return process_signup_form(request, data)

        else:
            independent_student_signup_form = IndependentStudentSignupForm(
                request.POST, prefix="independent_student_signup"
            )

            if not should_use_captcha:
                remove_captcha_from_forms(independent_student_signup_form)

            if independent_student_signup_form.is_valid():
                data = independent_student_signup_form.cleaned_data
                return process_independent_student_signup_form(request, data)

    res = render(
        request,
        "portal/register.html",
        {
            "teacher_signup_form": teacher_signup_form,
            "independent_student_signup_form": independent_student_signup_form,
            "captcha": should_use_captcha,
        },
    )

    res.count = invalid_form
    return res
Ejemplo n.º 3
0
def render_signup_form(request):
    invalid_form = False
    limits = getattr(request, "limits", {"ip": [0]})
    captcha_limit = 5
    should_use_captcha = (limits["ip"][0] >=
                          captcha_limit) and captcha.CAPTCHA_ENABLED

    teacher_signup_form = TeacherSignupForm(prefix="teacher_signup")
    independent_student_signup_form = IndependentStudentSignupForm(
        prefix="independent_student_signup")

    if request.method == "POST":
        if "teacher_signup" in request.POST:
            teacher_signup_form = TeacherSignupForm(request.POST,
                                                    prefix="teacher_signup")

            if not should_use_captcha:
                remove_captcha_from_forms(teacher_signup_form)

            if teacher_signup_form.is_valid():
                data = teacher_signup_form.cleaned_data
                return process_signup_form(request, data)

        else:
            independent_student_signup_form = IndependentStudentSignupForm(
                request.POST, prefix="independent_student_signup")

            if not should_use_captcha:
                remove_captcha_from_forms(independent_student_signup_form)

            if independent_student_signup_form.is_valid():
                data = independent_student_signup_form.cleaned_data
                return process_independent_student_signup_form(request, data)

    res = render(
        request,
        "portal/register.html",
        {
            "teacher_signup_form": teacher_signup_form,
            "independent_student_signup_form": independent_student_signup_form,
            "captcha": should_use_captcha,
        },
    )

    res.count = invalid_form
    return res
Ejemplo n.º 4
0
def render_signup_form(request):
    invalid_form = False

    signup_form = TeacherSignupForm(prefix='signup')

    if request.method == 'POST':
        signup_form = TeacherSignupForm(request.POST, prefix='signup')
        if signup_form.is_valid():
            data = signup_form.cleaned_data
            return process_signup_form(request, data)

    res = render(request, 'redesign/register.html', {
        'signup_form': signup_form
    })

    res.count = invalid_form
    return res
Ejemplo n.º 5
0
def render_signup_form(request):
    invalid_form = False
    limits = getattr(request, 'limits', {'ip': [0]})
    captcha_limit = 5
    should_use_captcha = (limits['ip'][0] >=
                          captcha_limit) and captcha.CAPTCHA_ENABLED

    teacher_signup_form = TeacherSignupForm(prefix='teacher_signup')
    student_signup_form = StudentSignupForm(prefix='student_signup')

    if request.method == 'POST':
        if 'teacher_signup' in request.POST:
            teacher_signup_form = TeacherSignupForm(request.POST,
                                                    prefix='teacher_signup')

            if not should_use_captcha:
                remove_captcha_from_forms(teacher_signup_form)

            if teacher_signup_form.is_valid():
                data = teacher_signup_form.cleaned_data
                return process_signup_form(request, data)

        else:
            student_signup_form = StudentSignupForm(request.POST,
                                                    prefix='student_signup')

            if not should_use_captcha:
                remove_captcha_from_forms(student_signup_form)

            if student_signup_form.is_valid():
                data = student_signup_form.cleaned_data
                return process_student_signup_form(request, data)

    res = render(
        request, 'portal/register.html', {
            'teacher_signup_form': teacher_signup_form,
            'student_signup_form': student_signup_form,
            'captcha': should_use_captcha,
        })

    res.count = invalid_form
    return res
Ejemplo n.º 6
0
def render_signup_form(request):
    invalid_form = False

    teacher_signup_form = TeacherSignupForm(prefix="teacher_signup")
    independent_student_signup_form = IndependentStudentSignupForm(
        prefix="independent_student_signup"
    )

    if request.method == "POST":
        if "teacher_signup-teacher_email" in request.POST:
            teacher_signup_form = TeacherSignupForm(
                request.POST, prefix="teacher_signup"
            )

            if not captcha.CAPTCHA_ENABLED:
                remove_captcha_from_forms(teacher_signup_form)

            if teacher_signup_form.is_valid():
                data = teacher_signup_form.cleaned_data
                return process_signup_form(request, data)

        else:
            independent_student_signup_form = IndependentStudentSignupForm(
                request.POST, prefix="independent_student_signup"
            )

            if independent_student_signup_form.is_valid():
                data = independent_student_signup_form.cleaned_data
                return process_independent_student_signup_form(request, data)

    res = render(
        request,
        "portal/register.html",
        {
            "teacher_signup_form": teacher_signup_form,
            "independent_student_signup_form": independent_student_signup_form,
        },
    )

    res.count = invalid_form
    return res
Ejemplo n.º 7
0
def teach(request):
    invalid_form = False
    limits = getattr(request, 'limits', {'ip': [0], 'email': [0]})
    captcha_limit = 5

    using_captcha = (limits['ip'][0] > captcha_limit or limits['email'][0] > captcha_limit)
    should_use_captcha = (limits['ip'][0] >= captcha_limit or limits['email'][0] >= captcha_limit)

    LoginFormWithCaptcha = partial(
        create_form_subclass_with_recaptcha(TeacherLoginForm, recaptcha_client), request)
    InputLoginForm = LoginFormWithCaptcha if using_captcha else TeacherLoginForm
    OutputLoginForm = LoginFormWithCaptcha if should_use_captcha else TeacherLoginForm

    login_form = OutputLoginForm(prefix='login')
    signup_form = TeacherSignupForm(prefix='signup')

    if request.method == 'POST':
        if 'login' in request.POST:
            login_form = InputLoginForm(request.POST, prefix='login')
            if login_form.is_valid():
                user = login_form.user
                if not is_verified(user):
                    send_verification_email(request, user)
                    return render(request, 'portal/email_verification_needed.html',
                                  {'user': user})

                login(request, login_form.user)

                if using_two_factor(request.user):
                    return render(request, 'portal/2FA_redirect.html', {
                        'form': AuthenticationForm(),
                        'username': request.user.username,
                        'password': login_form.cleaned_data['password'],
                    })
                else:
                    link = reverse('two_factor:profile')
                    messages.info(
                        request, ("You are not currently set up with two-factor authentication. "
                                  + "Use your phone or tablet to enhance your account's security. "
                                  + "Click <a href='" + link + "'>here</a> to find out more and "
                                  + "set it up or go to your account page at any time."),
                        extra_tags='safe')

                next_url = request.GET.get('next', None)
                if next_url:
                    return HttpResponseRedirect(next_url)

                return HttpResponseRedirect(reverse_lazy('teacher_home'))

            else:
                login_form = OutputLoginForm(request.POST, prefix='login')
                invalid_form = True

        if 'signup' in request.POST:
            signup_form = TeacherSignupForm(request.POST, prefix='signup')
            if signup_form.is_valid():
                data = signup_form.cleaned_data

                teacher = Teacher.objects.factory(
                    title=data['title'],
                    first_name=data['first_name'],
                    last_name=data['last_name'],
                    email=data['email'],
                    password=data['password'])

                send_verification_email(request, teacher.new_user)

                return render(request, 'portal/email_verification_needed.html',
                              {'user': teacher.new_user})

    logged_in_as_teacher = hasattr(request.user, 'userprofile') and \
        hasattr(request.user, 'teacher') and \
        (request.user.is_verified() or not using_two_factor(request.user))

    res = render(request, 'portal/teach.html', {
        'login_form': login_form,
        'signup_form': signup_form,
        'logged_in_as_teacher': logged_in_as_teacher,
    })

    res.count = invalid_form
    return res
Ejemplo n.º 8
0
def teach(request):
    invalid_form = False
    limits = getattr(request, 'limits', {'ip': [0], 'email': [0]})
    captcha_limit = 5

    using_captcha = (limits['ip'][0] > captcha_limit or limits['email'][0] > captcha_limit)
    should_use_captcha = (limits['ip'][0] >= captcha_limit or limits['email'][0] >= captcha_limit)

    LoginFormWithCaptcha = partial(
        create_form_subclass_with_recaptcha(TeacherLoginForm, recaptcha_client), request)
    InputLoginForm = LoginFormWithCaptcha if using_captcha else TeacherLoginForm
    OutputLoginForm = LoginFormWithCaptcha if should_use_captcha else TeacherLoginForm

    login_form = OutputLoginForm(prefix='login')
    signup_form = TeacherSignupForm(prefix='signup')

    if request.method == 'POST':
        if 'login' in request.POST:
            login_form = InputLoginForm(request.POST, prefix='login')
            if login_form.is_valid():
                userProfile = login_form.user.userprofile
                if userProfile.awaiting_email_verification:
                    send_verification_email(request, userProfile)
                    return render(request, 'portal/email_verification_needed.html',
                                  {'userprofile': userProfile})

                login(request, login_form.user)

                if default_device(request.user):
                    return render(request, 'portal/2FA_redirect.html', {
                        'form': AuthenticationForm(),
                        'username': request.user.username,
                        'password': login_form.cleaned_data['password'],
                    })
                else:
                    link = reverse('two_factor:profile')
                    messages.info(
                        request, ("You are not currently set up with two-factor authentication. "
                                  + "Use your phone or tablet to enhance your account's security. "
                                  + "Click <a href='" + link + "'>here</a> to find out more and "
                                  + "set it up or go to your account page at any time."),
                        extra_tags='safe')

                next_url = request.GET.get('next', None)
                if next_url:
                    return HttpResponseRedirect(next_url)

                return HttpResponseRedirect(reverse_lazy('teacher_home'))

            else:
                login_form = OutputLoginForm(request.POST, prefix='login')
                invalid_form = True

        if 'signup' in request.POST:
            signup_form = TeacherSignupForm(request.POST, prefix='signup')
            if signup_form.is_valid():
                data = signup_form.cleaned_data

                teacher = Teacher.objects.factory(
                    title=data['title'],
                    first_name=data['first_name'],
                    last_name=data['last_name'],
                    email=data['email'],
                    password=data['password'])

                send_verification_email(request, teacher.user)

                return render(request, 'portal/email_verification_needed.html',
                              {'userprofile': teacher.user})

    logged_in_as_teacher = hasattr(request.user, 'userprofile') and \
        hasattr(request.user.userprofile, 'teacher') and \
        (request.user.is_verified() or not default_device(request.user))

    res = render(request, 'portal/teach.html', {
        'login_form': login_form,
        'signup_form': signup_form,
        'logged_in_as_teacher': logged_in_as_teacher,
    })

    res.count = invalid_form
    return res