2017-12-12 18:21:20 +01:00
|
|
|
// load dependencies
|
|
|
|
const logger = require('winston');
|
2018-02-02 23:24:46 +01:00
|
|
|
const db = require('../models'); // require our models for syncing
|
2017-12-12 19:51:29 +01:00
|
|
|
// configure logging
|
2017-12-13 00:35:46 +01:00
|
|
|
const config = require('../config/speechConfig.js');
|
2017-12-16 18:55:29 +01:00
|
|
|
const { logLevel } = config.logging;
|
2017-12-13 00:35:46 +01:00
|
|
|
require('../config/loggerConfig.js')(logger, logLevel);
|
2017-12-12 18:21:20 +01:00
|
|
|
|
|
|
|
const userName = process.argv[2];
|
|
|
|
logger.debug('user name:', userName);
|
|
|
|
const oldPassword = process.argv[3];
|
|
|
|
logger.debug('old password:', oldPassword);
|
|
|
|
const newPassword = process.argv[4];
|
|
|
|
logger.debug('new password:', newPassword);
|
|
|
|
|
|
|
|
db.sequelize.sync() // sync sequelize
|
|
|
|
.then(() => {
|
|
|
|
logger.info('finding user profile');
|
|
|
|
return db.User.findOne({
|
|
|
|
where: {
|
|
|
|
userName: userName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(user => {
|
|
|
|
if (!user) {
|
|
|
|
throw new Error('no user found');
|
|
|
|
}
|
2017-12-12 19:51:29 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
user.comparePassword(oldPassword, (passwordErr, isMatch) => {
|
|
|
|
if (passwordErr) {
|
|
|
|
return reject(passwordErr);
|
|
|
|
}
|
|
|
|
if (!isMatch) {
|
|
|
|
return reject('Incorrect old password.');
|
|
|
|
}
|
|
|
|
logger.debug('Password was a match, updating password');
|
|
|
|
return resolve(user.changePassword(newPassword));
|
|
|
|
});
|
2017-12-12 18:21:20 +01:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
logger.debug('Password successfully updated');
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2017-12-12 19:51:29 +01:00
|
|
|
logger.error(error);
|
2017-12-12 18:21:20 +01:00
|
|
|
});
|