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
|
||||
const logger = require('winston');
|
||||
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];
|
||||
logger.debug('user name:', userName);
|
||||
|
@ -22,20 +26,22 @@ db.sequelize.sync() // sync sequelize
|
|||
if (!user) {
|
||||
throw new Error('no user found');
|
||||
}
|
||||
return user.comparePassword(oldPassword, (passwordErr, isMatch) => {
|
||||
if (passwordErr) {
|
||||
throw passwordErr;
|
||||
}
|
||||
if (!isMatch) {
|
||||
throw new Error('Incorrect old password.');
|
||||
}
|
||||
logger.debug('Password was a match, updating password');
|
||||
return user.changePassword(newPassword);
|
||||
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));
|
||||
});
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
logger.debug('Password successfully updated');
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error('error:', error);
|
||||
logger.error(error);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue