feat : New transaction password can't be old trans password and current login password.
chore: add message format.
This commit is contained in:
@@ -244,6 +244,24 @@ async function setTransPassword(req, res) {
|
|||||||
const user = await authService.findUserByCustomerNo(customerNo);
|
const user = await authService.findUserByCustomerNo(customerNo);
|
||||||
if (!user) return res.status(404).json({ error: 'USER_NOT_FOUND' });
|
if (!user) return res.status(404).json({ error: 'USER_NOT_FOUND' });
|
||||||
const { transaction_password } = req.body;
|
const { transaction_password } = req.body;
|
||||||
|
// if (user.transaction_password) {
|
||||||
|
// const isMatchWithOldPassword = await comparePassword(
|
||||||
|
// transaction_password,
|
||||||
|
// user.transaction_password
|
||||||
|
// );
|
||||||
|
// if (isMatchWithOldPassword)
|
||||||
|
// return res.status(500).json({
|
||||||
|
// error: 'New transaction Password will be different from Previous Password',
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
const isMatchWithLoginPassword = await comparePassword(
|
||||||
|
transaction_password,
|
||||||
|
user.password_hash
|
||||||
|
);
|
||||||
|
if (isMatchWithLoginPassword)
|
||||||
|
return res.status(500).json({
|
||||||
|
error: 'New transaction Password will be different from Login Password',
|
||||||
|
});
|
||||||
authService.setTransactionPassword(customerNo, transaction_password);
|
authService.setTransactionPassword(customerNo, transaction_password);
|
||||||
return res.json({ message: 'Transaction Password set' });
|
return res.json({ message: 'Transaction Password set' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -308,6 +326,14 @@ async function changeTransPassword(req, res) {
|
|||||||
error:
|
error:
|
||||||
'New Transaction Password will be different from Previous Transaction Password',
|
'New Transaction Password will be different from Previous Transaction Password',
|
||||||
});
|
});
|
||||||
|
const isMatchWithLoginPassword = await comparePassword(
|
||||||
|
newTPsw,
|
||||||
|
user.password_hash
|
||||||
|
);
|
||||||
|
if (isMatchWithLoginPassword)
|
||||||
|
return res.status(500).json({
|
||||||
|
error: 'New transaction Password will be different from Login Password',
|
||||||
|
});
|
||||||
authService.changeTransPassword(customerNo, newTPsw);
|
authService.changeTransPassword(customerNo, newTPsw);
|
||||||
return res.json({
|
return res.json({
|
||||||
message: 'New Transaction Password changed successfully',
|
message: 'New Transaction Password changed successfully',
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ async function SendOtp(req, res) {
|
|||||||
case 'TLIMIT_SET':
|
case 'TLIMIT_SET':
|
||||||
message = templates.TLIMIT_SET(amount);
|
message = templates.TLIMIT_SET(amount);
|
||||||
break;
|
break;
|
||||||
|
case 'LPWORD_CHANGE':
|
||||||
|
message = templates.LPWORD_CHANGE;
|
||||||
|
break;
|
||||||
|
case 'TPWORD_CHANGE':
|
||||||
|
message = templates.TPWORD_CHANGE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return res.status(400).json({ error: 'Invalid OTP type' });
|
return res.status(400).json({ error: 'Invalid OTP type' });
|
||||||
}
|
}
|
||||||
@@ -194,6 +200,7 @@ async function sendForSetPassword(req, res) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await setJson(`otp:${mobileNumber}`, otp, 300);
|
await setJson(`otp:${mobileNumber}`, otp, 300);
|
||||||
|
logger.info(`Sent OTP [${otp}] to ${mobileNumber}`);
|
||||||
return res.status(200).json({ message: 'OTP_SENT' });
|
return res.status(200).json({ message: 'OTP_SENT' });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err, 'Error sending OTP');
|
logger.error(err, 'Error sending OTP');
|
||||||
|
|||||||
@@ -54,11 +54,17 @@ const templates = {
|
|||||||
USERNAME_SAVED: (PreferName) =>
|
USERNAME_SAVED: (PreferName) =>
|
||||||
`Dear Customer, Your Preferred Name -${PreferName} has been updated successfully. If this change was not made by you, please contact our support team immediately.`,
|
`Dear Customer, Your Preferred Name -${PreferName} has been updated successfully. If this change was not made by you, please contact our support team immediately.`,
|
||||||
|
|
||||||
TLIMIT :(otp) =>
|
TLIMIT: (otp) =>
|
||||||
`Dear Customer,Please complete the transaction limit set with OTP -${otp}. -KCCB`,
|
`Dear Customer,Please complete the transaction limit set with OTP -${otp}. -KCCB`,
|
||||||
|
|
||||||
TLIMIT_SET :(amount) =>
|
TLIMIT_SET: (amount) =>
|
||||||
`Dear Customer,Your transaction limit for Internet Banking is set to Rs ${amount}. -KCCB`,
|
`Dear Customer,Your transaction limit for Internet Banking is set to Rs ${amount}. -KCCB`,
|
||||||
|
|
||||||
|
LPWORD_CHANGE:
|
||||||
|
`Dear Customer, Your Login password has been successfully updated. If you did not initiate this, please contact your nearest branch immediately. -KCCB`,
|
||||||
|
|
||||||
|
TPWORD_CHANGE:
|
||||||
|
`Dear Customer, Your transaction password has been successfully updated. If you did not initiate this, please contact your nearest branch immediately. -KCCB`,
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = templates;
|
module.exports = templates;
|
||||||
Reference in New Issue
Block a user