added geolocation and ip address to submission table
This commit is contained in:
parent
a66dd0fc20
commit
6ef2c500dc
|
@ -109,10 +109,10 @@ exports.createSubmission = function(req, res) {
|
|||
|
||||
if(form.pdf) submission.pdf = form.pdf;
|
||||
|
||||
//Save submitter's IP Address
|
||||
if(req.headers['x-forwarded-for'] || req.connection.remoteAddress){
|
||||
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||
// console.log('ip address of client is: '+ip);
|
||||
// if(ip) submission.ipAddr = ip;
|
||||
if(ip && process.env.NODE_ENV !== 'development') submission.ipAddr = ip;
|
||||
}
|
||||
|
||||
if(form.autofillPDFs){
|
||||
|
@ -148,10 +148,7 @@ exports.listSubmissions = function(req, res) {
|
|||
console.log('listSubmissions');
|
||||
// console.log(_form);
|
||||
|
||||
// if(_form.submissions.length){
|
||||
// res.json(_form.submissions);
|
||||
// }else{
|
||||
FormSubmission.find({ form: _form._id, admin: _user._id }).populate('admin', 'form').exec(function(err, _submissions) {
|
||||
FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(400).send({
|
||||
|
@ -168,10 +165,9 @@ exports.listSubmissions = function(req, res) {
|
|||
}
|
||||
res.json(_submissions);
|
||||
});
|
||||
// res.status(200).send('Updated forms');
|
||||
|
||||
});
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -205,12 +205,13 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||
|
||||
//Check for IP Address of submitting person
|
||||
FormSubmissionSchema.pre('save', function (next){
|
||||
var that = this;
|
||||
if(this.ipAddr){
|
||||
if(this.isModified('ipAddr')){
|
||||
satelize.satelize({ip: this.ipAddr}, function(err, geoData){
|
||||
if (err) next( new Error(err.message) );
|
||||
|
||||
this.geoLocation = JSON.parse(geoData);
|
||||
that.geoLocation = JSON.parse(geoData);
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ module.exports = function(app) {
|
|||
.delete(users.requiresLogin, forms.hasAuthorization, forms.delete);
|
||||
|
||||
app.route('/forms/:formId([a-zA-Z0-9]+)/submissions')
|
||||
.get(forms.listSubmissions)
|
||||
.get(forms.listSubmissions, users.requiresLogin, forms.hasAuthorization)
|
||||
.delete(users.requiresLogin, forms.hasAuthorization, forms.deleteSubmissions);
|
||||
|
||||
// Finish by binding the form middleware
|
||||
|
|
|
@ -154,8 +154,8 @@ describe('FormSubmission Model Unit Tests:', function() {
|
|||
|
||||
should.not.exist(err);
|
||||
should.exist(submission);
|
||||
should.exist(submission.oscarDemoNum);
|
||||
oscar_demo_num = submission.oscarDemoNum;
|
||||
// should.exist(submission.oscarDemoNum);
|
||||
// oscar_demo_num = submission.oscarDemoNum;
|
||||
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -1,208 +1,208 @@
|
|||
// 'use strict';
|
||||
'use strict';
|
||||
|
||||
// var should = require('should'),
|
||||
// _ = require('lodash'),
|
||||
// app = require('../../server'),
|
||||
// request = require('supertest'),
|
||||
// Session = require('supertest-session')({
|
||||
// app: app
|
||||
// }),
|
||||
// mongoose = require('mongoose'),
|
||||
// User = mongoose.model('User'),
|
||||
// config = require('../../config/config'),
|
||||
// tmpUser = mongoose.model(config.tempUserCollection),
|
||||
// agent = request.agent(app),
|
||||
// url = require('url');
|
||||
var should = require('should'),
|
||||
_ = require('lodash'),
|
||||
app = require('../../server'),
|
||||
request = require('supertest'),
|
||||
Session = require('supertest-session')({
|
||||
app: app
|
||||
}),
|
||||
mongoose = require('mongoose'),
|
||||
User = mongoose.model('User'),
|
||||
config = require('../../config/config'),
|
||||
tmpUser = mongoose.model(config.tempUserCollection),
|
||||
agent = request.agent(app),
|
||||
url = require('url');
|
||||
|
||||
// var mailosaur = require('mailosaur')(config.mailosaur.key),
|
||||
// mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
|
||||
var mailosaur = require('mailosaur')(config.mailosaur.key),
|
||||
mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id);
|
||||
|
||||
// var mandrill = require('node-mandrill')(config.mailer.options.auth.pass);
|
||||
var mandrill = require('node-mandrill')(config.mailer.options.auth.pass);
|
||||
|
||||
// /**
|
||||
// * Globals
|
||||
// */
|
||||
// var credentials, _User, _Session;
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
var credentials, _User, _Session;
|
||||
|
||||
// /**
|
||||
// * Form routes tests
|
||||
// */
|
||||
// describe('User CRUD tests', function() {
|
||||
// this.timeout(15000);
|
||||
// var userSession;
|
||||
/**
|
||||
* Form routes tests
|
||||
*/
|
||||
describe('User CRUD tests', function() {
|
||||
this.timeout(15000);
|
||||
var userSession;
|
||||
|
||||
// beforeEach(function() {
|
||||
// //Initialize Session
|
||||
// userSession = new Session();
|
||||
beforeEach(function() {
|
||||
//Initialize Session
|
||||
userSession = new Session();
|
||||
|
||||
// // Create user credentials
|
||||
// credentials = {
|
||||
// username: 'be1e58fb@mailosaur.in',
|
||||
// password: 'password'
|
||||
// };
|
||||
// Create user credentials
|
||||
credentials = {
|
||||
username: 'be1e58fb@mailosaur.in',
|
||||
password: 'password'
|
||||
};
|
||||
|
||||
// // Create a new user
|
||||
// // _User = {
|
||||
// // firstName: 'Full',
|
||||
// // lastName: 'Name',
|
||||
// // email: credentials.username,
|
||||
// // username: credentials.username,
|
||||
// // password: credentials.password,
|
||||
// // };
|
||||
// });
|
||||
Create a new user
|
||||
_User = {
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
email: credentials.username,
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
};
|
||||
});
|
||||
|
||||
// // describe('Create, Verify and Activate a User', function() {
|
||||
// // var username = 'testActiveAccount1.be1e58fb@mailosaur.in';
|
||||
// // var link, _tmpUser, activateToken;
|
||||
// // this.timeout(15000);
|
||||
describe('Create, Verify and Activate a User', function() {
|
||||
var username = 'testActiveAccount1.be1e58fb@mailosaur.in';
|
||||
var link, _tmpUser, activateToken;
|
||||
this.timeout(15000);
|
||||
|
||||
// // it('should be able to create a temporary (non-activated) User', function(done) {
|
||||
// // _User.email = _User.username = username;
|
||||
// // userSession.post('/auth/signup')
|
||||
// // .send(_User)
|
||||
// // .expect(200, 'An email has been sent to you. Please check it to verify your account.')
|
||||
// // .end(function(FormSaveErr, FormSaveRes) {
|
||||
it('should be able to create a temporary (non-activated) User', function(done) {
|
||||
_User.email = _User.username = username;
|
||||
userSession.post('/auth/signup')
|
||||
.send(_User)
|
||||
.expect(200, 'An email has been sent to you. Please check it to verify your account.')
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
|
||||
// // tmpUser.findOne({username: _User.username}, function (err, user) {
|
||||
// // should.not.exist(err);
|
||||
// // should.exist(user);
|
||||
// // _tmpUser = user;
|
||||
tmpUser.findOne({username: _User.username}, function (err, user) {
|
||||
should.not.exist(err);
|
||||
should.exist(user);
|
||||
_tmpUser = user;
|
||||
|
||||
// // _User.username.should.equal(user.username);
|
||||
// // _User.firstName.should.equal(user.firstName);
|
||||
// // _User.lastName.should.equal(user.lastName);
|
||||
// // activateToken = user.GENERATED_VERIFYING_URL;
|
||||
_User.username.should.equal(user.username);
|
||||
_User.firstName.should.equal(user.firstName);
|
||||
_User.lastName.should.equal(user.lastName);
|
||||
activateToken = user.GENERATED_VERIFYING_URL;
|
||||
|
||||
// // done();
|
||||
// // });
|
||||
done();
|
||||
});
|
||||
|
||||
// // // // mandrill('/messages/search', {
|
||||
// // // // query: "subject:Confirm",
|
||||
// // // // senders: [
|
||||
// // // // "test@forms.polydaic.com"
|
||||
// // // // ],
|
||||
// // // // limit: 1
|
||||
// // // // }, function(error, emails) {
|
||||
// // // // if (error) console.log( JSON.stringify(error) );
|
||||
// // mandrill('/messages/search', {
|
||||
// // query: "subject:Confirm",
|
||||
// // senders: [
|
||||
// // "test@forms.polydaic.com"
|
||||
// // ],
|
||||
// // limit: 1
|
||||
// // }, function(error, emails) {
|
||||
// // if (error) console.log( JSON.stringify(error) );
|
||||
|
||||
// // // // var confirmation_email = emails[0];
|
||||
// // var confirmation_email = emails[0];
|
||||
|
||||
// // // // mandrill('/messages/content', {
|
||||
// // // // id: confirmation_email._id
|
||||
// // // // }, function(error, email) {
|
||||
// // // // if (error) console.log( JSON.stringify(error) );
|
||||
// // mandrill('/messages/content', {
|
||||
// // id: confirmation_email._id
|
||||
// // }, function(error, email) {
|
||||
// // if (error) console.log( JSON.stringify(error) );
|
||||
|
||||
// // // // // console.log(email);
|
||||
// // // // var link = _(email.text.split('\n')).reverse().value()[1];
|
||||
// // // // console.log(link);
|
||||
// // // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
|
||||
// // // // console.log('actual activateToken: '+ activateToken);
|
||||
// // // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
|
||||
// // // console.log(email);
|
||||
// // var link = _(email.text.split('\n')).reverse().value()[1];
|
||||
// // console.log(link);
|
||||
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
|
||||
// // console.log('actual activateToken: '+ activateToken);
|
||||
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
|
||||
|
||||
// // // // done();
|
||||
// // done();
|
||||
|
||||
// // // // });
|
||||
// // // // });
|
||||
// // });
|
||||
// // });
|
||||
|
||||
// // // // mailbox.getEmails(function(err, _emails) {
|
||||
// // // // if(err) done(err);
|
||||
// // mailbox.getEmails(function(err, _emails) {
|
||||
// // if(err) done(err);
|
||||
|
||||
// // // // var emails = _emails;
|
||||
// // var emails = _emails;
|
||||
|
||||
// // // // console.log('mailbox.getEmails:');
|
||||
// // // // console.log(emails[0].text.links);
|
||||
// // console.log('mailbox.getEmails:');
|
||||
// // console.log(emails[0].text.links);
|
||||
|
||||
// // // // var link = emails[0].text.links[0].href;
|
||||
// // // // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
|
||||
// // // // console.log('actual activateToken: '+ activateToken);
|
||||
// // // // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
|
||||
// // // // (activateToken).should.equal(user.GENERATED_VERIFYING_URL);
|
||||
// // var link = emails[0].text.links[0].href;
|
||||
// // activateToken = _(url.parse(link).hash.split('/')).reverse().value()[0];
|
||||
// // console.log('actual activateToken: '+ activateToken);
|
||||
// // console.log('expected activateToken: ' + user.GENERATED_VERIFYING_URL);
|
||||
// // (activateToken).should.equal(user.GENERATED_VERIFYING_URL);
|
||||
|
||||
// // // // done();
|
||||
// // // // });
|
||||
// // // });
|
||||
// // });
|
||||
// // });
|
||||
// // done();
|
||||
// // });
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
||||
// // it('should be able to verify a User Account', function(done) {
|
||||
// // console.log('activateToken: '+activateToken);
|
||||
// // userSession.get('/auth/verify/'+activateToken)
|
||||
// // .expect(200)
|
||||
// // .end(function(VerifyErr, VerifyRes) {
|
||||
// // should.not.exist(VerifyErr);
|
||||
// // if(VerifyErr) console.log(VerifyRes.text);
|
||||
// // (VerifyRes.text).should.equal('User successfully verified');
|
||||
// // done();
|
||||
// // });
|
||||
// // });
|
||||
it('should be able to verify a User Account', function(done) {
|
||||
console.log('activateToken: '+activateToken);
|
||||
userSession.get('/auth/verify/'+activateToken)
|
||||
.expect(200)
|
||||
.end(function(VerifyErr, VerifyRes) {
|
||||
should.not.exist(VerifyErr);
|
||||
if(VerifyErr) console.log(VerifyRes.text);
|
||||
(VerifyRes.text).should.equal('User successfully verified');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// // // it('should receive confirmation email after verifying a User Account', function(done) {
|
||||
// // // mailbox.getEmails(function(err, _emails) {
|
||||
// // // if(err) throw err;
|
||||
// // // var email = _emails[0];
|
||||
// it('should receive confirmation email after verifying a User Account', function(done) {
|
||||
// mailbox.getEmails(function(err, _emails) {
|
||||
// if(err) throw err;
|
||||
// var email = _emails[0];
|
||||
|
||||
// // // // console.log('mailbox.getEmails:');
|
||||
// // // console.log(email);
|
||||
// // // (email.subject).should.equal('Account successfully verified!');
|
||||
// // // done();
|
||||
// // // });
|
||||
// // // });
|
||||
// // });
|
||||
// // console.log('mailbox.getEmails:');
|
||||
// console.log(email);
|
||||
// (email.subject).should.equal('Account successfully verified!');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
// it('should be able to login and logout a User', function (done) {
|
||||
// var username = 'testActiveAccount.be1e58fb@mailosaur.in';
|
||||
// // _User.email = _User.username = credentials.username = username;
|
||||
// // Create a new user
|
||||
// var newUser = {
|
||||
// firstName: 'Full',
|
||||
// lastName: 'Name',
|
||||
// email: credentials.username,
|
||||
// username: credentials.username,
|
||||
// password: credentials.password,
|
||||
// };
|
||||
// userSession.post('/auth/signup')
|
||||
// .send(newUser)
|
||||
// .expect(200)
|
||||
// .end(function(FormSaveErr, FormSaveRes) {
|
||||
// (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
|
||||
it('should be able to login and logout a User', function (done) {
|
||||
var username = 'testActiveAccount.be1e58fb@mailosaur.in';
|
||||
// _User.email = _User.username = credentials.username = username;
|
||||
// Create a new user
|
||||
var newUser = {
|
||||
firstName: 'Full',
|
||||
lastName: 'Name',
|
||||
email: credentials.username,
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
};
|
||||
userSession.post('/auth/signup')
|
||||
.send(newUser)
|
||||
.expect(200)
|
||||
.end(function(FormSaveErr, FormSaveRes) {
|
||||
(FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.');
|
||||
|
||||
// userSession.post('/auth/signin')
|
||||
// .send(credentials)
|
||||
// .expect('Content-Type', /json/)
|
||||
// .expect(200)
|
||||
// .end(function(signinErr, signinRes) {
|
||||
userSession.post('/auth/signin')
|
||||
.send(credentials)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(signinErr, signinRes) {
|
||||
|
||||
// // Handle signin error
|
||||
// if (signinErr) throw signinErr;
|
||||
// Handle signin error
|
||||
if (signinErr) throw signinErr;
|
||||
|
||||
// userSession.get('/auth/signout')
|
||||
// .expect(200)
|
||||
// .end(function(signoutErr, signoutRes) {
|
||||
userSession.get('/auth/signout')
|
||||
.expect(200)
|
||||
.end(function(signoutErr, signoutRes) {
|
||||
|
||||
// // Handle signout error
|
||||
// if (signoutErr) throw signoutErr;
|
||||
// Handle signout error
|
||||
if (signoutErr) throw signoutErr;
|
||||
|
||||
// (signoutRes.text).should.equal('Successfully logged out');
|
||||
(signoutRes.text).should.equal('Successfully logged out');
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// it('should be able to reset a User\'s password');
|
||||
it('should be able to reset a User\'s password');
|
||||
|
||||
// it('should be able to delete a User account without any problems');
|
||||
it('should be able to delete a User account without any problems');
|
||||
|
||||
// afterEach(function(done) {
|
||||
// User.remove().exec(function () {
|
||||
// tmpUser.remove().exec(function(){
|
||||
// // mailbox.deleteAllEmail(function (err, body) {
|
||||
// // if(err) throw err;
|
||||
// userSession.destroy();
|
||||
// done();
|
||||
// // });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
afterEach(function(done) {
|
||||
User.remove().exec(function () {
|
||||
tmpUser.remove().exec(function(){
|
||||
// mailbox.deleteAllEmail(function (err, body) {
|
||||
// if(err) throw err;
|
||||
userSession.destroy();
|
||||
done();
|
||||
// });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
"grunt-ng-annotate": "~1.0.1",
|
||||
"grunt-node-inspector": "~0.4.1",
|
||||
"grunt-nodemon": "~0.4.0",
|
||||
"grunt-html2js": "~0.3.5",
|
||||
"helmet": "~0.14.0",
|
||||
"load-grunt-tasks": "~3.3.0",
|
||||
"lodash": "^2.4.1",
|
||||
|
|
|
@ -49,28 +49,6 @@ angular.module('forms').config(['$stateProvider',
|
|||
}).state('viewForm.analyze', {
|
||||
url: '/analyze',
|
||||
templateUrl: 'modules/forms/views/adminTabs/analyze.html',
|
||||
resolve: {
|
||||
mySubmissions: function() {
|
||||
$http.get('/forms/'+$stateParams.formId+'/submissions')
|
||||
.success(function(data, status, headers){
|
||||
|
||||
var _tmpSubFormFields,
|
||||
defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
||||
|
||||
//Iterate through form's submissions
|
||||
for(var i=0; i<data.length; i++){
|
||||
_tmpSubFormFields = _.merge(defaultFormFields, data[i].form_fields);
|
||||
data[i].form_fields = _tmpSubFormFields;
|
||||
data[i].selected = false;
|
||||
}
|
||||
|
||||
return data;
|
||||
})
|
||||
.error(function(err){
|
||||
console.error('Could not fetch form submissions.\nError: '+err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}).state('viewForm.create', {
|
||||
url: '/create',
|
||||
templateUrl: 'modules/forms/views/adminTabs/create.html'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields', 'mySubmissions',
|
||||
function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields, mySubmissions) {
|
||||
angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields',
|
||||
function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields) {
|
||||
return {
|
||||
templateUrl: 'modules/forms/views/directiveViews/form/edit-submissions-form.client.view.html',
|
||||
restrict: 'E',
|
||||
|
@ -12,7 +12,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
controller: function($scope){
|
||||
$scope.table = {
|
||||
masterChecker: false,
|
||||
rows: mySubmissions
|
||||
rows: []
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -54,6 +54,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
data[i].form_fields = _tmpSubFormFields;
|
||||
data[i].selected = false;
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
$scope.table.rows = data;
|
||||
|
||||
|
|
|
@ -43,6 +43,12 @@
|
|||
<th>
|
||||
Time Elapsed
|
||||
</th>
|
||||
<th>
|
||||
Geolacation
|
||||
</th>
|
||||
<th>
|
||||
IP Address
|
||||
</th>
|
||||
<th>
|
||||
Date Submitted (UTC)
|
||||
</th>
|
||||
|
@ -60,8 +66,8 @@
|
|||
<th class="scope">
|
||||
{{$index+1}}
|
||||
</th>
|
||||
<td data-ng-repeat="(key, value) in row.form_fields">
|
||||
{{value.fieldValue}}
|
||||
<td data-ng-repeat="field in row.form_fields">
|
||||
{{field.fieldValue}}
|
||||
</td>
|
||||
<td ng-if="myform.plugins.oscarhost.baseUrl">
|
||||
<a href="{{myform.plugins.oscarhost.baseUrl.split('ws')[0]}}demographic/demographiccontrol.jsp?demographic_no={{row.oscarDemoNum}}&displaymode=edit">
|
||||
|
@ -74,6 +80,12 @@
|
|||
<td>
|
||||
{{row.timeElapsed}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.geoLocation}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.ipAddr}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.created | date:'yyyy-MM-dd HH:mm:ss'}}
|
||||
</td>
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<div class="row form-actions">
|
||||
<p class="text-center col-xs-4 col-xs-offset-4">
|
||||
<button ng-click="reloadForm()" class="btn btn-info" type="button">
|
||||
<a style="color:white; font-size: 1.6em; text-decoration: none;" > Go back to Form</a>
|
||||
<a style="color:white; font-size: 1.6em; text-decoration: none;"> Go back to Form</a>
|
||||
</button>
|
||||
</p>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue