Standard JS code conversion + fixes

This commit is contained in:
NGPixel
2017-02-08 20:52:37 -05:00
parent a508b2a7f4
commit 414dc386d6
54 changed files with 4022 additions and 4288 deletions

View File

@@ -1,4 +1,4 @@
"use strict";
'use strict'
/**
* BruteForce schema
@@ -6,13 +6,13 @@
* @type {<Mongoose.Schema>}
*/
var bruteForceSchema = Mongoose.Schema({
_id: { type: String, index: 1 },
data: {
count: Number,
lastRequest: Date,
firstRequest: Date
},
expires: { type: Date, index: { expires: '1d' } }
});
_id: { type: String, index: 1 },
data: {
count: Number,
lastRequest: Date,
firstRequest: Date
},
expires: { type: Date, index: { expires: '1d' } }
})
module.exports = Mongoose.model('Bruteforce', bruteForceSchema);
module.exports = Mongoose.model('Bruteforce', bruteForceSchema)

View File

@@ -1,7 +1,4 @@
"use strict";
const Promise = require('bluebird'),
_ = require('lodash');
'use strict'
/**
* Entry schema
@@ -10,7 +7,7 @@ const Promise = require('bluebird'),
*/
var entrySchema = Mongoose.Schema({
_id: String,
_id: String,
title: {
type: String,
@@ -31,9 +28,9 @@ var entrySchema = Mongoose.Schema({
}
},
{
timestamps: {}
});
{
timestamps: {}
})
entrySchema.index({
_id: 'text',
@@ -48,6 +45,6 @@ entrySchema.index({
content: 1
},
name: 'EntriesTextIndex'
});
})
module.exports = Mongoose.model('Entry', entrySchema);
module.exports = Mongoose.model('Entry', entrySchema)

View File

@@ -1,7 +1,4 @@
"use strict";
const Promise = require('bluebird'),
_ = require('lodash');
'use strict'
/**
* Upload File schema
@@ -10,7 +7,7 @@ const Promise = require('bluebird'),
*/
var uplFileSchema = Mongoose.Schema({
_id: String,
_id: String,
category: {
type: String,
@@ -42,9 +39,6 @@ var uplFileSchema = Mongoose.Schema({
required: true
}
},
{
timestamps: {}
});
}, { timestamps: {} })
module.exports = Mongoose.model('UplFile', uplFileSchema);
module.exports = Mongoose.model('UplFile', uplFileSchema)

View File

@@ -1,7 +1,4 @@
"use strict";
const Promise = require('bluebird'),
_ = require('lodash');
'use strict'
/**
* Upload Folder schema
@@ -10,16 +7,13 @@ const Promise = require('bluebird'),
*/
var uplFolderSchema = Mongoose.Schema({
_id: String,
_id: String,
name: {
type: String,
index: true
}
},
{
timestamps: {}
});
}, { timestamps: {} })
module.exports = Mongoose.model('UplFolder', uplFolderSchema);
module.exports = Mongoose.model('UplFolder', uplFolderSchema)

View File

@@ -1,8 +1,8 @@
"use strict";
'use strict'
const Promise = require('bluebird'),
bcrypt = require('bcryptjs-then'),
_ = require('lodash');
const Promise = require('bluebird')
const bcrypt = require('bcryptjs-then')
const _ = require('lodash')
/**
* Region schema
@@ -11,78 +11,73 @@ const Promise = require('bluebird'),
*/
var userSchema = Mongoose.Schema({
email: {
type: String,
required: true,
index: true
},
email: {
type: String,
required: true,
index: true
},
provider: {
type: String,
required: true
},
provider: {
type: String,
required: true
},
providerId: {
type: String
},
providerId: {
type: String
},
password: {
type: String
},
password: {
type: String
},
name: {
type: String
},
name: {
type: String
},
rights: [{
role: String,
path: String,
exact: Boolean,
deny: Boolean
}]
rights: [{
role: String,
path: String,
exact: Boolean,
deny: Boolean
}]
},
{
timestamps: {}
});
}, { timestamps: {} })
userSchema.statics.processProfile = (profile) => {
let primaryEmail = ''
if (_.isArray(profile.emails)) {
let e = _.find(profile.emails, ['primary', true])
primaryEmail = (e) ? e.value : _.first(profile.emails).value
} else if (_.isString(profile.email) && profile.email.length > 5) {
primaryEmail = profile.email
} else {
return Promise.reject(new Error('Invalid User Email'))
}
let primaryEmail = '';
if(_.isArray(profile.emails)) {
let e = _.find(profile.emails, ['primary', true]);
primaryEmail = (e) ? e.value : _.first(profile.emails).value;
} else if(_.isString(profile.email) && profile.email.length > 5) {
primaryEmail = profile.email;
} else {
return Promise.reject(new Error('Invalid User Email'));
}
return db.User.findOneAndUpdate({
email: primaryEmail,
provider: profile.provider
}, {
email: primaryEmail,
provider: profile.provider,
providerId: profile.id,
name: profile.displayName || _.split(primaryEmail, '@')[0]
}, {
new: true,
upsert: true
}).then((user) => {
return (user) ? user : Promise.reject(new Error('User Upsert failed.'));
});
};
return db.User.findOneAndUpdate({
email: primaryEmail,
provider: profile.provider
}, {
email: primaryEmail,
provider: profile.provider,
providerId: profile.id,
name: profile.displayName || _.split(primaryEmail, '@')[0]
}, {
new: true,
upsert: true
}).then((user) => {
return user || Promise.reject(new Error('User Upsert failed.'))
})
}
userSchema.statics.hashPassword = (rawPwd) => {
return bcrypt.hash(rawPwd);
};
return bcrypt.hash(rawPwd)
}
userSchema.methods.validatePassword = function(rawPwd) {
return bcrypt.compare(rawPwd, this.password).then((isValid) => {
return (isValid) ? true : Promise.reject(new Error('Invalid Login'));
});
};
userSchema.methods.validatePassword = function (rawPwd) {
return bcrypt.compare(rawPwd, this.password).then((isValid) => {
return (isValid) ? true : Promise.reject(new Error('Invalid Login'))
})
}
module.exports = Mongoose.model('User', userSchema);
module.exports = Mongoose.model('User', userSchema)