fixed login/signup bug

This commit is contained in:
David Baldwynn 2015-09-15 15:21:49 -07:00
parent dee6945d88
commit 8b8aed337e
17 changed files with 385 additions and 164 deletions

View file

@ -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();
}
});
}
};
/**

View file

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

View file

@ -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){

View file

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

View file

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

View file

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

View file

@ -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(){

View file

@ -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: '<div>Start Page</div>',
// 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;
// // };
// }
// };
// }]);

View file

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

View file

@ -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();

View file

@ -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() {

View file

@ -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('<entry-page pageData="myStartPage" pageType="startPage"></entry-page>');
// $compile(element)(scope);
// scope.$digest();
// // console.log(element.html());
// expect(element.html()).not.toEqual('<div class="ng-scope">Start Page</div>');
// });
// // it('exitStartPage should work for "startPage" type of entryPage', inject(function($rootScope) {
// // scope.myPage = _.cloneDeep(sampleStartPage);
// // var el = angular.element('<entry-page pageData="myPage" pageType="startPage"></entry-page>');
// // $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('<div>Start Page</div>');
// // }));
// });
// }());

View file

@ -90,9 +90,9 @@
</edit-submissions-form-directive>
</tab>
</tabset>
<!--
<!--
<div class="cg-busy cg-busy-backdrop cg-busy-backdrop-animation ng-show ng-scope"></div> -->
<!--
<!--
<div class="cg-busy cg-busy-animation cg-busy-default-wrapper">
<div class="cg-busy-default-sign">
<div class="cg-busy-default-spinner">
@ -113,7 +113,7 @@
</div>
</div> -->
<!-- <div class="cg-busy cg-busy-animation cg-busy-default-wrapper">
<!-- <div class="cg-busy cg-busy-animation cg-busy-default-wrapper">
<div style="position: absolute; top: 0px; right: 0px;">
<div class="cg-busy-default-spinner">
<div class="bar1"></div>
@ -133,7 +133,7 @@
</div>
</div> -->
<!-- <div class="cg-busy cg-busy-backdrop cg-busy-backdrop-animation ng-show ng-scope"></div>
<!-- <div class="cg-busy cg-busy-backdrop cg-busy-backdrop-animation ng-show ng-scope"></div>
<div class="cg-busy cg-busy-animation">
<div style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;">

View file

@ -0,0 +1,24 @@
<div class="field row text-center">
<div class="col-xs-12 text-center">
<h1>{{pageData.introTitle}}</h1>
</div>
<div class="col-xs-10 col-xs-offset-1 text-left">
<p style="color:#ddd;">{{pageData.introParagraph}}</p>
</div>
</div>
<div class="row form-actions" style="padding-bottom:3em; padding-left: 1em; padding-right: 1em;">
<p ng-repeat="button in pageData.buttons" class="text-center" style="display:inline;">
<button class="btn btn-info" type="button" ng-style="{'background-color':button.bgColor, 'color':button.color}">
<a href="{{button.url}}" style="font-size: 1.6em; text-decoration: none; color: inherit;" >
{{button.text}}
</a>
</button>
</p>
</div>
<div class="row form-actions">
<p class="col-xs-3 col-xs-offset-3 text-center">
<button class="btn btn-info" type="button">
<a ng-click="exitpageData()" style="color:white; font-size: 1.6em; text-decoration: none;">Continue to Form</a>
</button>
</p>
</div>

View file

@ -50,16 +50,17 @@
<h4>Preview Start Page</h4>
</div>
<ul class="col-md-12 container" style="list-style:none;border:2px lightgray solid;">
<!-- <entryPage pageData="myform.startPage" pageType="startPage"></entryPage> -->
<div class="field row text-center">
<div class="col-xs-12 text-center">
<h1>{{myform.startPage.introTitle}}</h1>
<h1>{{pageData.introTitle}}</h1>
</div>
<div class="col-xs-10 col-xs-offset-1 text-left">
<p style="color:#ddd;">{{myform.startPage.introParagraph}}</p>
<p style="color:#ddd;">{{pageData.introParagraph}}</p>
</div>
</div>
<div class="row form-actions" style="padding-bottom:3em; padding-left: 1em; padding-right: 1em;">
<p ng-repeat="button in myform.startPage.buttons" class="text-center" style="display:inline;">
<div class="row form-actions" style="padding-bottom:3em; padding-left: 1em; padding-right: 1em;">
<p ng-repeat="button in pageData.buttons" class="text-center" style="display:inline;">
<button class="btn btn-info" type="button" ng-style="{'background-color':button.bgColor, 'color':button.color}">
<a href="{{button.url}}" style="font-size: 1.6em; text-decoration: none; color: inherit;" >
{{button.text}}
@ -70,7 +71,7 @@
<div class="row form-actions">
<p class="col-xs-3 col-xs-offset-3 text-center">
<button class="btn btn-info" type="button">
<a ng-click="exitstartPage()" style="color:white; font-size: 1.6em; text-decoration: none;">Continue to Form</a>
<a ng-click="exitpageData()" style="color:white; font-size: 1.6em; text-decoration: none;">Continue to Form</a>
</button>
</p>
</div>

View file

@ -5,23 +5,25 @@
<div ng-show="!myform.submitted && myform.startPage.showStart" class="form-submitted">
<div class="field row text-center">
<div class="col-xs-12 text-center">
<h1>Welcome to {{myform.title}}</h1>
<h1>{{myform.startPage.introTitle}}</h1>
</div>
<div class="col-xs-10 col-xs-offset-1 text-center">
<p>{{myform.startPage.introText}}</p>
<div class="col-xs-10 col-xs-offset-1 text-left">
<p style="color:#ddd;">{{myform.startPage.introParagraph}}</p>
</div>
</div>
<div class="row form-actions">
<p ng-repeat="button in myform.startPage.buttons" class="col-xs-6 col-xs-offset-3 text-center">
<button class="btn btn-info" type="button">
<a href="{{button.url}}" style="font-size: 1.6em; text-decoration: none;">{{button.buttonText}}</a>
<div class="row form-actions" style="padding-bottom:3em; padding-left: 1em; padding-right: 1em;">
<p ng-repeat="button in myform.startPage.buttons" class="text-center" style="display:inline;">
<button class="btn btn-info" type="button" ng-style="{'background-color':button.bgColor, 'color':button.color}">
<a href="{{button.url}}" style="font-size: 1.6em; text-decoration: none; color: inherit;" >
{{button.text}}
</a>
</button>
</p>
</div>
<div class="row form-actions">
<p class="col-xs-6 col-xs-offset-3 text-center">
<p class="col-xs-3 col-xs-offset-3 text-center">
<button class="btn btn-info" type="button">
<a ng-click="exitStartPage()" style="font-size: 1.6em; text-decoration: none;">Continue to Form</a>
<a ng-click="exitStartPage()" style="color:white; font-size: 1.6em; text-decoration: none;">Continue to Form</a>
</button>
</p>
</div>

View file

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