def post(self, request, course_id): """ submits the reverification to SoftwareSecure """ try: now = datetime.datetime.now(UTC) course_id = CourseKey.from_string(course_id) window = MidcourseReverificationWindow.get_window(course_id, now) if window is None: raise WindowExpiredException attempt = SoftwareSecurePhotoVerification(user=request.user, window=window) b64_face_image = request.POST["face_image"].split(",")[1] attempt.upload_face_image(b64_face_image.decode("base64")) attempt.fetch_photo_id_image() attempt.mark_ready() attempt.save() attempt.submit() course_enrollment = CourseEnrollment.get_or_create_enrollment(request.user, course_id) course_enrollment.update_enrollment(mode="verified") course_enrollment.emit_event(EVENT_NAME_USER_SUBMITTED_MIDCOURSE_REVERIFY) return HttpResponseRedirect(reverse("verify_student_midcourse_reverification_confirmation")) except WindowExpiredException: log.exception( "User {} attempted to re-verify, but the window expired before the attempt".format(request.user.id) ) return HttpResponseRedirect(reverse("verify_student_reverification_window_expired")) except Exception: log.exception("Could not submit verification attempt for user {}".format(request.user.id)) context = {"user_full_name": request.user.profile.name, "error": True} return render_to_response("verify_student/midcourse_photo_reverification.html", context)
def test_fetch_photo_id_image(self): user = UserFactory.create() orig_attempt = SoftwareSecurePhotoVerification(user=user) orig_attempt.save() old_key = orig_attempt.photo_id_key new_attempt = SoftwareSecurePhotoVerification(user=user) new_attempt.save() new_attempt.fetch_photo_id_image() assert_equals(new_attempt.photo_id_key, old_key)
def test_fetch_photo_id_image(self): user = UserFactory.create() orig_attempt = SoftwareSecurePhotoVerification(user=user, window=None) orig_attempt.save() old_key = orig_attempt.photo_id_key window = MidcourseReverificationWindowFactory( course_id=SlashSeparatedCourseKey("pony", "rainbow", "dash"), start_date=datetime.now(pytz.utc) - timedelta(days=5), end_date=datetime.now(pytz.utc) + timedelta(days=5)) new_attempt = SoftwareSecurePhotoVerification(user=user, window=window) new_attempt.save() new_attempt.fetch_photo_id_image() assert_equals(new_attempt.photo_id_key, old_key)
def test_fetch_photo_id_image(self): user = UserFactory.create() orig_attempt = SoftwareSecurePhotoVerification(user=user, window=None) orig_attempt.save() old_key = orig_attempt.photo_id_key window = MidcourseReverificationWindowFactory( course_id=SlashSeparatedCourseKey("pony", "rainbow", "dash"), start_date=datetime.now(pytz.utc) - timedelta(days=5), end_date=datetime.now(pytz.utc) + timedelta(days=5) ) new_attempt = SoftwareSecurePhotoVerification(user=user, window=window) new_attempt.save() new_attempt.fetch_photo_id_image() assert_equals(new_attempt.photo_id_key, old_key)
def post(self, request, course_id): """ submits the reverification to SoftwareSecure """ try: now = datetime.datetime.now(UTC) course_id = SlashSeparatedCourseKey.from_deprecated_string( course_id) window = MidcourseReverificationWindow.get_window(course_id, now) if window is None: raise WindowExpiredException attempt = SoftwareSecurePhotoVerification(user=request.user, window=window) b64_face_image = request.POST['face_image'].split(",")[1] attempt.upload_face_image(b64_face_image.decode('base64')) attempt.fetch_photo_id_image() attempt.mark_ready() attempt.save() attempt.submit() course_enrollment = CourseEnrollment.get_or_create_enrollment( request.user, course_id) course_enrollment.update_enrollment(mode="verified") course_enrollment.emit_event( EVENT_NAME_USER_SUBMITTED_MIDCOURSE_REVERIFY) return HttpResponseRedirect( reverse( 'verify_student_midcourse_reverification_confirmation')) except WindowExpiredException: log.exception( "User {} attempted to re-verify, but the window expired before the attempt" .format(request.user.id)) return HttpResponseRedirect( reverse('verify_student_reverification_window_expired')) except Exception: log.exception( "Could not submit verification attempt for user {}".format( request.user.id)) context = { "user_full_name": request.user.profile.name, "error": True, } return render_to_response( "verify_student/midcourse_photo_reverification.html", context)