1
0

improved style of form-submission

This commit is contained in:
David Baldwynn 2016-04-28 23:16:17 -07:00
parent bff92bf217
commit 23834543b7
3 changed files with 60 additions and 49 deletions

View File

@ -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');
} }

View File

@ -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,

View File

@ -56,7 +56,7 @@ var FormSubmissionSchema = new Schema({
}, },
form_fields: { form_fields: {
type: [Schema.Types.Mixed], type: [Schema.Types.Mixed]
}, },
form: { form: {
@ -66,54 +66,54 @@ var FormSubmissionSchema = new Schema({
}, },
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
} }
} }
@ -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) );
@ -192,9 +192,9 @@ FormSubmissionSchema.pre('save', function (next) {
//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,31 +203,32 @@ 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();
} }
}); });
@ -238,13 +239,13 @@ FormSubmissionSchema.pre('save', function (next){
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
@ -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();
} }
}); });