diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index 16cfe929..30293541 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -275,31 +275,32 @@ exports.list = function(req, res) { exports.formByID = function(req, res, next, id) { if (!mongoose.Types.ObjectId.isValid(id)) { - res.status(400).send({ + return res.status(400).send({ message: 'Form is invalid' }); } + else { + Form.findById(id).populate('admin').exec(function(err, form) { + if (err) { + return next(err); + } else if (form === undefined || form === null) { + res.status(400).send({ + message: 'Form not found' + }); + } + else { + // console.log(form.admin); - Form.findById(id).populate('admin').exec(function(err, form) { - if (err) { - return next(err); - } else if (form === undefined || form === null) { - res.status(400).send({ - message: 'Form not found' - }); - } - else { - // console.log(form.admin); + //Remove sensitive information from User object + form.admin.password = undefined; + form.admin.salt = undefined; + form.provider = undefined; - //Remove sensitive information from User object - form.admin.password = undefined; - form.admin.salt = undefined; - form.provider = undefined; - - req.form = form; - next(); - } - }); + req.form = form; + next(); + } + }); + } }; /** diff --git a/app/controllers/users/users.authentication.server.controller.js b/app/controllers/users/users.authentication.server.controller.js index ae16c8cb..45e24676 100755 --- a/app/controllers/users/users.authentication.server.controller.js +++ b/app/controllers/users/users.authentication.server.controller.js @@ -56,20 +56,35 @@ exports.signup = function(req, res) { user.username = user.email; // Then save the temporary user - nev.createTempUser(user, function(newTempUser) { - // new user created - if (newTempUser) { - nev.registerTempUser(newTempUser, function (err) { - if (err) { - return res.status(400).send({ - message: errorHandler.getErrorMessage(err) - }); - } - res.status(200).send('An email has been sent to you. Please check it to verify your account.'); - }); - } else { - return res.status(400).send('Error: Temp user could NOT be created!'); - } + nev.createTempUser(user, function(err, newTempUser) { + + if (err) { + console.log('Error: '); + console.log(err); + res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + }else { + console.log('new tmpuser created'); + // new user created + if (newTempUser) { + nev.registerTempUser(newTempUser, function (err) { + if (err) { + console.log('Error: '); + console.log(err); + res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + }else { + console.log('new tmpuser registered'); + res.status(200).send('An email has been sent to you. Please check it to verify your account.'); + } + }); + } else { + console.log('Error: Temp user already exists!'); + res.status(400).send('Error: Temp user already exists!'); + } + } }); }; @@ -104,8 +119,8 @@ exports.signin = function(req, res, next) { */ exports.signout = function(req, res) { req.logout(); - res.status(200).send('Successfully logged out'); - // res.redirect('/'); + // res.status(200).send('Successfully logged out'); + res.redirect('/'); }; /** diff --git a/app/models/form_submission.server.model.js b/app/models/form_submission.server.model.js index d8f59c64..b9c64862 100644 --- a/app/models/form_submission.server.model.js +++ b/app/models/form_submission.server.model.js @@ -63,10 +63,6 @@ var FormSubmissionSchema = new Schema({ }); -//Mongoose Relationship initialization -// FormSubmissionSchema.plugin(relationship, { relationshipPathName:'form' }); - - //Check for IP Address of submitting person FormSubmissionSchema.pre('save', function (next){ if(this.ipAddr){ diff --git a/app/tests/user.server.routes.test.js b/app/tests/user.server.routes.test.js index 58670f56..6316414c 100644 --- a/app/tests/user.server.routes.test.js +++ b/app/tests/user.server.routes.test.js @@ -8,11 +8,12 @@ var should = require('should'), app: app }), mongoose = require('mongoose'), - User = mongoose.model('User'), + url = require('url'), config = require('../../config/config'), + User = mongoose.model('User'), tmpUser = mongoose.model(config.tempUserCollection), - agent = request.agent(app), - url = require('url'); + agent = request.agent(app); + var mailosaur = require('mailosaur')(config.mailosaur.key), mailbox = new mailosaur.Mailbox(config.mailosaur.mailbox_id); @@ -23,12 +24,26 @@ var mandrill = require('node-mandrill')(config.mailer.options.auth.pass); * Globals */ var credentials, _User, _Session; +// 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, +}; /** * Form routes tests */ describe('User CRUD tests', function() { - this.timeout(15000); + this.timeout(100000); var userSession; beforeEach(function() { @@ -51,98 +66,115 @@ describe('User CRUD tests', function() { }; }); - // describe('Create, Verify and Activate a User', function() { - var username = 'testActiveAccount.be1e58fb@mailosaur.in'; + describe('Create, Verify and Activate a User', function() { + _User.email = _User.username = 'testActiveAccount5.be1e58fb@mailosaur.in'; var link, _tmpUser, activateToken = ''; - it('should be able to create a temporary (non-activated) User', function(done) { - _User.email = _User.username = username; - request(app).post('/auth/signup') + before(function(done){ + tmpUser.findOne({username: _User.username}, function (err, user) { + console.log(user); + if(user){ + tmpUser.remove({username: _User.username}, function(err){ + if(err) done(err) + done(); + }); + }else {done();} + }); + }); + + it('should be able to query /signup', function(done) { + + 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) { - // (FormSaveRes.text).should.equal('An email has been sent to you. Please check it to verify your account.'); + should.not.exist(FormSaveErr); done(); - // 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); - - // // 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]; - - // // 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); - - // // done(); - - // // }); - // // }); - - - // // mailbox.getEmails(function(err, _emails) { - // // if(err) done(err); - - // // var emails = _emails; - - // // 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); - - // // done(); - // // }); - // }); }); }); - // it('should be able to verify a User Account', function(done) { - // userSession.get('/auth/verify/'+activateToken) - // .expect(200) - // .end(function(VerifyErr, VerifyRes) { - // should.not.exist(VerifyErr); - // (VerifyRes.text).should.equal('User successfully verified'); - // done(); - // }); - // }); + it('should have created a temporary user', function(done){ + tmpUser.findOne({username: _User.username}).exec(function (err, user) { + should.not.exist(err); + should.exist(user); + _tmpUser = user; - // 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]; + _User.username.should.equal(user.username); + _User.firstName.should.equal(user.firstName); + _User.lastName.should.equal(user.lastName); + done(); - // // console.log('mailbox.getEmails:'); - // console.log(email); - // (email.subject).should.equal('Account successfully verified!'); - // done(); - // }); - // }); - // }); + // 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]; + + // 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); + + // done(); + + // }); + // }); + }); + }); + + it('should have sent a verification email', function(done){ + + mailbox.getEmails(function(err, _emails) { + if(err) done(err); + + var emails = _emails; + + 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: ' + _tmpUser.GENERATED_VERIFYING_URL); + (activateToken).should.equal(_tmpUser.GENERATED_VERIFYING_URL); + + done(); + }); + }); + + it('should be able to verify a User Account', function(done) { + userSession.get('/auth/verify/'+activateToken) + .expect(200) + .end(function(VerifyErr, VerifyRes) { + should.not.exist(VerifyErr); + (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]; + + 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'; diff --git a/public/modules/forms/config/forms.client.routes.js b/public/modules/forms/config/forms.client.routes.js index 87f062bf..a04f4c41 100644 --- a/public/modules/forms/config/forms.client.routes.js +++ b/public/modules/forms/config/forms.client.routes.js @@ -13,19 +13,20 @@ angular.module('forms').config(['$stateProvider', permissions: [ 'editForm' ] } }). + state('submitForm', { + url: '/forms/:formId', + templateUrl: 'modules/forms/views/submit-form.client.view.html', + data: { + hideNav: true, + }, + }). state('viewForm', { url: '/forms/:formId/admin', templateUrl: 'modules/forms/views/admin-form.client.view.html', data: { permissions: [ 'editForm' ] } - }). - state('viewPublicForm', { - url: '/forms/:formId', - templateUrl: 'modules/forms/views/view-public-form.client.view.html', - data: { - hideNav: true, - }, - }); + }); + } ]); \ No newline at end of file diff --git a/public/modules/forms/controllers/admin-form.client.controller.js b/public/modules/forms/controllers/admin-form.client.controller.js index 39fbed6c..b3f85146 100644 --- a/public/modules/forms/controllers/admin-form.client.controller.js +++ b/public/modules/forms/controllers/admin-form.client.controller.js @@ -7,15 +7,23 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope $scope = $rootScope; $scope.myform = CurrentForm.getForm(); + $scope.myform._id = $stateParams.formId; $rootScope.saveInProgress = false; // Find a specific Form $scope.findOne = function(){ - $scope.myform = Forms.get({ + Forms.get({ formId: $stateParams.formId + }, function(form){ + CurrentForm.setForm(form); + $scope.myform = form; + $scope.myform._id = $stateParams.formId; + }, function(err){ + console.error('Could not fetch form'); + console.error(err); }); - CurrentForm.setForm($scope.myform); }; + $scope.setForm = function(form){ $scope.myform = form; }; diff --git a/public/modules/forms/directives/edit-submissions-form.client.directive.js b/public/modules/forms/directives/edit-submissions-form.client.directive.js index 3fee0f57..fa067843 100644 --- a/public/modules/forms/directives/edit-submissions-form.client.directive.js +++ b/public/modules/forms/directives/edit-submissions-form.client.directive.js @@ -15,7 +15,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', rows: [] }; - /* ** Table Functions */ @@ -46,8 +45,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', $http.get('/forms/'+$scope.myform._id+'/submissions') .success(function(data, status, headers){ - console.log(data[0].form_fields); - var _tmpSubFormFields, defaultFormFields = _.cloneDeep($scope.myform.form_fields); @@ -68,7 +65,9 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', .error(function(err){ console.error('Could not fetch form submissions.\nError: '+err); }); - }; + + }; + //Delete selected submissions of Form $scope.deleteSelectedSubmissions = function(){ diff --git a/public/modules/forms/directives/entry_page.client.directive.js b/public/modules/forms/directives/entry_page.client.directive.js new file mode 100644 index 00000000..fbbf80ce --- /dev/null +++ b/public/modules/forms/directives/entry_page.client.directive.js @@ -0,0 +1,47 @@ +// 'use strict'; + +// angular.module('forms').directive('entryPage', ['$templateCache', '$http', '$compile', '$rootScope', +// function($templateCache, $http, $compile, $rootScope) { +// var getTemplateUrl = function(type) { + +// var templateUrl = 'modules/forms/views/directiveViews/entryPage/'; +// var supported_pages = [ +// 'welcome', +// 'thankyou' +// ]; +// if (__indexOf.call(supported_pages, type) >= 0) { +// templateUrl += type + '.html'; +// } +// var template = $templateCache.get(templateUrl); +// return template; +// }; +// return { +// restrict: 'E', +// template: '
Start Page
', +// scope: { +// 'pageData': '=', +// 'pageType': '&' +// }, +// link: function(scope, element) { + +// // console.log(attrs); +// console.log('scope.pageData'); +// // console.log(scope); +// scope.exitStartPage = function() { +// // console.log(scope.pageData); +// // if(attrs.pageData.showStart) attrs.pageData.showStart = false; +// }; + +// var template = getTemplateUrl(scope.pageType); +// element.html(template); +// $compile(element.contents())(scope); +// }, +// controller: function($scope){ +// console.log('entryPage Controller'); +// console.log($scope.pageData); +// // $scope.exitStartPage = function() { +// // if($scope.pageData.showStart) scope.pageData.showStart = false; +// // }; +// } +// }; +// }]); \ No newline at end of file diff --git a/public/modules/forms/directives/field.client.directive.js b/public/modules/forms/directives/field.client.directive.js index f05330fa..829ddaf9 100644 --- a/public/modules/forms/directives/field.client.directive.js +++ b/public/modules/forms/directives/field.client.directive.js @@ -18,6 +18,7 @@ angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', var templateUrl = 'modules/forms/views/directiveViews/field/'; var supported_fields = [ 'textfield', + 'welcome_page', 'email', 'textarea', 'checkbox', @@ -65,6 +66,7 @@ angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', // } // GET template content from path + console.log(scope.field); var template = getTemplateUrl(scope.field); // $http.get(templateUrl).success(function(data) { element.html(template); diff --git a/public/modules/forms/directives/submit-form.client.directive.js b/public/modules/forms/directives/submit-form.client.directive.js index 8ae98097..6e1da767 100644 --- a/public/modules/forms/directives/submit-form.client.directive.js +++ b/public/modules/forms/directives/submit-form.client.directive.js @@ -16,6 +16,9 @@ angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', ' TimeCounter.startClock() + $scope.exitStartPage = function(){ + $scope.myform.startPage.showStart = false; + } $rootScope.setActiveField = function (field_id) { $scope.selected = field_id; }; @@ -47,11 +50,6 @@ angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', ' }); }; - - $scope.exitStartPage = function () { - $scope.myform.startPage.showStart = false; - }; - $scope.reloadForm = function(){ //Reset Timer TimeCounter.stopClock(); diff --git a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js index 9ef77e7a..13e40a9a 100644 --- a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js +++ b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js @@ -154,7 +154,6 @@ }); })); - beforeEach(inject(function($modal) { spyOn($modal, 'open').and.returnValue(new fakeModal()); })); @@ -210,7 +209,7 @@ $httpBackend.flush(); // Test scope value - expect( scope.myform.toJSON() ).toEqualData(expectedFormObj.toJSON()); + expect( scope.myform.toJSON() ).toEqualData(expectedFormObj); })); it('$scope.removeCurrentForm() with valid form data should send a DELETE request with the id of form', function() { diff --git a/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js b/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js new file mode 100644 index 00000000..a28d70b0 --- /dev/null +++ b/public/modules/forms/tests/unit/directives/entry-page.client.directive.test.js @@ -0,0 +1,94 @@ +// 'use strict'; + +// (function() { +// // Forms Controller Spec +// describe('entryPage Directive Tests', function() { +// // Initialize global variables +// var scope, +// $templateCache, +// $httpBackend, +// $compile; + +// var sampleStartPage = { +// showStart: true, +// introTitle: 'Welcome to Form', +// introParagraph: 'Sample intro paragraph', +// buttons:[ +// { +// url: 'http://google.com', +// action: '', +// text: 'Google', +// bgColor: '#ffffff', +// color: '#000000', +// }, +// { +// url: 'http://facebook.com', +// action: '', +// text: 'Facebook', +// bgColor: '#0000ff', +// color: '#000000', +// } +// ] +// }; + + +// // The $resource service augments the response object with methods for updating and deleting the resource. +// // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match +// // the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher. +// // When the toEqualData matcher compares two objects, it takes only object properties into +// // account and ignores methods. +// beforeEach(function() { +// jasmine.addMatchers({ +// toEqualData: function(util, customEqualityTesters) { +// return { +// compare: function(actual, expected) { +// return { +// pass: angular.equals(actual, expected) +// }; +// } +// }; +// } +// }); +// }); + +// // Load the main application module +// beforeEach(module(ApplicationConfiguration.applicationModuleName)); +// beforeEach(module('module-templates')); + +// beforeEach(inject(function($rootScope, _$compile_, _$httpBackend_) { +// scope = $rootScope.$new(); +// $compile = _$compile_; + +// // Point global variables to injected services +// $httpBackend = _$httpBackend_; +// })); + + +// it('should be able to render entryPage in html', function() { +// scope.myStartPage = _.cloneDeep(sampleStartPage); +// console.log(scope.myStartPage); +// var element = angular.element(''); +// $compile(element)(scope); +// scope.$digest(); + +// // console.log(element.html()); +// expect(element.html()).not.toEqual('
Start Page
'); +// }); + +// // it('exitStartPage should work for "startPage" type of entryPage', inject(function($rootScope) { +// // scope.myPage = _.cloneDeep(sampleStartPage); +// // var el = angular.element(''); +// // $compile(el)(scope); +// // scope.$digest(); + +// // $httpBackend.whenGET(/.+\.html$/).respond(''); +// // $httpBackend.whenGET('/users/me/').respond(''); + +// // scope = el.isolateScope() || el.scope(); + +// // scope.exitStartPage(); +// // // expect(scope.myStartPage.showStart).toBe(false); +// // expect(el.html()).not.toEqual('
Start Page
'); +// // })); +// }); +// }()); \ No newline at end of file diff --git a/public/modules/forms/views/admin-form.client.view.html b/public/modules/forms/views/admin-form.client.view.html index ff76d4f9..dd2dd0e8 100644 --- a/public/modules/forms/views/admin-form.client.view.html +++ b/public/modules/forms/views/admin-form.client.view.html @@ -90,9 +90,9 @@ - - - -
-

{{myform.startPage.introTitle}}

+

{{pageData.introTitle}}

-

{{myform.startPage.introParagraph}}

+

{{pageData.introParagraph}}

-
-

+

+

diff --git a/public/modules/forms/views/directiveViews/form/submit-form.client.view.html b/public/modules/forms/views/directiveViews/form/submit-form.client.view.html index 49f76d37..6202c816 100755 --- a/public/modules/forms/views/directiveViews/form/submit-form.client.view.html +++ b/public/modules/forms/views/directiveViews/form/submit-form.client.view.html @@ -5,23 +5,25 @@
-

Welcome to {{myform.title}}

+

{{myform.startPage.introTitle}}

-
-

{{myform.startPage.introText}}

+
+

{{myform.startPage.introParagraph}}

- diff --git a/public/modules/users/controllers/authentication.client.controller.js b/public/modules/users/controllers/authentication.client.controller.js index 71c71806..98dcda59 100755 --- a/public/modules/users/controllers/authentication.client.controller.js +++ b/public/modules/users/controllers/authentication.client.controller.js @@ -36,6 +36,8 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca $state.go('signup-success'); }, function(error) { + console.log('Error: '); + console.log(error); if(error) { $scope.error = error; console.log(error);