def configure_post_login(request, render_dict): if "school_login" in request.POST: form = StudentLoginForm(request.POST, prefix="login") process_form = process_student_login_form render_dict["school_login_form"] = form configure_login_form_captcha(form, render_dict, "student_captcha") elif "independent_student_login" in request.POST: form = IndependentStudentLoginForm(request.POST, prefix="independent_student") process_form = process_indep_student_login_form render_dict["independent_student_login_form"] = form render_dict["independent_student_view"] = True configure_login_form_captcha(form, render_dict, "independent_student_captcha") else: form = TeacherLoginForm(request.POST, prefix="login") process_form = process_login_form render_dict["login_form"] = form configure_login_form_captcha(form, render_dict, "teacher_captcha") return form, process_form, render_dict
def configure_post_login(request, render_dict): if 'school_login' in request.POST: form = StudentLoginForm(request.POST, prefix="login") process_form = process_student_login_form render_dict['school_login_form'] = form configure_login_form_captcha(form, render_dict, 'student_captcha') elif 'independent_student_login' in request.POST: form = IndependentStudentLoginForm(request.POST, prefix='independent_student') process_form = process_indep_student_login_form render_dict['independent_student_login_form'] = form render_dict['independent_student_view'] = True configure_login_form_captcha(form, render_dict, 'independent_student_captcha') else: form = TeacherLoginForm(request.POST, prefix='login') process_form = process_login_form render_dict['login_form'] = form configure_login_form_captcha(form, render_dict, 'teacher_captcha') return form, process_form, render_dict
def play(request): invalid_form = False limits = getattr(request, 'limits', {'ip': [0], 'name': [0]}) ip_captcha_limit = 30 name_captcha_limit = 5 using_captcha = (limits['ip'][0] > ip_captcha_limit or limits['name'][0] >= name_captcha_limit) should_use_captcha = (limits['ip'][0] >= ip_captcha_limit or limits['name'][0] >= name_captcha_limit) StudentLoginFormWithCaptcha = partial( create_form_subclass_with_recaptcha(StudentLoginForm, recaptcha_client), request) InputStudentLoginForm = StudentLoginFormWithCaptcha if using_captcha else StudentLoginForm OutputStudentLoginForm = StudentLoginFormWithCaptcha if should_use_captcha else StudentLoginForm IndependentStudentLoginFormWithCaptcha = partial( create_form_subclass_with_recaptcha(IndependentStudentLoginForm, recaptcha_client), request) InputIndependentStudentLoginForm = IndependentStudentLoginFormWithCaptcha if using_captcha else IndependentStudentLoginForm OutputIndependentStudentLoginForm = IndependentStudentLoginFormWithCaptcha if should_use_captcha else IndependentStudentLoginForm school_login_form = OutputStudentLoginForm(prefix='login') independent_student_login_form = IndependentStudentLoginForm(prefix='independent_student') signup_form = StudentSignupForm(prefix='signup') independent_student_view = False signup_view = False if request.method == 'POST': if 'school_login' in request.POST: school_login_form = InputStudentLoginForm(request.POST, prefix='login') if school_login_form.is_valid(): login(request, school_login_form.user) next_url = request.GET.get('next', None) if next_url: return HttpResponseRedirect(next_url) return HttpResponseRedirect(reverse_lazy('student_details')) else: school_login_form = OutputStudentLoginForm(request.POST, prefix='login') invalid_form = True elif 'independent_student_login' in request.POST: independent_student_login_form = InputIndependentStudentLoginForm(request.POST, prefix='independent_student') if independent_student_login_form.is_valid(): user = independent_student_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, independent_student_login_form.user) next_url = request.GET.get('next', None) if next_url: return HttpResponseRedirect(next_url) return HttpResponseRedirect(reverse_lazy('student_details')) else: independent_student_view = True independent_student_login_form = OutputIndependentStudentLoginForm(request.POST, prefix='independent_student') school_login_form = StudentLoginForm(prefix='login') invalid_form = True elif 'signup' in request.POST: signup_form = StudentSignupForm(request.POST, prefix='signup') if signup_form.is_valid(): data = signup_form.cleaned_data student = Student.objects.independentStudentFactory( username=data['username'], name=data['name'], email=data['email'], password=data['password']) email_supplied = (data['email'] != '') if (email_supplied): send_verification_email(request, student.new_user) return render(request, 'portal/email_verification_needed.html', {'user': student.new_user}) else: # dead code - frontend ensures email supplied. auth_user = authenticate(username=data['username'], password=data['password']) login(request, auth_user) return render(request, 'portal/play/student_details.html') else: signup_view = True res = render(request, 'portal/play.html', { 'school_login_form': school_login_form, 'independent_student_login_form': independent_student_login_form, 'signup_form': signup_form, 'independent_student_view': independent_student_view, 'signup_view': signup_view, }) res.count = invalid_form return res
def render_login_form(request): invalid_form = False teacher_limits = getattr(request, "limits", {"ip": [0], "email": [0]}) teacher_captcha_limit = 5 login_form = TeacherLoginForm(prefix="login") student_limits = getattr(request, "limits", {"ip": [0], "name": [0]}) student_captcha_limit = 30 student_name_captcha_limit = 5 school_login_form = StudentLoginForm(prefix="login") independent_student_login_form = IndependentStudentLoginForm( prefix="independent_student") independent_student_view = False render_dict = { "login_form": login_form, "school_login_form": school_login_form, "independent_student_login_form": independent_student_login_form, "independent_student_view": independent_student_view, "logged_in_as_teacher": is_logged_in_as_teacher(request), "settings": app_settings, "teacher_captcha": compute_teacher_should_use_captcha(teacher_limits, teacher_captcha_limit), "student_captcha": compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), "independent_student_captcha": compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), } configure_login_form_captcha(login_form, render_dict, "teacher_captcha") configure_login_form_captcha(school_login_form, render_dict, "student_captcha") configure_login_form_captcha(independent_student_login_form, render_dict, "independent_student_captcha") if request.method == "POST": form, process_form, render_dict = configure_post_login( request, render_dict) if form.is_valid(): return process_form(request, form) else: invalid_form = True res = render(request, "portal/login.html", render_dict) res.count = invalid_form return res
def render_login_form(request): invalid_form = False teacher_limits = getattr(request, 'limits', {'ip': [0], 'email': [0]}) teacher_captcha_limit = 5 login_form = TeacherLoginForm(prefix='login') student_limits = getattr(request, 'limits', {'ip': [0], 'name': [0]}) student_captcha_limit = 30 student_name_captcha_limit = 5 school_login_form = StudentLoginForm(prefix='login') independent_student_login_form = IndependentStudentLoginForm( prefix='independent_student') independent_student_view = False render_dict = { 'login_form': login_form, 'school_login_form': school_login_form, 'independent_student_login_form': independent_student_login_form, 'independent_student_view': independent_student_view, 'logged_in_as_teacher': is_logged_in_as_teacher(request), 'settings': app_settings, 'teacher_captcha': compute_teacher_should_use_captcha(teacher_limits, teacher_captcha_limit), 'student_captcha': compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), 'independent_student_captcha': compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), } configure_login_form_captcha(login_form, render_dict, 'teacher_captcha') configure_login_form_captcha(school_login_form, render_dict, 'student_captcha') configure_login_form_captcha(independent_student_login_form, render_dict, 'independent_student_captcha') if request.method == 'POST': form, process_form, render_dict = configure_post_login( request, render_dict) if form.is_valid(): return process_form(request, form) else: invalid_form = True res = render(request, 'portal/login.html', render_dict) res.count = invalid_form return res
def render_login_form(request): invalid_form = False teacher_limits = getattr(request, 'limits', {'ip': [0], 'email': [0]}) teacher_captcha_limit = 5 login_form = TeacherLoginForm(prefix='login') student_limits = getattr(request, 'limits', {'ip': [0], 'name': [0]}) student_captcha_limit = 30 student_name_captcha_limit = 5 school_login_form = StudentLoginForm(prefix='login') independent_student_login_form = IndependentStudentLoginForm( prefix='independent_student') independent_student_view = False render_dict = { 'login_form': login_form, 'school_login_form': school_login_form, 'independent_student_login_form': independent_student_login_form, 'independent_student_view': independent_student_view, 'logged_in_as_teacher': is_logged_in_as_teacher(request), 'settings': app_settings, 'teacher_captcha': compute_teacher_should_use_captcha(teacher_limits, teacher_captcha_limit), 'student_captcha': compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), 'independent_student_captcha': compute_student_should_use_captcha(student_limits, student_captcha_limit, student_name_captcha_limit), 'teacher_captcha_visible': False, 'student_captcha_visible': False, 'independent_student_captcha_visible': False, } if request.method == 'POST': if 'school_login' in request.POST: form = StudentLoginForm(request.POST, prefix="login") process_form = process_student_login_form render_dict['school_login_form'] = StudentLoginForm(request.POST, prefix='login') render_dict['student_captcha_visible'] = True form.view_options[ 'is_recaptcha_visible'] = compute_student_use_captcha( student_limits, student_captcha_limit, student_name_captcha_limit) elif 'independent_student_login' in request.POST: form = IndependentStudentLoginForm(request.POST, prefix='independent_student') process_form = process_indep_student_login_form render_dict[ 'independent_student_login_form'] = IndependentStudentLoginForm( request.POST, prefix='independent_student') render_dict['independent_student_view'] = True render_dict['independent_student_captcha_visible'] = True form.view_options[ 'is_recaptcha_visible'] = compute_student_use_captcha( student_limits, student_captcha_limit, student_name_captcha_limit) else: form = TeacherLoginForm(request.POST, prefix='login') process_form = process_login_form render_dict['login_form'] = TeacherLoginForm(request.POST, prefix='login') render_dict['teacher_captcha_visible'] = True form.view_options[ 'is_recaptcha_visible'] = compute_teacher_use_captcha( teacher_limits, teacher_captcha_limit) form.view_options['is_recaptcha_valid'] = check_recaptcha(request) if form.is_valid(): return process_form(request, form) else: invalid_form = True res = render(request, 'portal/login.html', render_dict) res.count = invalid_form return res