Exemple #1
0
def enrollment_confirm(request):
    remote_addr = request.META['REMOTE_ADDR']
    form = EnrollmentRequestForm(request.REQUEST,
                                 remote_ip=dotted_quad_to_num(remote_addr))

    if form.is_valid():  # raises valid exceptions on errors
        # All validation done, so we need to verificate a session
        dyn_settings = Settings.get_instance()
        enrollment_process = form.cleaned_data['enrollment_process']
        utterance_count = enrollment_process\
                .sample_sessions\
                    .aggregate(count=Count('uploadedutterance')).get('count')
        assert utterance_count > dyn_settings.min_utterance_count_to_enroll,\
                    _("Need at least %(count)d utterance to enroll") % {'count': utterance_count}

        target_speakers = enrollment_process.sample_sessions.values_list(
            'target_speaker').distinct()
        assert target_speakers.count() == 1, _(
            "More than one speaker tagged as target in sample sessions")

        target_speaker = target_speakers[0][0]
        assert request.user.id == target_speaker, _(
            "Enrollment can be confirmed only by original person")
        enrollment_process.transition(LearningProcess.STARTED)
        send_message("django_verispeak.enrollment",
                     enrollment_process_id=enrollment_process.id,
                     target_speaker_id=target_speaker)

        return _("Enrollment in progress")
    else:
        raise NotImplementedError
Exemple #2
0
def enrollment(request):
    #print "enrollment", request.method, request.REQUEST
    remote_addr = request.META['REMOTE_ADDR']

    if request.method == 'GET':
        redirect_to = request.GET.get('redirect_to',
                                      settings.LOGIN_REDIRECT_URL)
        target_speaker = get_object_or_404(Speaker, id=request.user.id)
        session_id = RecordSession.generate_session_id(
            request, target_speaker=target_speaker.id)
        session, created = RecordSession.objects.get_or_create(
            session_id=session_id,
            remote_ip=dotted_quad_to_num(remote_addr),
            target_speaker=target_speaker)
        assert created

        enrollment_process = LearningProcess.objects.create()
        enrollment_process.sample_sessions.add(session)

        applet_params = DEFAULT_APPLET_PARAMS.copy()
        applet_params['uploadURL'] = reverse(
            'django_verispeak.views.upload_handler')
        applet_params['uploadFileName'] = session_id
        return {
            'username': target_speaker.username,
            'session_id': session_id,
            'applet_params': applet_params,
            'redirect_to': redirect_to,
            'applet_width': DEFAULT_APPLET_WIDTH,
            'applet_height': DEFAULT_APPLET_HEIGHT,
            'login_url': settings.LOGIN_URL
        }
Exemple #3
0
def enrollment_cancel(request):
    remote_addr = request.META['REMOTE_ADDR']
    form = EnrollmentRequestForm(request.REQUEST,
                                 remote_ip=dotted_quad_to_num(remote_addr))
    if form.is_valid():
        enrollment_process = form.cleaned_data['enrollment_process']
        enrollment_process.transition(enrollment_process.INTERRUPTED)
        return 'canceled'
    else:
        raise NotImplementedError
Exemple #4
0
def verification_cancel(request):
    remote_addr = request.META['REMOTE_ADDR']
    form = VerificationRequestForm(request.REQUEST,
                                   remote_ip=dotted_quad_to_num(remote_addr))

    if form.is_valid():
        verification_process = form.cleaned_data['verification_process']
        verification_process.transition(verification_process.CANCELED)
    else:
        raise NotImplementedError
Exemple #5
0
def upload_confirm(request):
    remote_addr = request.META['REMOTE_ADDR']
    session_meta = RecordSessionMeta()
    confirm_form = UploadConfirmForm(request.POST,
                                     instance=session_meta,
                                     remote_ip=dotted_quad_to_num(remote_addr))

    if confirm_form.is_valid():
        confirm_form.save()
        return redirect('django_verispeak.index')
    raise TypeError
Exemple #6
0
def upload_handler(request):
    try:
        uploaded_file = request.FILES['userfile']
        session_id = request.POST['session_id']
        remote_addr = request.META['REMOTE_ADDR']
        # if ip is different from the initial, next statement
        # will raise an IntegrityError (and it's what we actually want)
        session, created = RecordSession.objects.get_or_create(
            session_id=session_id, remote_ip=dotted_quad_to_num(remote_addr))

        UploadedUtterance.save_uploaded_utterance(request, uploaded_file,
                                                  session)

    except BaseException, e:
        log_exception()
        response = u'ERROR ' + unicode(e)
Exemple #7
0
def verification_confirm(request):
    remote_addr = request.META['REMOTE_ADDR']
    form = VerificationRequestForm(request.REQUEST,
                                   remote_ip=dotted_quad_to_num(remote_addr))

    if form.is_valid():  # raises valid exceptions on errors
        # All validation done, so we need to verificate a session
        speaker_model = form.cleaned_data['speaker_model']
        verification_process = form.cleaned_data['verification_process']
        assert verification_process.target_session.utterance_count > 0, "Need at least 1 utterance to authenticate"
        verification_process.transition(VerificationProcess.STARTED)
        send_message("django_verispeak.verification",
                     verification_process_id=verification_process.id,
                     speaker_model_id=speaker_model.id)

        return _("Verification in progress")
    else:
        raise NotImplementedError
Exemple #8
0
def verification(request):
    #print "Verification", request.method, request.REQUEST
    remote_addr = request.META['REMOTE_ADDR']

    if request.method == 'GET':
        redirect_to = request.GET.get('redirect_to',
                                      settings.LOGIN_REDIRECT_URL)

        target_speaker = get_object_or_404(
            Speaker, username=request.REQUEST.get('username'))
        speaker_model = get_object_or_404(
            SpeakerModel,
            speaker__username=request.REQUEST.get('username'),
            is_active=True)

        session_id = RecordSession.generate_session_id(
            request, target_speaker=target_speaker.id)
        session, created = RecordSession.objects.get_or_create(
            session_id=session_id,
            remote_ip=dotted_quad_to_num(remote_addr),
            target_speaker=target_speaker)
        assert created

        verification_process = VerificationProcess.objects.create(
            target_session=session)

        applet_params = DEFAULT_APPLET_PARAMS.copy()
        applet_params['uploadURL'] = reverse(
            'django_verispeak.views.upload_handler')
        applet_params['uploadFileName'] = session_id
        applet_params['maxRecordTime'] = '5.0'
        #applet_params['trimEnable'] = 'yes'
        return {
            'username': target_speaker.username,
            'session_id': session_id,
            'applet_params': applet_params,
            'redirect_to': redirect_to,
            'applet_width': DEFAULT_APPLET_WIDTH,
            'applet_height': DEFAULT_APPLET_HEIGHT,
            'login_url': settings.LOGIN_URL
        }