wrapped comparePassword in a promise
This commit is contained in:
parent
c7ad52216d
commit
b7a38dd099
1 changed files with 16 additions and 10 deletions
|
@ -1,6 +1,10 @@
|
||||||
// load dependencies
|
// load dependencies
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const db = require('./models'); // require our models for syncing
|
const db = require('./models'); // require our models for syncing
|
||||||
|
// configure logging
|
||||||
|
const config = require('./config/speechConfig.js');
|
||||||
|
const logLevel = config.logging.logLevel;
|
||||||
|
require('./config/loggerConfig.js')(logger, logLevel);
|
||||||
|
|
||||||
const userName = process.argv[2];
|
const userName = process.argv[2];
|
||||||
logger.debug('user name:', userName);
|
logger.debug('user name:', userName);
|
||||||
|
@ -22,20 +26,22 @@ db.sequelize.sync() // sync sequelize
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error('no user found');
|
throw new Error('no user found');
|
||||||
}
|
}
|
||||||
return user.comparePassword(oldPassword, (passwordErr, isMatch) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (passwordErr) {
|
user.comparePassword(oldPassword, (passwordErr, isMatch) => {
|
||||||
throw passwordErr;
|
if (passwordErr) {
|
||||||
}
|
return reject(passwordErr);
|
||||||
if (!isMatch) {
|
}
|
||||||
throw new Error('Incorrect old password.');
|
if (!isMatch) {
|
||||||
}
|
return reject('Incorrect old password.');
|
||||||
logger.debug('Password was a match, updating password');
|
}
|
||||||
return user.changePassword(newPassword);
|
logger.debug('Password was a match, updating password');
|
||||||
|
return resolve(user.changePassword(newPassword));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger.debug('Password successfully updated');
|
logger.debug('Password successfully updated');
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error('error:', error);
|
logger.error(error);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue