Email signin verification code changes
This commit is contained in:
parent
ee0dcd34fd
commit
41bbc2ca6f
@ -1054,6 +1054,31 @@ exports.forgotPasswordVerifyOTP = async (req, res) => {
|
||||
return res.status(500).json({ status: "failed", message: "Internal server error" });
|
||||
}
|
||||
};
|
||||
function formatUAEPhoneNumber(phone) {
|
||||
if (!phone) return '';
|
||||
|
||||
// Convert number → string safely
|
||||
let digits = String(phone).replace(/\D/g, '');
|
||||
|
||||
// Case 1: 9-digit UAE mobile (e.g. 506491429)
|
||||
if (digits.length === 9 && digits.startsWith('5')) {
|
||||
digits = '971' + digits;
|
||||
}
|
||||
|
||||
// Case 2: 10-digit starting with 0 (e.g. 0506491429)
|
||||
if (digits.length === 10 && digits.startsWith('0')) {
|
||||
digits = '971' + digits.substring(1);
|
||||
}
|
||||
|
||||
// Case 3: Already has country code
|
||||
if (digits.startsWith('971') && digits.length === 12) {
|
||||
// ok
|
||||
} else if (!digits.startsWith('971')) {
|
||||
return phone; // fail-safe
|
||||
}
|
||||
|
||||
return `+${digits.substring(0, 3)} ${digits.substring(3, 5)} ${digits.substring(5, 8)} ${digits.substring(8)}`;
|
||||
}
|
||||
|
||||
exports.requestOTPForLogin = async (req, res) => {
|
||||
try {
|
||||
@ -1103,13 +1128,14 @@ exports.requestOTPForLogin = async (req, res) => {
|
||||
{
|
||||
where: { email: registered_email }
|
||||
}
|
||||
);
|
||||
);
|
||||
const formattedSupportPhone = formatUAEPhoneNumber(process.env.SUPPORT_PHONE);
|
||||
const placeHolderData = {
|
||||
username: loggingUser.name,
|
||||
verfication_code: otp,
|
||||
otp_expiry: otp_expiry,
|
||||
otp_expiry: 10,
|
||||
support_email: process.env.SUPPORT_EMAIL,
|
||||
support_phone: process.env.SUPPORT_PHONE,
|
||||
support_phone: formattedSupportPhone,
|
||||
logo_url: `${process.env.APP_BASE_URL}/assets/FCSCLogo.png`
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user