improved style of form-submission
This commit is contained in:
parent
bff92bf217
commit
23834543b7
@ -33,6 +33,11 @@ exports.forgot = function(req, res, next) {
|
|||||||
User.findOne({
|
User.findOne({
|
||||||
username: req.body.username
|
username: req.body.username
|
||||||
}, '-salt -password', function(err, user) {
|
}, '-salt -password', function(err, user) {
|
||||||
|
if(err){
|
||||||
|
return res.status(500).send({
|
||||||
|
message: err.message
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
message: 'No account with that username has been found'
|
message: 'No account with that username has been found'
|
||||||
@ -102,6 +107,11 @@ exports.validateResetToken = function(req, res) {
|
|||||||
$gt: Date.now()
|
$gt: Date.now()
|
||||||
}
|
}
|
||||||
}, function(err, user) {
|
}, function(err, user) {
|
||||||
|
if(err){
|
||||||
|
return res.status(500).send({
|
||||||
|
message: err.message
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.redirect('/#!/password/reset/invalid');
|
return res.redirect('/#!/password/reset/invalid');
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@ var mongoose = require('mongoose'),
|
|||||||
|
|
||||||
var FieldOptionSchema = new Schema({
|
var FieldOptionSchema = new Schema({
|
||||||
option_id: {
|
option_id: {
|
||||||
type: Number,
|
type: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
option_title: {
|
option_title: {
|
||||||
type: String,
|
type: String
|
||||||
},
|
},
|
||||||
|
|
||||||
option_value: {
|
option_value: {
|
||||||
type: String,
|
type: String,
|
||||||
trim: true,
|
trim: true
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ var FormFieldSchema = new Schema({
|
|||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
trim: true,
|
trim: true,
|
||||||
required: 'Field Title cannot be blank',
|
required: 'Field Title cannot be blank'
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -17,7 +17,7 @@ var mongoose = require('mongoose'),
|
|||||||
FieldSchema = require('./form_field.server.model.js'),
|
FieldSchema = require('./form_field.server.model.js'),
|
||||||
OscarSecurity = require('../../scripts/oscarhost/OscarSecurity');
|
OscarSecurity = require('../../scripts/oscarhost/OscarSecurity');
|
||||||
|
|
||||||
var newDemoTemplate = {
|
var newDemoTemplate = {
|
||||||
address: '880-9650 Velit. St.',
|
address: '880-9650 Velit. St.',
|
||||||
city: '',
|
city: '',
|
||||||
dateOfBirth: '10',
|
dateOfBirth: '10',
|
||||||
@ -38,10 +38,10 @@ var newDemoTemplate = {
|
|||||||
sin: '',
|
sin: '',
|
||||||
spokenLanguage: 'English',
|
spokenLanguage: 'English',
|
||||||
title: 'MS.',
|
title: 'MS.',
|
||||||
yearOfBirth: '2015'
|
yearOfBirth: '2015'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form Submission Schema
|
* Form Submission Schema
|
||||||
*/
|
*/
|
||||||
var FormSubmissionSchema = new Schema({
|
var FormSubmissionSchema = new Schema({
|
||||||
@ -56,64 +56,64 @@ var FormSubmissionSchema = new Schema({
|
|||||||
},
|
},
|
||||||
|
|
||||||
form_fields: {
|
form_fields: {
|
||||||
type: [Schema.Types.Mixed],
|
type: [Schema.Types.Mixed]
|
||||||
},
|
},
|
||||||
|
|
||||||
form: {
|
form: {
|
||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: 'Form',
|
ref: 'Form',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
||||||
ipAddr: {
|
ipAddr: {
|
||||||
type: String,
|
type: String
|
||||||
},
|
},
|
||||||
geoLocation: {
|
geoLocation: {
|
||||||
Country: {
|
Country: {
|
||||||
type: String,
|
type: String
|
||||||
},
|
},
|
||||||
Region: {
|
Region: {
|
||||||
type: String,
|
type: String
|
||||||
},
|
},
|
||||||
City: {
|
City: {
|
||||||
type: String,
|
type: String
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
pdfFilePath: {
|
pdfFilePath: {
|
||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed
|
||||||
},
|
},
|
||||||
pdf: {
|
pdf: {
|
||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed
|
||||||
},
|
},
|
||||||
fdfData: {
|
fdfData: {
|
||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed
|
||||||
},
|
},
|
||||||
|
|
||||||
timeElapsed: {
|
timeElapsed: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
percentageComplete: {
|
percentageComplete: {
|
||||||
type: Number,
|
type: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
//TODO: DAVID: Need to not have this hardcoded
|
//TODO: DAVID: Need to not have this hardcoded
|
||||||
oscarDemoNum: {
|
oscarDemoNum: {
|
||||||
type: Number,
|
type: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPlugins: {
|
hasPlugins: {
|
||||||
oscarhost: {
|
oscarhost: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
|||||||
|
|
||||||
//Oscarhost API hook
|
//Oscarhost API hook
|
||||||
FormSubmissionSchema.pre('save', function (next) {
|
FormSubmissionSchema.pre('save', function (next) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if(this.hasPlugins.oscarhost){
|
if(this.hasPlugins.oscarhost){
|
||||||
@ -140,7 +140,7 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||||||
// console.log('FormSubmission [form_field ids]\n--------');
|
// console.log('FormSubmission [form_field ids]\n--------');
|
||||||
// console.log(submission_ids);
|
// console.log(submission_ids);
|
||||||
|
|
||||||
if(err) next(err);
|
if(err) return next(err);
|
||||||
// console.log(_form);
|
// console.log(_form);
|
||||||
// console.log('should push to api');
|
// console.log('should push to api');
|
||||||
// console.log( (!this.oscarDemoNum && !!_form.plugins.oscarhost.baseUrl && !!_form.plugins.oscarhost.settings.fieldMap) );
|
// console.log( (!this.oscarDemoNum && !!_form.plugins.oscarhost.baseUrl && !!_form.plugins.oscarhost.settings.fieldMap) );
|
||||||
@ -175,7 +175,7 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||||||
var date = new Date(currField.fieldValue);
|
var date = new Date(currField.fieldValue);
|
||||||
_generatedDemo.dateOfBirth = date.getDate()+'';
|
_generatedDemo.dateOfBirth = date.getDate()+'';
|
||||||
_generatedDemo.yearOfBirth = date.getFullYear()+'';
|
_generatedDemo.yearOfBirth = date.getFullYear()+'';
|
||||||
_generatedDemo.monthOfBirth = date.getMonth()+'';
|
_generatedDemo.monthOfBirth = date.getMonth()+'';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var currDate = new Date();
|
var currDate = new Date();
|
||||||
@ -183,18 +183,18 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||||||
_generatedDemo.lastUpdateDate = currDate.toISOString();
|
_generatedDemo.lastUpdateDate = currDate.toISOString();
|
||||||
return _generatedDemo;
|
return _generatedDemo;
|
||||||
};
|
};
|
||||||
|
|
||||||
var submissionDemographic = generateDemo(self.form_fields, _form.plugins.oscarhost.settings.fieldMap, newDemoTemplate);
|
var submissionDemographic = generateDemo(self.form_fields, _form.plugins.oscarhost.settings.fieldMap, newDemoTemplate);
|
||||||
|
|
||||||
console.log(submissionDemographic);
|
console.log(submissionDemographic);
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (callback) {
|
function (callback) {
|
||||||
//Authenticate with API
|
//Authenticate with API
|
||||||
soap.createClient(url_login, options, function(err, client) {
|
soap.createClient(url_login, options, function(err, client) {
|
||||||
client.login(args_login, function (err, result) {
|
client.login(args_login, function (err, result) {
|
||||||
if(err) callback(err);
|
if(err) return callback(err);
|
||||||
console.log('SOAP authenticated');
|
console.log('SOAP authenticated');
|
||||||
callback(null, result.return);
|
return callback(null, result.return);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -203,56 +203,57 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||||||
//Force Add Demographic
|
//Force Add Demographic
|
||||||
if(_form.plugins.oscarhost.settings.updateType === 'force_add'){
|
if(_form.plugins.oscarhost.settings.updateType === 'force_add'){
|
||||||
soap.createClient(url_demo, options, function(err, client) {
|
soap.createClient(url_demo, options, function(err, client) {
|
||||||
|
if(err) return callback(err);
|
||||||
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
|
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
|
||||||
|
|
||||||
client.addDemographic({ arg0: submissionDemographic }, function (err, result) {
|
client.addDemographic({ arg0: submissionDemographic }, function (err, result) {
|
||||||
console.log('FORCE ADDING DEMOGRAPHIC \n');
|
console.log('FORCE ADDING DEMOGRAPHIC \n');
|
||||||
// console.log(result.return);
|
// console.log(result.return);
|
||||||
if(err) callback(err);
|
if(err) return callback(err);
|
||||||
callback(null, result);
|
return callback(null, result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if(err) next(err);
|
if(err) return next(err);
|
||||||
|
|
||||||
self.oscarDemoNum = parseInt(result.return, 10);
|
self.oscarDemoNum = parseInt(result.return, 10);
|
||||||
console.log('self.oscarDemoNum: '+self.oscarDemoNum);
|
console.log('self.oscarDemoNum: '+self.oscarDemoNum);
|
||||||
next();
|
return next();
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
next();
|
return next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Check for IP Address of submitting person
|
//Check for IP Address of submitting person
|
||||||
FormSubmissionSchema.pre('save', function (next){
|
FormSubmissionSchema.pre('save', function (next){
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.ipAddr){
|
if(this.ipAddr){
|
||||||
if(this.isModified('ipAddr') || !this.geoLocation){
|
if(this.isModified('ipAddr') || !this.geoLocation){
|
||||||
freegeoip.getLocation(this.ipAddr, function(err, location){
|
freegeoip.getLocation(this.ipAddr, function(err, location){
|
||||||
if(err) next(err);
|
if(err) return next(err);
|
||||||
//self.geoLocation = JSON.parse(location);
|
//self.geoLocation = JSON.parse(location);
|
||||||
next();
|
return next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Generate autofilled PDF if flags are set
|
//Generate autofilled PDF if flags are set
|
||||||
FormSubmissionSchema.pre('save', function (next) {
|
FormSubmissionSchema.pre('save', function (next) {
|
||||||
var fdfData, dest_filename, dest_path,
|
var fdfData, dest_filename, dest_path,
|
||||||
self = this,
|
self = this,
|
||||||
_form = this.form;
|
_form = this.form;
|
||||||
|
|
||||||
|
|
||||||
if(this.pdf && this.pdf.path){
|
if(this.pdf && this.pdf.path){
|
||||||
dest_filename = self.title.replace(/ /g,'')+'_submission_'+Date.now()+'.pdf';
|
dest_filename = self.title.replace(/ /g,'')+'_submission_'+Date.now()+'.pdf';
|
||||||
@ -264,13 +265,13 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||||||
pdfFiller.fillForm(self.pdf.path, dest_path, self.fdfData, function(err){
|
pdfFiller.fillForm(self.pdf.path, dest_path, self.fdfData, function(err){
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log('\n err.message: '+err.message);
|
console.log('\n err.message: '+err.message);
|
||||||
next( new Error(err.message) );
|
return next( new Error(err.message) );
|
||||||
}
|
}
|
||||||
console.log('Field data from Form: '+self.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path);
|
console.log('Field data from Form: '+self.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path);
|
||||||
next();
|
return next();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
next();
|
return next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user