mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-05 10:37:30 +02:00
Merge commit 'b43c80e2c097b11114f4e4f01b9718321721a89b'
* commit 'b43c80e2c097b11114f4e4f01b9718321721a89b': feat(build): Update dependencies (#1847) fix(travis): Fix Travis failing on webdriver issues (#1845) fix(eslint): Inconsistent spacing before function parentheses (#1844) fix(mongodb): update ssl connection settings (#1809) Remove deprecated crypto package (#1843) feat(config): Mongo Seed 2.0 (#1808) fix(users): don't fail on missing old image on image upload (#1839) feat(build): Turn on mangling for uglify (#1841) fix(gulp): fix broken test:server:watch task (#1842) feat(core): Enhancement page title directive (#1686) feat(user): Add email support to forgot password (#1834) fix(mocha): update mochajs version to reduce vulnerabilities (#1830) refactor(menus): Refactor to the Menus client service to use functional loops/filters (#1575) feat(config): Mongoose 4.11 upgrade (#1818) # Conflicts: # config/env/development.js # config/lib/app.js # modules/articles/server/models/article.server.model.js # modules/chat/client/config/chat.client.routes.js # modules/core/client/directives/page-title.client.directive.js # modules/core/client/services/menu.client.service.js # modules/users/client/config/users-admin.client.routes.js # modules/users/client/views/password/forgot-password.client.view.html # modules/users/server/models/user.server.model.js # package.json
This commit is contained in:
@@ -11,7 +11,8 @@ var mongoose = require('mongoose'),
|
||||
validator = require('validator'),
|
||||
generatePassword = require('generate-password'),
|
||||
owasp = require('owasp-password-strength-test'),
|
||||
moment = require('moment');
|
||||
moment = require('moment'),
|
||||
chalk = require('chalk');
|
||||
|
||||
owasp.config(config.shared.owasp);
|
||||
|
||||
@@ -424,4 +425,92 @@ UserSchema.statics.generateRandomPassphrase = function () {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.seed = seed;
|
||||
|
||||
mongoose.model('User', UserSchema);
|
||||
|
||||
/**
|
||||
* Seeds the User collection with document (User)
|
||||
* and provided options.
|
||||
*/
|
||||
function seed(doc, options) {
|
||||
var User = mongoose.model('User');
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
skipDocument()
|
||||
.then(add)
|
||||
.then(function (response) {
|
||||
return resolve(response);
|
||||
})
|
||||
.catch(function (err) {
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
function skipDocument() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
User
|
||||
.findOne({
|
||||
username: doc.username
|
||||
})
|
||||
.exec(function (err, existing) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
if (!existing) {
|
||||
return resolve(false);
|
||||
}
|
||||
|
||||
if (existing && !options.overwrite) {
|
||||
return resolve(true);
|
||||
}
|
||||
|
||||
// Remove User (overwrite)
|
||||
|
||||
existing.remove(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function add(skip) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (skip) {
|
||||
return resolve({
|
||||
message: chalk.yellow('Database Seeding: User\t\t' + doc.username + ' skipped')
|
||||
});
|
||||
}
|
||||
|
||||
User.generateRandomPassphrase()
|
||||
.then(function (passphrase) {
|
||||
var user = new User(doc);
|
||||
|
||||
user.provider = 'local';
|
||||
user.displayName = user.firstName + ' ' + user.lastName;
|
||||
user.password = passphrase;
|
||||
|
||||
user.save(function (err) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
return resolve({
|
||||
message: 'Database Seeding: User\t\t' + user.username + ' added with password set to ' + passphrase
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user