fixed email verification
This commit is contained in:
parent
6c2f23c0c9
commit
1309832742
|
@ -1,16 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
// var raven = require('raven');
|
||||
var config = require('../../config/config');
|
||||
// var client = new raven.Client(config.DSN);
|
||||
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
exports.index = function(req, res) {
|
||||
// next( throw new Error('Hello, world!'));
|
||||
// client.captureMessage('Rendering index.html');
|
||||
res.render('index', {
|
||||
user: req.user || null,
|
||||
request: req
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* Module dependencies.
|
||||
*/
|
||||
var _ = require('lodash'),
|
||||
nev = require('email-verification'),
|
||||
errorHandler = require('../errors.server.controller'),
|
||||
mongoose = require('mongoose'),
|
||||
passport = require('passport'),
|
||||
|
@ -12,16 +11,52 @@ var _ = require('lodash'),
|
|||
config = require('../../../config/config'),
|
||||
nodemailer = require('nodemailer'),
|
||||
crypto = require('crypto'),
|
||||
nev = require('email-verification'),
|
||||
User = mongoose.model('User');
|
||||
|
||||
var nev = require('email-verification')(mongoose);
|
||||
|
||||
// NEV setup and configuration ================
|
||||
var config_nev = function () {
|
||||
|
||||
var User = require('../../models/user.server.model');
|
||||
|
||||
nev.configure({
|
||||
persistentUserModel: User,
|
||||
tempUserCollection: config.tempUserCollection,
|
||||
expirationTime: 1800, // 30 minutes
|
||||
|
||||
verificationURL: config.baseUrl+'/#!/verify/${URL}',
|
||||
transportOptions: config.mailer.options,
|
||||
verifyMailOptions: {
|
||||
from: config.mailer.from,
|
||||
subject: 'Confirm your account',
|
||||
html: '<p>Please verify your account by clicking <a href="${URL}">this link</a>. If you are unable to do so, copy and ' +
|
||||
'paste the following link into your browser:</p><p>${URL}</p>',
|
||||
text: 'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
|
||||
},
|
||||
|
||||
confirmMailOptions: {
|
||||
from: config.mailer.from,
|
||||
subject: 'Account successfully verified!',
|
||||
html: '<p>Your account has been successfully verified.</p>',
|
||||
text: 'Your account has been successfully verified.'
|
||||
},
|
||||
|
||||
});
|
||||
nev.generateTempUserModel(User);
|
||||
};
|
||||
|
||||
config_nev();
|
||||
|
||||
var smtpTransport = nodemailer.createTransport(config.mailer.options);
|
||||
|
||||
exports.validateVerificationToken = function(req, res, next){
|
||||
exports.validateVerificationToken = function(req, res){
|
||||
console.log('validateVerificationToken');
|
||||
console.log('token: '+req.params.token+'\n\n');
|
||||
nev.confirmTempUser(req.params.token, function(user) {
|
||||
if (user){
|
||||
nev.confirmTempUser(req.params.token, function(user, err) {
|
||||
if(err) {
|
||||
res.status(500).send( {message: errorHandler.getErrorMessage(err) } );
|
||||
}else if (user){
|
||||
res.status(200).send('User successfully verified');
|
||||
}else {
|
||||
// redirect to resend verification email
|
||||
|
@ -31,8 +66,10 @@ exports.validateVerificationToken = function(req, res, next){
|
|||
};
|
||||
|
||||
exports.resendVerificationEmail = function(req, res, next){
|
||||
nev.resendVerificationEmail(req.body.email, function(user) {
|
||||
if (user){
|
||||
nev.resendVerificationEmail(req.body.email, function(err, userFound) {
|
||||
if(err) {
|
||||
res.status(500).send( {message: errorHandler.getErrorMessage(err) } );
|
||||
}else if (userFound){
|
||||
res.status(200).send('Verification email successfully Re-Sent');
|
||||
}else {
|
||||
// user hasn't been found yet
|
||||
|
@ -66,7 +103,7 @@ exports.signup = function(req, res) {
|
|||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}else {
|
||||
console.log('new tmpuser created');
|
||||
|
||||
// new user created
|
||||
if (newTempUser) {
|
||||
nev.registerTempUser(newTempUser, function (err) {
|
||||
|
@ -120,7 +157,6 @@ exports.signin = function(req, res, next) {
|
|||
*/
|
||||
exports.signout = function(req, res) {
|
||||
req.logout();
|
||||
// res.status(200).send('Successfully logged out');
|
||||
res.redirect('/');
|
||||
};
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@ FormSchema.pre('save', function (next) {
|
|||
'Radio': 'radio'
|
||||
};
|
||||
|
||||
console.log('autogenerating form');
|
||||
// console.log('autogenerating form');
|
||||
// console.log(that.pdf.path);
|
||||
|
||||
pdfFiller.generateFieldJson(that.pdf.path, function(err, _form_fields){
|
||||
|
@ -373,7 +373,7 @@ FormSchema.pre('save', function (next) {
|
|||
});
|
||||
|
||||
FormSchema.pre('save', function (next) {
|
||||
// var _original = this._original;
|
||||
|
||||
// console.log('_original\n------------');
|
||||
// console.log(_original);
|
||||
//console.log('field has been deleted: ');
|
||||
|
@ -404,23 +404,6 @@ FormSchema.pre('save', function (next) {
|
|||
|
||||
var deleted_id = old_ids[deletedIdIndex];
|
||||
|
||||
//Search for submissions with deleted form_field
|
||||
// if(submissions.length){
|
||||
// submissionsWithDeletedField = _.select(form.submissions, function(submission){
|
||||
// var field = _(submission.form_fields).filter(function(field) { return field._id === deleted_id; })
|
||||
// return !!field;
|
||||
// });
|
||||
|
||||
// //Push old form_field to start of array
|
||||
// if(submissionsWithDeletedField.length){
|
||||
// that.form_fields.unshift(old_form_fields[deletedIdIndex]);
|
||||
// modifiedSubmissions.push.apply(modifiedSubmissions, submissionsWithDeletedField);
|
||||
// console.log(modifiedSubmissions);
|
||||
// }
|
||||
|
||||
// callback(null, modifiedSubmissions);
|
||||
// } else{
|
||||
|
||||
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
|
||||
FormSubmission.
|
||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
|
||||
|
|
|
@ -28,12 +28,6 @@ var FieldOptionSchema = new Schema({
|
|||
* FormField Schema
|
||||
*/
|
||||
var FormFieldSchema = new Schema({
|
||||
// formSubmission: {
|
||||
// type: Schema.ObjectId,
|
||||
// ref: 'FormSubmission',
|
||||
// childPath: 'form_fields'
|
||||
// },
|
||||
|
||||
title: {
|
||||
type: String,
|
||||
trim: true,
|
||||
|
@ -95,7 +89,6 @@ var FormFieldSchema = new Schema({
|
|||
fieldValue: Schema.Types.Mixed
|
||||
});
|
||||
|
||||
// FormFieldSchema.plugin(relationship, { relationshipPathName:'formSubmission' });
|
||||
FormFieldSchema.plugin(mUtilities.timestamp, {
|
||||
createdPath: 'created',
|
||||
modifiedPath: 'lastModified',
|
||||
|
|
|
@ -247,5 +247,3 @@ FormSubmissionSchema.pre('save', function (next) {
|
|||
});
|
||||
|
||||
module.exports = FormSubmissionSchema;
|
||||
|
||||
//mongoose.model('FormSubmission', FormSubmissionSchema);
|
||||
|
|
|
@ -18,14 +18,6 @@ var BooleanExpressionSchema = new Schema({
|
|||
}
|
||||
});
|
||||
|
||||
/*
|
||||
BooleanExpresssionSchema.plugin(tree, {
|
||||
pathSeparator : '#' // Default path separator
|
||||
onDelete : 'DELETE' // Can be set to 'DELETE' or 'REPARENT'. Default: 'REPARENT'
|
||||
numWorkers: 5 // Number of stream workers
|
||||
idType: Schema.ObjectId // Type used for _id. Can be, for example, String generated by shortid module
|
||||
});
|
||||
*/
|
||||
|
||||
BooleanExpressionSchema.methods.evaluate = function(){
|
||||
|
||||
|
@ -83,5 +75,4 @@ var LogicJumpSchema = new Schema({
|
|||
|
||||
});
|
||||
|
||||
// return LogicJumpSchema;
|
||||
mongoose.model('LogicJump', LogicJumpSchema);
|
||||
|
|
|
@ -142,16 +142,6 @@ UserSchema.virtual('password').get(function () {
|
|||
});
|
||||
|
||||
|
||||
// UserSchema.pre('save', function(next) {
|
||||
// if (this.password && this.password.length > 6) {
|
||||
// this.salt = crypto.randomBytes(16).toString('base64');
|
||||
// this.password = this.hashPassword(this.password);
|
||||
// }
|
||||
|
||||
// next();
|
||||
// });
|
||||
|
||||
|
||||
/**
|
||||
* Create instance method for hashing a password
|
||||
*/
|
||||
|
@ -207,4 +197,4 @@ UserSchema.methods.isAdmin = function() {
|
|||
return false;
|
||||
};
|
||||
|
||||
mongoose.model('User', UserSchema);
|
||||
module.exports = mongoose.model('User', UserSchema);
|
||||
|
|
|
@ -9,20 +9,20 @@ var users = require('../../app/controllers/users.server.controller'),
|
|||
config = require('../../config/config');
|
||||
|
||||
// Setting the pdf upload route and folder
|
||||
var upload = multer({ dest: config.tmpUploadPath,
|
||||
rename: function (fieldname, filename) {
|
||||
return Date.now();
|
||||
},
|
||||
onFileUploadStart: function (file) {
|
||||
//Check to make sure we can only upload images and pdfs
|
||||
console.log(file.originalname + ' is starting ...');
|
||||
},
|
||||
onFileUploadComplete: function (file, req, res) {
|
||||
console.log(file.originalname + ' uploaded to ' + file.path);
|
||||
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||
// res.status(200).send(file);
|
||||
}
|
||||
});
|
||||
// var upload = multer({ dest: config.tmpUploadPath,
|
||||
// rename: function (fieldname, filename) {
|
||||
// return Date.now();
|
||||
// },
|
||||
// onFileUploadStart: function (file) {
|
||||
// //Check to make sure we can only upload images and pdfs
|
||||
// console.log(file.originalname + ' is starting ...');
|
||||
// },
|
||||
// onFileUploadComplete: function (file, req, res) {
|
||||
// console.log(file.originalname + ' uploaded to ' + file.path);
|
||||
// // console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||
// // res.status(200).send(file);
|
||||
// }
|
||||
// });
|
||||
|
||||
module.exports = function(app) {
|
||||
// Form Routes
|
||||
|
|
2
config/env/development.js
vendored
2
config/env/development.js
vendored
|
@ -49,7 +49,7 @@ module.exports = {
|
|||
mailer: {
|
||||
from: process.env.MAILER_FROM || '',
|
||||
options: {
|
||||
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||
service: process.env.MAILER_SERVICE_PROVIDER || 'no-reply@kioskform.herokuapp.com',
|
||||
auth: {
|
||||
user: process.env.MAILER_EMAIL_ID || '',
|
||||
pass: process.env.MAILER_PASSWORD || ''
|
||||
|
|
77
config/env/production-dev.js
vendored
Normal file
77
config/env/production-dev.js
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
baseUrl: 'kioskform-dev.herokuapp.com',
|
||||
db: {
|
||||
uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
|
||||
options: {
|
||||
user: 'admin',
|
||||
pass: process.env.MONGOLAB_PASS || 'admin'
|
||||
}
|
||||
},
|
||||
log: {
|
||||
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
|
||||
format: 'dev',
|
||||
// Stream defaults to process.stdout
|
||||
// Uncomment to enable logging to a log on the file system
|
||||
options: {
|
||||
stream: 'access.log'
|
||||
}
|
||||
},
|
||||
sessionCookie: {
|
||||
domain: 'kioskform-dev.herokuapp.com'
|
||||
},
|
||||
assets: {
|
||||
// lib: {
|
||||
// css: [
|
||||
// 'public/lib/bootstrap/dist/css/bootstrap.min.css',
|
||||
// 'public/lib/bootstrap/dist/css/bootstrap-theme.min.css',
|
||||
// ],
|
||||
// js: [
|
||||
// 'public/lib/angular/angular.min.js',
|
||||
// 'public/lib/angular-resource/angular-resource.min.js',
|
||||
// 'public/lib/angular-animate/angular-animate.min.js',
|
||||
// 'public/lib/angular-ui-router/release/angular-ui-router.min.js',
|
||||
// 'public/lib/angular-ui-utils/ui-utils.min.js',
|
||||
// 'public/lib/angular-bootstrap/ui-bootstrap-tpls.min.js'
|
||||
// ]
|
||||
// },
|
||||
css: 'public/dist/application.min.css',
|
||||
js: 'public/dist/application.min.js'
|
||||
},
|
||||
facebook: {
|
||||
clientID: process.env.FACEBOOK_ID || 'APP_ID',
|
||||
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
|
||||
callbackURL: '/auth/facebook/callback'
|
||||
},
|
||||
twitter: {
|
||||
clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY',
|
||||
clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET',
|
||||
callbackURL: '/auth/twitter/callback'
|
||||
},
|
||||
google: {
|
||||
clientID: process.env.GOOGLE_ID || 'APP_ID',
|
||||
clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET',
|
||||
callbackURL: '/auth/google/callback'
|
||||
},
|
||||
linkedin: {
|
||||
clientID: process.env.LINKEDIN_ID || 'APP_ID',
|
||||
clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET',
|
||||
callbackURL: '/auth/linkedin/callback'
|
||||
},
|
||||
github: {
|
||||
clientID: process.env.GITHUB_ID || 'APP_ID',
|
||||
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
|
||||
callbackURL: '/auth/github/callback'
|
||||
},
|
||||
mailer: {
|
||||
from: process.env.MAILER_FROM || 'no-reply@kioskform-dev.herokuapp.com',
|
||||
options: {
|
||||
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||
auth: {
|
||||
user: process.env.MAILER_EMAIL_ID || '',
|
||||
pass: process.env.MAILER_PASSWORD || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
6
config/env/production.js
vendored
6
config/env/production.js
vendored
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
baseUrl: 'kioskform-dev.herokuapp.com',
|
||||
baseUrl: 'kioskform.herokuapp.com',
|
||||
db: {
|
||||
uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
|
||||
options: {
|
||||
|
@ -19,7 +19,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
sessionCookie: {
|
||||
domain: 'kioskform-dev.herokuapp.com'
|
||||
domain: 'kioskform.herokuapp.com'
|
||||
},
|
||||
assets: {
|
||||
// lib: {
|
||||
|
@ -67,7 +67,7 @@ module.exports = {
|
|||
mailer: {
|
||||
from: process.env.MAILER_FROM || '',
|
||||
options: {
|
||||
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||
service: process.env.MAILER_SERVICE_PROVIDER || 'no-reply@kioskform.herokuapp.com',
|
||||
auth: {
|
||||
user: process.env.MAILER_EMAIL_ID || '',
|
||||
pass: process.env.MAILER_PASSWORD || ''
|
||||
|
|
|
@ -18,47 +18,13 @@ var fs = require('fs-extra'),
|
|||
multer = require('multer'),
|
||||
passport = require('passport'),
|
||||
raven = require('raven'),
|
||||
mongoStore = require('connect-mongo')({
|
||||
session: session
|
||||
}),
|
||||
MongoStore = require('connect-mongo')(session),
|
||||
flash = require('connect-flash'),
|
||||
config = require('./config'),
|
||||
consolidate = require('consolidate'),
|
||||
path = require('path'),
|
||||
client = new raven.Client(config.DSN);
|
||||
|
||||
// NEV setup and configuration ================
|
||||
var config_nev = function () {
|
||||
|
||||
var nev = require('email-verification'),
|
||||
mongoose = require('mongoose'),
|
||||
User = mongoose.model('User');
|
||||
|
||||
nev.configure({
|
||||
persistentUserModel: User,
|
||||
tempUserCollection: config.tempUserCollection,
|
||||
expirationTime: 1800, // 30 minutes
|
||||
|
||||
verificationURL: config.baseUrl+'/#!/verify/${URL}',
|
||||
transportOptions: config.mailer.options,
|
||||
verifyMailOptions: {
|
||||
from: config.mailer.from,
|
||||
subject: 'Confirm your account',
|
||||
html: '<p>Please verify your account by clicking <a href="${URL}">this link</a>. If you are unable to do so, copy and ' +
|
||||
'paste the following link into your browser:</p><p>${URL}</p>',
|
||||
text: 'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
|
||||
},
|
||||
|
||||
confirmMailOptions: {
|
||||
from: config.mailer.from,
|
||||
subject: 'Account successfully verified!',
|
||||
html: '<p>Your account has been successfully verified.</p>',
|
||||
text: 'Your account has been successfully verified.'
|
||||
},
|
||||
|
||||
});
|
||||
nev.generateTempUserModel(User);
|
||||
};
|
||||
|
||||
|
||||
module.exports = function(db) {
|
||||
|
@ -70,9 +36,6 @@ module.exports = function(db) {
|
|||
require(path.resolve(modelPath));
|
||||
});
|
||||
|
||||
//Configure Node-Email-Verification
|
||||
config_nev();
|
||||
|
||||
// Setting application local variables
|
||||
app.locals.title = config.app.title;
|
||||
app.locals.description = config.app.description;
|
||||
|
@ -169,10 +132,10 @@ module.exports = function(db) {
|
|||
saveUninitialized: true,
|
||||
resave: true,
|
||||
secret: config.sessionSecret,
|
||||
store: new mongoStore({
|
||||
db: db.connection.db,
|
||||
collection: config.sessionCollection
|
||||
}),
|
||||
store: new MongoStore({
|
||||
mongooseConnection: db.connection,
|
||||
collection: config.sessionCollection
|
||||
}),
|
||||
cookie: config.sessionCookie,
|
||||
name: config.sessionName
|
||||
}));
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
"chalk": "~1.0.0",
|
||||
"compression": "~1.2.0",
|
||||
"connect-flash": "~0.1.1",
|
||||
"connect-mongo": "~0.4.1",
|
||||
"connect-mongo": "~0.8.1",
|
||||
"consolidate": "~0.10.0",
|
||||
"cookie-parser": "~1.3.2",
|
||||
"email-verification": "whitef0x0/node-email-verification",
|
||||
"email-verification": "~0.3.1",
|
||||
"express": "~4.10.1",
|
||||
"express-session": "~1.9.1",
|
||||
"forever": "~0.11.0",
|
||||
|
|
Loading…
Reference in a new issue