Files
edx-platform/lms/static/js/verify_student/models/verification_model.js
Will Daly 47b81c9274 Allow users to submit initial verification at in-course checkpoints.
* Combine verification and reverification photo submission end-points.
* Combine verification and reverification Backbone models.
* Allow deletion of verification status in Django admin.
* Initial verification from a checkpoint is associated with the checkpoint.
* Fix critical bug in which an invalid link was sent to Software Secure
  for the photo ID image of reverification attempts.
2015-07-27 19:32:18 -07:00

86 lines
3.0 KiB
JavaScript

/**
* In-memory storage of verification photo data.
*
* This can be passed to multiple steps in the workflow
* to persist image data in-memory before it is submitted
* to the server.
*
*/
var edx = edx || {};
(function( $, Backbone ) {
'use strict';
edx.verify_student = edx.verify_student || {};
edx.verify_student.VerificationModel = Backbone.Model.extend({
defaults: {
// If provided, change the user's full name when submitting photos.
fullName: null,
// Image data for the user's face photo.
faceImage: "",
// Image data for the user's ID photo.
// In the case of an in-course reverification, we won't
// need to send this because we'll send the ID photo that
// the user submitted with the initial verification attempt.
identificationImage: null,
// If the verification attempt is associated with a checkpoint
// in a course, we send the the course and checkpoint location.
courseKey: null,
checkpoint: null,
},
sync: function( method, model ) {
var headers = { 'X-CSRFToken': $.cookie( 'csrftoken' ) },
data = {};
data.face_image = model.get("faceImage");
// The ID photo is optional, since in-course reverification
// re-uses the image from the initial verification attempt.
if (model.has("identificationImage")) {
data.photo_id_image = model.get("identificationImage");
}
// Full name is an optional parameter; if not provided,
// it won't be changed.
if (model.has("fullName")) {
data.full_name = model.get("fullName");
// Track the user's decision to change the name on their account
window.analytics.track( 'edx.bi.user.full_name.changed', {
category: 'verification'
});
}
// If the user entered the verification flow from a checkpoint
// in a course, we need to send the course and checkpoint
// location to associate the attempt with the checkpoint.
if (model.has("courseKey") && model.has("checkpoint")) {
data.course_key = model.get("courseKey");
data.checkpoint = model.get("checkpoint");
}
// Submit the request to the server,
// triggering events on success and error.
$.ajax({
url: '/verify_student/submit-photos/',
type: 'POST',
data: data,
headers: headers,
success: function( response ) {
model.trigger( 'sync', response.url );
},
error: function( error ) {
model.trigger( 'error', error );
}
});
}
});
})( jQuery, Backbone );