1
0
ohmyform/scripts/create_admin.js
wodka f7b1dd05e9 fix analytics
upgrade missing dependencies
upgrade libraries
change service naming
2019-07-15 10:15:06 +02:00

48 lines
1.0 KiB
JavaScript

var config = require('../config/config'),
mongoose = require('mongoose'),
chalk = require('chalk');
exports.run = function(app, db, cb) {
console.log(chalk.green('Creating the Admin Account'));
var User = mongoose.model('User');
var email = config.admin.email || 'admin@admin.com';
var newUserObj = {
firstName: 'Admin',
lastName: 'Account',
email: email,
username: config.admin.username || 'root',
password: config.admin.password || 'root',
provider: 'local',
roles: ['admin', 'user']
};
var options = {
upsert: true,
new: true,
setDefaultsOnInsert: true
};
User.findOneAndUpdate({username: newUserObj.username}, newUserObj, options, function (err, currUser1) {
if (err) {
return cb(err);
}
if(!currUser1){
return cb(new Error('Couldn\'t create admin account'));
} else {
currUser1.password = config.admin.password;
currUser1.save(function(err, currUser2){
if (err) {
return cb(err);
}
console.log(chalk.green('Successfully created/updated Admin Account'));
return cb();
});
}
});
};