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({
username: req.body.username
}, '-salt -password', function(err, user) {
if(err){
return res.status(500).send({
message: err.message
});
}
if (!user) {
return res.status(400).send({
message: 'No account with that username has been found'
@ -102,6 +107,11 @@ exports.validateResetToken = function(req, res) {
$gt: Date.now()
}
}, function(err, user) {
if(err){
return res.status(500).send({
message: err.message
});
}
if (!user) {
return res.redirect('/#!/password/reset/invalid');
}

View File

@ -10,17 +10,17 @@ var mongoose = require('mongoose'),
var FieldOptionSchema = new Schema({
option_id: {
type: Number,
type: Number
},
option_title: {
type: String,
type: String
},
option_value: {
type: String,
trim: true,
},
trim: true
}
});
@ -31,7 +31,7 @@ var FormFieldSchema = new Schema({
title: {
type: String,
trim: true,
required: 'Field Title cannot be blank',
required: 'Field Title cannot be blank'
},
description: {
type: String,

View File

@ -56,7 +56,7 @@ var FormSubmissionSchema = new Schema({
},
form_fields: {
type: [Schema.Types.Mixed],
type: [Schema.Types.Mixed]
},
form: {
@ -66,54 +66,54 @@ var FormSubmissionSchema = new Schema({
},
ipAddr: {
type: String,
type: String
},
geoLocation: {
Country: {
type: String,
type: String
},
Region: {
type: String,
type: String
},
City: {
type: String,
type: String
}
},
device: {
type: {
type: String,
type: String
},
name: {
type: String,
type: String
}
},
pdfFilePath: {
type: Schema.Types.Mixed,
type: Schema.Types.Mixed
},
pdf: {
type: Schema.Types.Mixed,
type: Schema.Types.Mixed
},
fdfData: {
type: Schema.Types.Mixed,
type: Schema.Types.Mixed
},
timeElapsed: {
type: Number,
},
percentageComplete: {
type: Number,
type: Number
},
//TODO: DAVID: Need to not have this hardcoded
oscarDemoNum: {
type: Number,
type: Number
},
hasPlugins: {
oscarhost: {
type: Boolean,
default: false,
default: false
}
}
@ -140,7 +140,7 @@ FormSubmissionSchema.pre('save', function (next) {
// console.log('FormSubmission [form_field ids]\n--------');
// console.log(submission_ids);
if(err) next(err);
if(err) return next(err);
// console.log(_form);
// console.log('should push to api');
// 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
soap.createClient(url_login, options, function(err, client) {
client.login(args_login, function (err, result) {
if(err) callback(err);
if(err) return callback(err);
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
if(_form.plugins.oscarhost.settings.updateType === 'force_add'){
soap.createClient(url_demo, options, function(err, client) {
if(err) return callback(err);
client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) );
client.addDemographic({ arg0: submissionDemographic }, function (err, result) {
console.log('FORCE ADDING DEMOGRAPHIC \n');
// console.log(result.return);
if(err) callback(err);
callback(null, result);
if(err) return callback(err);
return callback(null, result);
});
});
}
},
], function(err, result) {
if(err) next(err);
if(err) return next(err);
self.oscarDemoNum = parseInt(result.return, 10);
console.log('self.oscarDemoNum: '+self.oscarDemoNum);
next();
return next();
});
}else{
next();
return next();
}
});
}else{
next();
return next();
}
});
@ -238,13 +239,13 @@ FormSubmissionSchema.pre('save', function (next){
if(this.ipAddr){
if(this.isModified('ipAddr') || !this.geoLocation){
freegeoip.getLocation(this.ipAddr, function(err, location){
if(err) next(err);
if(err) return next(err);
//self.geoLocation = JSON.parse(location);
next();
return next();
});
}
}
next();
return next();
});
//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){
if(err) {
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);
next();
return next();
});
} else {
next();
return next();
}
});