Esempio n. 1
0
def process_login_form(request, login_form):
    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)

    teacher = request.user.userprofile.teacher

    return redirect_user_to_correct_page(teacher)
Esempio n. 2
0
def process_update_account_form(request, teacher):
    update_account_form = TeacherEditAccountForm(request.user, request.POST)
    changing_email = False
    new_email = ""
    if update_account_form.is_valid():
        data = update_account_form.cleaned_data
        changing_email = False

        # check not default value for CharField
        if (data['password'] != ''):
            teacher.new_user.set_password(data['password'])
            teacher.new_user.save()
            update_session_auth_hash(request, update_account_form.user)

        teacher.title = data['title']
        teacher.new_user.first_name = data['first_name']
        teacher.new_user.last_name = data['last_name']
        new_email = data['email']
        if new_email != '' and new_email != teacher.new_user.email:
            # new email to set and verify
            changing_email = True
            send_verification_email(request, teacher.new_user, new_email)

        teacher.save()
        teacher.new_user.save()

        messages.success(
            request, 'Your account details have been successfully changed.')

    return changing_email, new_email
Esempio n. 3
0
def process_signup_form(request, data):
    teacher = Teacher.objects.factory(title=data['teacher_title'],
                                      first_name=data['teacher_first_name'],
                                      last_name=data['teacher_last_name'],
                                      email=data['teacher_email'],
                                      password=data['teacher_password'])

    send_verification_email(request, teacher.user.user)

    return render(request, 'redesign/email_verification_needed_new.html',
                  {'user': teacher.user.user})
Esempio n. 4
0
def process_student_signup_form(request, 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, 'redesign/email_verification_needed_new.html',
                      {'user': student.new_user})

    return render(request, 'portal/play/student_details.html')
Esempio n. 5
0
def process_indep_student_login_form(request, independent_student_login_form):
    user = independent_student_login_form.user
    if not is_verified(user):
        send_verification_email(request, user)
        return render(request, 'redesign/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'))