no message
This commit is contained in:
302
.eslintrc.js
302
.eslintrc.js
@@ -4,22 +4,314 @@ module.exports = {
|
|||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": "eslint:recommended",
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"indent": [
|
"accessor-pairs": "error",
|
||||||
|
"array-bracket-newline": "off",
|
||||||
|
"array-bracket-spacing": "off",
|
||||||
|
"array-callback-return": "error",
|
||||||
|
"array-element-newline": "off",
|
||||||
|
"arrow-body-style": "off",
|
||||||
|
"arrow-parens": [
|
||||||
"error",
|
"error",
|
||||||
4
|
"always"
|
||||||
],
|
],
|
||||||
|
"arrow-spacing": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"after": true,
|
||||||
|
"before": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"block-scoped-var": "error",
|
||||||
|
"block-spacing": [
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"brace-style": "off",
|
||||||
|
"callback-return": "off",
|
||||||
|
"camelcase": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"properties": "never"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"capitalized-comments": "off",
|
||||||
|
"class-methods-use-this": "error",
|
||||||
|
"comma-dangle": "error",
|
||||||
|
"comma-spacing": "off",
|
||||||
|
"comma-style": [
|
||||||
|
"error",
|
||||||
|
"last"
|
||||||
|
],
|
||||||
|
"complexity": "error",
|
||||||
|
"computed-property-spacing": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"consistent-return": "off",
|
||||||
|
"consistent-this": "off",
|
||||||
|
"curly": "off",
|
||||||
|
"default-case": "error",
|
||||||
|
"dot-location": [
|
||||||
|
"error",
|
||||||
|
"property"
|
||||||
|
],
|
||||||
|
"dot-notation": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"allowKeywords": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"eol-last": "off",
|
||||||
|
"eqeqeq": "off",
|
||||||
|
"for-direction": "error",
|
||||||
|
"func-call-spacing": "error",
|
||||||
|
"func-name-matching": "error",
|
||||||
|
"func-names": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"func-style": [
|
||||||
|
"error",
|
||||||
|
"declaration"
|
||||||
|
],
|
||||||
|
"function-paren-newline": "off",
|
||||||
|
"generator-star-spacing": "error",
|
||||||
|
"getter-return": "error",
|
||||||
|
"global-require": "error",
|
||||||
|
"guard-for-in": "off",
|
||||||
|
"handle-callback-err": "off",
|
||||||
|
"id-blacklist": "error",
|
||||||
|
"id-length": "off",
|
||||||
|
"id-match": "error",
|
||||||
|
"implicit-arrow-linebreak": [
|
||||||
|
"error",
|
||||||
|
"beside"
|
||||||
|
],
|
||||||
|
"indent": "off",
|
||||||
|
"indent-legacy": "off",
|
||||||
|
"init-declarations": "off",
|
||||||
|
"jsx-quotes": "error",
|
||||||
|
"key-spacing": "off",
|
||||||
|
"keyword-spacing": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"after": true,
|
||||||
|
"before": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"line-comment-position": "off",
|
||||||
"linebreak-style": [
|
"linebreak-style": [
|
||||||
"error",
|
"error",
|
||||||
"unix"
|
"unix"
|
||||||
],
|
],
|
||||||
"quotes": [
|
"lines-around-comment": "error",
|
||||||
|
"lines-around-directive": "error",
|
||||||
|
"lines-between-class-members": "error",
|
||||||
|
"max-depth": "error",
|
||||||
|
"max-len": "off",
|
||||||
|
"max-lines": "off",
|
||||||
|
"max-nested-callbacks": "error",
|
||||||
|
"max-params": "off",
|
||||||
|
"max-statements": "off",
|
||||||
|
"max-statements-per-line": "off",
|
||||||
|
"multiline-comment-style": [
|
||||||
"error",
|
"error",
|
||||||
"single"
|
"separate-lines"
|
||||||
],
|
],
|
||||||
"semi": [
|
"multiline-ternary": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"new-parens": "error",
|
||||||
|
"newline-after-var": "off",
|
||||||
|
"newline-before-return": "off",
|
||||||
|
"newline-per-chained-call": "off",
|
||||||
|
"no-alert": "error",
|
||||||
|
"no-array-constructor": "error",
|
||||||
|
"no-await-in-loop": "error",
|
||||||
|
"no-bitwise": "error",
|
||||||
|
"no-buffer-constructor": "error",
|
||||||
|
"no-caller": "error",
|
||||||
|
"no-catch-shadow": "off",
|
||||||
|
"no-confusing-arrow": "error",
|
||||||
|
"no-continue": "error",
|
||||||
|
"no-div-regex": "error",
|
||||||
|
"no-duplicate-imports": "error",
|
||||||
|
"no-else-return": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"allowElseIf": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-empty-function": "off",
|
||||||
|
"no-eq-null": "error",
|
||||||
|
"no-eval": "error",
|
||||||
|
"no-extend-native": "error",
|
||||||
|
"no-extra-bind": "error",
|
||||||
|
"no-extra-label": "error",
|
||||||
|
"no-extra-parens": "off",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-implicit-globals": "error",
|
||||||
|
"no-implied-eval": "error",
|
||||||
|
"no-inline-comments": "off",
|
||||||
|
"no-inner-declarations": [
|
||||||
|
"error",
|
||||||
|
"functions"
|
||||||
|
],
|
||||||
|
"no-invalid-this": "off",
|
||||||
|
"no-iterator": "error",
|
||||||
|
"no-label-var": "error",
|
||||||
|
"no-labels": "error",
|
||||||
|
"no-lone-blocks": "error",
|
||||||
|
"no-lonely-if": "off",
|
||||||
|
"no-loop-func": "off",
|
||||||
|
"no-magic-numbers": "off",
|
||||||
|
"no-mixed-operators": "off",
|
||||||
|
"no-mixed-requires": "error",
|
||||||
|
"no-multi-assign": "error",
|
||||||
|
"no-multi-spaces": "off",
|
||||||
|
"no-multi-str": "error",
|
||||||
|
"no-multiple-empty-lines": "error",
|
||||||
|
"no-native-reassign": "error",
|
||||||
|
"no-negated-condition": "error",
|
||||||
|
"no-negated-in-lhs": "error",
|
||||||
|
"no-nested-ternary": "error",
|
||||||
|
"no-new": "error",
|
||||||
|
"no-new-func": "error",
|
||||||
|
"no-new-object": "error",
|
||||||
|
"no-new-require": "error",
|
||||||
|
"no-new-wrappers": "error",
|
||||||
|
"no-octal-escape": "error",
|
||||||
|
"no-param-reassign": "off",
|
||||||
|
"no-path-concat": "error",
|
||||||
|
"no-plusplus": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"allowForLoopAfterthoughts": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-process-env": "error",
|
||||||
|
"no-process-exit": "error",
|
||||||
|
"no-proto": "error",
|
||||||
|
"no-prototype-builtins": "error",
|
||||||
|
"no-restricted-globals": "error",
|
||||||
|
"no-restricted-imports": "error",
|
||||||
|
"no-restricted-modules": "error",
|
||||||
|
"no-restricted-properties": "error",
|
||||||
|
"no-restricted-syntax": "error",
|
||||||
|
"no-return-assign": "error",
|
||||||
|
"no-return-await": "error",
|
||||||
|
"no-script-url": "error",
|
||||||
|
"no-self-compare": "error",
|
||||||
|
"no-sequences": "error",
|
||||||
|
"no-shadow": "off",
|
||||||
|
"no-shadow-restricted-names": "error",
|
||||||
|
"no-spaced-func": "error",
|
||||||
|
"no-sync": "error",
|
||||||
|
"no-tabs": "off",
|
||||||
|
"no-template-curly-in-string": "error",
|
||||||
|
"no-ternary": "off",
|
||||||
|
"no-throw-literal": "error",
|
||||||
|
"no-trailing-spaces": "off",
|
||||||
|
"no-undef-init": "error",
|
||||||
|
"no-undefined": "error",
|
||||||
|
"no-underscore-dangle": "off",
|
||||||
|
"no-unmodified-loop-condition": "error",
|
||||||
|
"no-unneeded-ternary": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"defaultAssignment": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-unused-expressions": "error",
|
||||||
|
"no-use-before-define": "off",
|
||||||
|
"no-useless-call": "error",
|
||||||
|
"no-useless-computed-key": "error",
|
||||||
|
"no-useless-concat": "error",
|
||||||
|
"no-useless-constructor": "error",
|
||||||
|
"no-useless-rename": "error",
|
||||||
|
"no-useless-return": "error",
|
||||||
|
"no-var": "off",
|
||||||
|
"no-void": "error",
|
||||||
|
"no-warning-comments": "error",
|
||||||
|
"no-whitespace-before-property": "error",
|
||||||
|
"no-with": "error",
|
||||||
|
"nonblock-statement-body-position": "error",
|
||||||
|
"object-curly-newline": "off",
|
||||||
|
"object-curly-spacing": "off",
|
||||||
|
"object-shorthand": "off",
|
||||||
|
"one-var": "off",
|
||||||
|
"one-var-declaration-per-line": [
|
||||||
|
"error",
|
||||||
|
"initializations"
|
||||||
|
],
|
||||||
|
"operator-assignment": "off",
|
||||||
|
"operator-linebreak": "error",
|
||||||
|
"padded-blocks": "off",
|
||||||
|
"padding-line-between-statements": "error",
|
||||||
|
"prefer-arrow-callback": "off",
|
||||||
|
"prefer-const": "off",
|
||||||
|
"prefer-destructuring": "off",
|
||||||
|
"prefer-numeric-literals": "error",
|
||||||
|
"prefer-promise-reject-errors": "off",
|
||||||
|
"prefer-reflect": "off",
|
||||||
|
"prefer-rest-params": "off",
|
||||||
|
"prefer-spread": "error",
|
||||||
|
"prefer-template": "off",
|
||||||
|
"quote-props": "off",
|
||||||
|
"quotes": "off",
|
||||||
|
"radix": [
|
||||||
|
"error",
|
||||||
|
"as-needed"
|
||||||
|
],
|
||||||
|
"require-await": "error",
|
||||||
|
"require-jsdoc": "off",
|
||||||
|
"rest-spread-spacing": "error",
|
||||||
|
"semi": "off",
|
||||||
|
"semi-spacing": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"after": true,
|
||||||
|
"before": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"semi-style": [
|
||||||
|
"error",
|
||||||
|
"last"
|
||||||
|
],
|
||||||
|
"sort-imports": "error",
|
||||||
|
"sort-keys": "off",
|
||||||
|
"sort-vars": "error",
|
||||||
|
"space-before-blocks": "error",
|
||||||
|
"space-before-function-paren": "off",
|
||||||
|
"space-in-parens": "off",
|
||||||
|
"space-infix-ops": "off",
|
||||||
|
"space-unary-ops": "error",
|
||||||
|
"spaced-comment": [
|
||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
|
],
|
||||||
|
"strict": "error",
|
||||||
|
"switch-colon-spacing": "error",
|
||||||
|
"symbol-description": "error",
|
||||||
|
"template-curly-spacing": "error",
|
||||||
|
"template-tag-spacing": "error",
|
||||||
|
"unicode-bom": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"valid-jsdoc": "off",
|
||||||
|
"vars-on-top": "off",
|
||||||
|
"wrap-iife": "error",
|
||||||
|
"wrap-regex": "error",
|
||||||
|
"yield-star-spacing": "error",
|
||||||
|
"yoda": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
1
app.js
1
app.js
@@ -22,7 +22,6 @@ app.use('/users', users);
|
|||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
console.log('[App::use] 404: Not Found', { args: arguments });
|
|
||||||
var err = new Error('Not Found', { args: arguments });
|
var err = new Error('Not Found', { args: arguments });
|
||||||
err.status = 404;
|
err.status = 404;
|
||||||
next(err);
|
next(err);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ const GoogleMaps = require('@google/maps').createClient({
|
|||||||
key: 'AIzaSyCvpBGztvxtRUNigOW9f0GXVRWlukJZsps'
|
key: 'AIzaSyCvpBGztvxtRUNigOW9f0GXVRWlukJZsps'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var logger = require('../modules/logger');
|
||||||
|
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
const GeocacheSchema = new Schema({
|
const GeocacheSchema = new Schema({
|
||||||
@@ -80,7 +82,7 @@ GeocacheSchema.index({ name: 1, loc: '2dsphere' });
|
|||||||
|
|
||||||
const GeocacheModel = mongoose.model('geocache', GeocacheSchema);
|
const GeocacheModel = mongoose.model('geocache', GeocacheSchema);
|
||||||
|
|
||||||
function distanceBetween (geoJSON1, geoJSON2, unit = 'mi') {
|
/*function distanceBetween (geoJSON1, geoJSON2, unit = 'mi') {
|
||||||
var radlat1 = Math.PI * geoJSON1.coordinates[1]/180;
|
var radlat1 = Math.PI * geoJSON1.coordinates[1]/180;
|
||||||
var radlat2 = Math.PI * geoJSON2.coordinates[1]/180;
|
var radlat2 = Math.PI * geoJSON2.coordinates[1]/180;
|
||||||
var theta = geoJSON1.coordinates[0] - geoJSON2.coordinates[0];
|
var theta = geoJSON1.coordinates[0] - geoJSON2.coordinates[0];
|
||||||
@@ -88,12 +90,12 @@ function distanceBetween (geoJSON1, geoJSON2, unit = 'mi') {
|
|||||||
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
|
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
|
||||||
dist = Math.acos(dist);
|
dist = Math.acos(dist);
|
||||||
dist = dist * 180/Math.PI;
|
dist = dist * 180/Math.PI;
|
||||||
dist = dist * 60 * 1.1515; /* miles between */
|
dist = dist * 60 * 1.1515; // miles between
|
||||||
if (unit == "km") { dist = Conversion.metersToKilometers(Conversion.milesToMeters(dist)); }
|
if (unit == "km") { dist = Conversion.metersToKilometers(Conversion.milesToMeters(dist)); }
|
||||||
if (unit == "m") { dist = dist * 1.609344; }
|
if (unit == "m") { dist = dist * 1.609344; }
|
||||||
if (unit == "n") { dist = dist * 0.8684; }
|
if (unit == "n") { dist = dist * 0.8684; }
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
function queryGeodataApi (query, callback) {
|
function queryGeodataApi (query, callback) {
|
||||||
GoogleMaps.geocode({
|
GoogleMaps.geocode({
|
||||||
@@ -123,7 +125,7 @@ function queryGeodataApi (query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeNameForKey (name) {
|
function sanitizeNameForKey (name) {
|
||||||
var key = name.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,'');
|
var key = name.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g,'');
|
||||||
key = key.replace(/\s{2,}/g,' ');
|
key = key.replace(/\s{2,}/g,' ');
|
||||||
key = key.trim();
|
key = key.trim();
|
||||||
key = key.toLowerCase();
|
key = key.toLowerCase();
|
||||||
@@ -317,8 +319,10 @@ module.exports = {
|
|||||||
let geocacheInstance = new GeocacheModel(geodata);
|
let geocacheInstance = new GeocacheModel(geodata);
|
||||||
geocacheInstance.save((err, result) => {
|
geocacheInstance.save((err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('[Geocache::getGeoJSON] There was an error creating the GeoJSON entry.', { err: err });
|
logger.error('[Geocache::getGeoJSON] There was an error creating the GeoJSON entry.', { err: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug()
|
||||||
});
|
});
|
||||||
resolve(geodata.loc);
|
resolve(geodata.loc);
|
||||||
}
|
}
|
||||||
@@ -350,8 +354,8 @@ module.exports = {
|
|||||||
if (!results[i].formatted) {
|
if (!results[i].formatted) {
|
||||||
results[i].formatted = results[i].georesult.formatted_address;
|
results[i].formatted = results[i].georesult.formatted_address;
|
||||||
GeocacheModel.findByIdAndUpdate(results[i]._id, { $set: results[i] }, (err, result) => {
|
GeocacheModel.findByIdAndUpdate(results[i]._id, { $set: results[i] }, (err, result) => {
|
||||||
if (err) console.error('There was an error populating the geocache formatted address.');
|
if (err) logger.error('There was an error populating the geocache formatted address.');
|
||||||
if (result) console.log('The geocache entry was updated');
|
if (result) logger.log('The geocache entry was updated');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,8 +386,8 @@ module.exports = {
|
|||||||
if (!results[i].key) {
|
if (!results[i].key) {
|
||||||
results[i].key = sanitizeNameForKey(results[i].name);
|
results[i].key = sanitizeNameForKey(results[i].name);
|
||||||
GeocacheModel.findByIdAndUpdate(results[i]._id, { $set: results[i] }, (err, result) => {
|
GeocacheModel.findByIdAndUpdate(results[i]._id, { $set: results[i] }, (err, result) => {
|
||||||
if (err) console.error('There was an error populating the geocache entry key.');
|
if (err) logger.error('There was an error populating the geocache entry key.');
|
||||||
if (result) console.log('The geocache entry was updated');
|
if (result) logger.log('The geocache entry was updated');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const Token = require('../modules/token');
|
|||||||
|
|
||||||
const secret = 'Creepily hooking the gays up since 2008!';
|
const secret = 'Creepily hooking the gays up since 2008!';
|
||||||
|
|
||||||
|
var logger = require('../modules/logger');
|
||||||
|
|
||||||
function generateHmac (userId, expires) {
|
function generateHmac (userId, expires) {
|
||||||
var string = String(userId) + '|' + String(expires);
|
var string = String(userId) + '|' + String(expires);
|
||||||
return Crypto.createHmac('sha1', secret).update(string).digest('hex');
|
return Crypto.createHmac('sha1', secret).update(string).digest('hex');
|
||||||
@@ -25,10 +27,10 @@ function sendMail (options, callback) {
|
|||||||
|
|
||||||
callback = typeof callback === 'function' ? callback : (error, info) => {
|
callback = typeof callback === 'function' ? callback : (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return console.log(error);
|
return logger.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Message %s sent: %s', info.messageId, info.response);
|
logger.debug('Message %s sent: %s', info.messageId, info.response);
|
||||||
};
|
};
|
||||||
|
|
||||||
// send mail with defined transport object
|
// send mail with defined transport object
|
||||||
@@ -110,18 +112,18 @@ module.exports = {
|
|||||||
|
|
||||||
sendMail(mail, (error, info) => {
|
sendMail(mail, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('[reset::forceReset] Message Send Error', { error: error });
|
logger.debug('[reset::forceReset] Message Send Error', { error: error });
|
||||||
forceResetMailResolve({ success: false, message: 'There was an error sending the message', error: error });
|
forceResetMailResolve({ success: false, message: 'There was an error sending the message', error: error });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
console.log('[reset::forceReset] Message sent', { messageId: info.messageId, response: info.response, resetLink: resetLink });
|
logger.debug('[reset::forceReset] Message sent', { messageId: info.messageId, response: info.response, resetLink: resetLink });
|
||||||
forceResetMailResolve({ success: true, message: 'Message ' + info.messageId + ' sent: ' + info.response + '.' });
|
forceResetMailResolve({ success: true, message: 'Message ' + info.messageId + ' sent: ' + info.response + '.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('[reset::forceReset] There was an error creating the reset token.', { err: err });
|
logger.debug('[reset::forceReset] There was an error creating the reset token.', { err: err });
|
||||||
forceResetMailReject(err);
|
forceResetMailReject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -184,14 +186,14 @@ module.exports = {
|
|||||||
if (e) {
|
if (e) {
|
||||||
e.emit('markUsed', null, result);
|
e.emit('markUsed', null, result);
|
||||||
} else {
|
} else {
|
||||||
console.log('[ResetModel::markUsed] Password reset token used', { token: result });
|
logger.debug('[ResetModel::markUsed] Password reset token used', { token: result });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.emit('markUsed', err, null);
|
e.emit('markUsed', err, null);
|
||||||
} else {
|
} else {
|
||||||
console.error('[ResetModel::markUsed] Error marking password reset token used', { token: err });
|
logger.error('[ResetModel::markUsed] Error marking password reset token used', { token: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -226,18 +228,18 @@ module.exports = {
|
|||||||
|
|
||||||
sendMail(mail, (error, info) => {
|
sendMail(mail, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('[reset::sendNewUser] Message Send Error', { error: error });
|
logger.error('[reset::sendNewUser] Message Send Error', { error: error });
|
||||||
newUserMailResolve({ success: false, message: 'There was an error sending the message', error: error });
|
newUserMailResolve({ success: false, message: 'There was an error sending the message', error: error });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
console.log('[reset::sendNewUser] Message %s sent: %s', info.messageId, info.response);
|
logger.debug('[reset::sendNewUser] Message %s sent: %s', info.messageId, info.response);
|
||||||
newUserMailResolve({ success: true, message: 'Message ' + info.messageId + ' sent: ' + info.response + '.' });
|
newUserMailResolve({ success: true, message: 'Message ' + info.messageId + ' sent: ' + info.response + '.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('[reset::sendNewUser] There was an error creating the reset token.', { err: err });
|
logger.error('[reset::sendNewUser] There was an error creating the reset token.', { err: err });
|
||||||
newUserMailReject(err);
|
newUserMailReject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -295,13 +297,13 @@ module.exports = {
|
|||||||
sendMail(mail, (err, info) => {
|
sendMail(mail, (err, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
var error = { msg: '[reset::sendReset] There was an error sending the reset email.', err: err };
|
var error = { msg: '[reset::sendReset] There was an error sending the reset email.', err: err };
|
||||||
console.log('[reset::sendReset] Message Send Error', { err: err });
|
logger.error('[reset::sendReset] Message Send Error', { err: err });
|
||||||
sendMailResolve({ success: false, message: 'There was an error requesting the password reset.', error: error });
|
sendMailResolve({ success: false, message: 'There was an error requesting the password reset.', error: error });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
var message = 'Message ' + info.messageId + ' sent: ' + info.response + '.';
|
var message = 'Message ' + info.messageId + ' sent: ' + info.response + '.';
|
||||||
console.log('[reset::sendReset] ' + message);
|
logger.debug('[reset::sendReset] ' + message);
|
||||||
sendMailResolve({ success: true, message: 'The password reset request was successfully completed.', response: message });
|
sendMailResolve({ success: true, message: 'The password reset request was successfully completed.', response: message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -316,7 +318,7 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
var error = { msg: '[reset::sendReset] There was an error creating the reset token.', err: err };
|
var error = { msg: '[reset::sendReset] There was an error creating the reset token.', err: err };
|
||||||
console.log(error.msg, { err: err });
|
logger.debug(error.msg, { err: err });
|
||||||
e.emit('sendReset', null, { success: false, message: 'There was an error requesting the password reset.', error: error });
|
e.emit('sendReset', null, { success: false, message: 'There was an error requesting the password reset.', error: error });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,13 +68,15 @@ UserSchema.post('save', function (err, res, next) {
|
|||||||
|
|
||||||
const UserModel = Mongoose.model('users', UserSchema);
|
const UserModel = Mongoose.model('users', UserSchema);
|
||||||
|
|
||||||
|
var logger = require('../modules/logger');
|
||||||
|
|
||||||
function hashPassword (password, callback) {
|
function hashPassword (password, callback) {
|
||||||
callback = callback || false;
|
callback = callback || false;
|
||||||
|
|
||||||
Authentication.hashPassword(password, (err, password) => {
|
Authentication.hashPassword(password, (err, password) => {
|
||||||
if (err !== null) {
|
if (err !== null) {
|
||||||
err = new Error({ success: false, message: 'There was an error hashing the updated password.', err: err });
|
err = new Error({ success: false, message: 'There was an error hashing the updated password.', err: err });
|
||||||
console.error('[updateUser:hashPassword] ', err);
|
logger.error('[updateUser:hashPassword] ', err);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
@@ -101,7 +103,7 @@ function confirmPassword (username, passwordToValidate, callback) {
|
|||||||
UserModel.findById({ userName: username }, (err, user) => {
|
UserModel.findById({ userName: username }, (err, user) => {
|
||||||
if (err !== null) {
|
if (err !== null) {
|
||||||
err = new Error({ success: false, message: 'There was an error locating the user.', err: (err || null) });
|
err = new Error({ success: false, message: 'There was an error locating the user.', err: (err || null) });
|
||||||
console.error('[updateUser:confirmPassword] ', err);
|
logger.error('[updateUser:confirmPassword] ', err);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
@@ -114,7 +116,7 @@ function confirmPassword (username, passwordToValidate, callback) {
|
|||||||
Authentication.verifyPassword(passwordToValidate, Buffer.from(storedUser.password, 'hex'), (err, valid) => {
|
Authentication.verifyPassword(passwordToValidate, Buffer.from(storedUser.password, 'hex'), (err, valid) => {
|
||||||
if (err !== null || !valid) {
|
if (err !== null || !valid) {
|
||||||
err = new Error({ success: false, message: (!err && !valid ? 'The current password was incorrect.' : 'There was an error attempting to validate the password.'), err: (err || null) });
|
err = new Error({ success: false, message: (!err && !valid ? 'The current password was incorrect.' : 'There was an error attempting to validate the password.'), err: (err || null) });
|
||||||
console.error('[updateUser:confirmPassword] ', { err: err, valid: valid });
|
logger.error('[updateUser:confirmPassword] ', { err: err, valid: valid });
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
@@ -183,7 +185,7 @@ module.exports = {
|
|||||||
string: 'There was an error authenticating the user.'
|
string: 'There was an error authenticating the user.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('[UserModel::authenticateUser] Error finding user', { err: err, username: login.userName });
|
logger.debug('[UserModel::authenticateUser] Error finding user', { err: err, username: login.userName });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +209,7 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
Authentication.verifyPassword(login.password, Buffer.from(user.password, 'hex'), (err, valid) => {
|
Authentication.verifyPassword(login.password, Buffer.from(user.password, 'hex'), (err, valid) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('[UserModel::authenticateUser] Error validating password', { err: err, user: user });
|
logger.debug('[UserModel::authenticateUser] Error validating password', { err: err, user: user });
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +233,7 @@ module.exports = {
|
|||||||
|
|
||||||
loginObject.timestamp = Date.now();
|
loginObject.timestamp = Date.now();
|
||||||
|
|
||||||
console.log('[UserModel::authenticateUser] User Validated', { user: user, loginObject: loginObject });
|
logger.debug('[UserModel::authenticateUser] User Validated', { user: user, loginObject: loginObject });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
} else {
|
} else {
|
||||||
loginObject.err = {
|
loginObject.err = {
|
||||||
@@ -240,7 +242,7 @@ module.exports = {
|
|||||||
string: 'The user id or password you entered was invalid.'
|
string: 'The user id or password you entered was invalid.'
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[UserModel::authenticateUser] Invalid Password', { user: user, loginObject: loginObject });
|
logger.debug('[UserModel::authenticateUser] Invalid Password', { user: user, loginObject: loginObject });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -256,7 +258,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[UserModel::authenticateUser] Error verifying password', { err: err, user: user });
|
logger.error('[UserModel::authenticateUser] Error verifying password', { err: err, user: user });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +273,7 @@ module.exports = {
|
|||||||
string: 'The user is not authorized, please contact an administrator.'
|
string: 'The user is not authorized, please contact an administrator.'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('[UserModel::authenticateUser] The user is disabled', { err: err, user: user });
|
logger.debug('[UserModel::authenticateUser] The user is disabled', { err: err, user: user });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -284,7 +286,7 @@ module.exports = {
|
|||||||
string: 'The user id or password you entered was invalid.'
|
string: 'The user id or password you entered was invalid.'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('[UserModel::authenticateUser] The user does not exist', { err: err, user: user });
|
logger.debug('[UserModel::authenticateUser] The user does not exist', { err: err, user: user });
|
||||||
resolve(loginObject);
|
resolve(loginObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,7 +306,7 @@ module.exports = {
|
|||||||
var userInstance = new UserModel(user);
|
var userInstance = new UserModel(user);
|
||||||
|
|
||||||
userInstance.save((err, result) => {
|
userInstance.save((err, result) => {
|
||||||
console.log('createUser', { err: err, result: result, user: userInstance });
|
logger.debug('createUser', { err: err, result: result, user: userInstance });
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
|||||||
22
modules/logger.js
Normal file
22
modules/logger.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const winston = require('winston');
|
||||||
|
|
||||||
|
var logger = new (winston.Logger)({
|
||||||
|
transports: [
|
||||||
|
new (winston.transports.File)({
|
||||||
|
name: 'debug-file',
|
||||||
|
filename: 'urge-debug.log',
|
||||||
|
handleExceptions: true,
|
||||||
|
humanReadableUnhandledException: true,
|
||||||
|
level: 'debug'
|
||||||
|
}),
|
||||||
|
new (winston.transports.File)({
|
||||||
|
name: 'error-file',
|
||||||
|
filename: 'urge-error.log',
|
||||||
|
handleExceptions: true,
|
||||||
|
humanReadableUnhandledException: true,
|
||||||
|
level: 'error'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = logger;
|
||||||
@@ -12,6 +12,8 @@ const Token = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var logger = require('../modules/logger');
|
||||||
|
|
||||||
function createAnonymousToken (e) {
|
function createAnonymousToken (e) {
|
||||||
Token.create({ user: null, permission: 0 }, (err, token) => {
|
Token.create({ user: null, permission: 0 }, (err, token) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -105,20 +107,17 @@ function verifyTokenAndUserThen (token, minimumPermission, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function verifyTokenAndRoleThen (token, action, callback, log = false) {
|
function verifyTokenAndRoleThen (token, action, callback, log = false) {
|
||||||
if (log) console.log('verifyTokenAndRoleThen', { token: token, action: action });
|
logger.debug('verifyTokenAndRoleThen', { token: token, action: action });
|
||||||
validateToken(null, token, (err, decoded) => {
|
validateToken(null, token, (err, decoded) => {
|
||||||
if (log) console.log('verifyTokenAndRoleThen::validateToken', { err: err, decoded: decoded.data });
|
logger.debug('verifyTokenAndRoleThen::validateToken', { err: err, decoded: decoded.data });
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
callback('Session could not be validated.', null);
|
callback('Session could not be validated.', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
let [initial, canElevateTo = false] = Array.isArray(action) ? action : [ action ];
|
let [initial, canElevateTo = false] = Array.isArray(action) ? action : [ action ];
|
||||||
|
logger.debug('Roles.canRole[' + initial + ']', Roles.canRole(null, decoded.data.permission, initial));
|
||||||
if (log) {
|
logger.debug('Roles.canRole[' + canElevateTo + ']', Roles.canRole(null, decoded.data.permission, canElevateTo));
|
||||||
console.log('Roles.canRole[' + initial + ']', Roles.canRole(null, decoded.data.permission, initial));
|
|
||||||
console.log('Roles.canRole[' + canElevateTo + ']', Roles.canRole(null, decoded.data.permission, canElevateTo));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decoded && decoded.valid) {
|
if (decoded && decoded.valid) {
|
||||||
Roles.canRole(null, decoded.data.permission, action, (err, result) => {
|
Roles.canRole(null, decoded.data.permission, action, (err, result) => {
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
"multer": "^1.2.0",
|
"multer": "^1.2.0",
|
||||||
"nodemailer": "~4.0.1",
|
"nodemailer": "~4.0.1",
|
||||||
"shortid": "~2.2.8",
|
"shortid": "~2.2.8",
|
||||||
"vcard-js": "^1.2.2"
|
"vcard-js": "^1.2.2",
|
||||||
|
"winston": "^2.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
|||||||
@@ -1,8 +1,41 @@
|
|||||||
var EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
var Express = require('express');
|
const Express = require('express');
|
||||||
var Profiles = require('../models/profile');
|
const ParamStr = '/:limit?/:skip?/:min?/:max?/:pos?/:lkng?/:tribes?/:ethnos?';
|
||||||
var Router = Express.Router();
|
const Profiles = require('../models/profile');
|
||||||
var Token = require('../modules/token');
|
const Router = Express.Router();
|
||||||
|
const Token = require('../modules/token');
|
||||||
|
|
||||||
|
function processQueryParams (params) {
|
||||||
|
var query = {};
|
||||||
|
|
||||||
|
if (params.minAge && !isNaN(parseInt(params.minAge))) {
|
||||||
|
query['details.age'] = query['details.age'] || {};
|
||||||
|
query['details.age'].$gte = parseInt(params.minAge);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.maxAge && !isNaN(parseInt(params.maxAge))) {
|
||||||
|
query['details.age'] = query['details.age'] || {};
|
||||||
|
query['details.age'].$lte = parseInt(params.maxAge);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.pos && params.pos !== 'null') {
|
||||||
|
query['details.position'] = { $in: params.pos.split('|') };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.lkng && params.lkng !== 'null') {
|
||||||
|
query['details.looking'] = { $in: params.lkng.split('|') };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.tribes && params.tribes !== 'null') {
|
||||||
|
query['details.tribes'] = { $in: params.tribes.split('|') };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.ethnos && params.ethnos !== 'null') {
|
||||||
|
query['details.ethnos'] = { $in: params.ethnos.split('|') };
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
function update (req, res, next) {
|
function update (req, res, next) {
|
||||||
Token.verifyThen(req.get('authorization'), 'edit', (err, decoded) => {
|
Token.verifyThen(req.get('authorization'), 'edit', (err, decoded) => {
|
||||||
@@ -91,7 +124,7 @@ Router.route('/')
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.route('/find/:limit?/:skip?/:min?/:max?/:pos?/:lkng?/:tribes?/:ethnos?')
|
Router.route('/find' + ParamStr)
|
||||||
.get((req, res) => {
|
.get((req, res) => {
|
||||||
Token.verifyThen(req.get('authorization'), 'view', (err, decoded) => {
|
Token.verifyThen(req.get('authorization'), 'view', (err, decoded) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -106,8 +139,8 @@ Router.route('/find/:limit?/:skip?/:min?/:max?/:pos?/:lkng?/:tribes?/:ethnos?')
|
|||||||
find: find,
|
find: find,
|
||||||
select: null,
|
select: null,
|
||||||
options: {
|
options: {
|
||||||
limit: 0,
|
limit: !isNaN(parseInt(req.params.limit)) ? parseInt(req.params.limit) : 0,
|
||||||
skip: 0,
|
skip: !isNaN(parseInt(req.params.skip)) ? parseInt(req.params.skip) : 0,
|
||||||
sort: { 'order': 1 }
|
sort: { 'order': 1 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -126,7 +159,7 @@ Router.route('/find/:limit?/:skip?/:min?/:max?/:pos?/:lkng?/:tribes?/:ethnos?')
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.route('/list/:limit?/:skip?/:min?/:max?/:pos?/:lkng?/:tribes?/:ethnos?')
|
Router.route('/list' + ParamStr)
|
||||||
.get((req, res) => {
|
.get((req, res) => {
|
||||||
Token.verifyThen(req.get('authorization'), 'view', (err, decoded) => {
|
Token.verifyThen(req.get('authorization'), 'view', (err, decoded) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user