Commit 52fbc07b by jay

signup otp fix

1 parent a9106a85
......@@ -78,20 +78,20 @@
"httpResposneIsVerifiedBody": {
"type": "text"
},
"httpsLoginOtpRequestBody": {
"httpsSMSRequestBody": {
"type": "text"
},
"httpLoginOtpRequestHeaders": {
"httpSMSRequestHeaders": {
"type": "text"
},
"httpLoginOtpRequestUrl": {
"httpSMSRequestUrl": {
"type": "text"
},
"httpLoginOtpRequestMethod": {
"type": "string"
"httpSMSRequestMethod": {
"type": "text"
},
"httpLoginOtpResposneBody": {
"type": "string"
"httpSMSResposneBody": {
"type": "text"
}
}
}
......@@ -66,14 +66,15 @@ module.exports = createCoreService(
// otp_verified_yn: "N",
};
// console.log("OTPDETAILS", otpDetails);
await axios.get(`http://vas.themultimedia.in/domestic/sendsms/bulksms.php?username=OSAPI&password=os123456&type=TEXT&sender=HROTPs&entityId=1101407690000029629&templateId=1507166789848358346&mobile=${data.mobileNo}&message=Dear%20${data.fullName}%0AYour%20OTP%20for%20Hiranandani%20Exclusive%20website%20login%20is%20${data.emailToSend.oneTimePassword}%0AValid%20for%2010%20minute%20Please%20do%20not%20share%20this%20OTP.%0ARegards%2C%0AHiranandani%20Team.`)
const spertoResponse = await axios.post(
const spertoSMSResponse = await axios.get(`http://vas.themultimedia.in/domestic/sendsms/bulksms.php?username=OSAPI&password=os123456&type=TEXT&sender=HROTPs&entityId=1101407690000029629&templateId=1507166789848358346&mobile=${data.mobileNo}&message=Dear%20${data.fullName}%0AYour%20OTP%20for%20Hiranandani%20Exclusive%20website%20login%20is%20${data.emailToSend.oneTimePassword}%0AValid%20for%2010%20minute%20Please%20do%20not%20share%20this%20OTP.%0ARegards%2C%0AHiranandani%20Team.`)
const spertoEmailResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails,
{ headers: headers }
);
// console.log("spertoResponse", spertoResponse);
return spertoResponse;
// const finalReturn = {}
console.log("spertoSMSResponse", spertoSMSResponse);
return {spertoSMSResponse, spertoEmailResponse} ;
// return ;
},
})
......
......@@ -79,6 +79,7 @@ const userPermissionExtension = (plugin) => {
const emailToSend = {
to: user.email,
from: `contact@hiranandani.net`,
oneTimePassword: oneTimePassword,
replyTo: resetPasswordSettings.response_email,
subject: `Your one time password is: ${oneTimePassword}`,
text: `Hello ${endUser.fullName}, Your one time password to login to your partner portal is ${oneTimePassword}`,
......@@ -89,59 +90,118 @@ const userPermissionExtension = (plugin) => {
Regards,
Hiranandani Team.`,
};
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
const updateUser = await getService("user").edit(user.id, {
oneTimePassword: `${oneTimePassword}`,
});
const headers = { "Content-Type": "application/json" };
const otpDetails = {
api_key: process.env.SPERTO_API_KEY,
from_name: "Hiranandani",
from_mail: emailToSend.from,
to: emailToSend.to,
subject: emailToSend.subject,
body: emailToSend.html,
const finalData = {
emailToSend: emailToSend,
mobileNo: mobileNumber,
fullName: endUser.fullName,
};
await strapi.plugin("email").service("email").send(emailToSend);
await axios.get(
`http://vas.themultimedia.in/domestic/sendsms/bulksms.php?username=OSAPI&password=os123456&type=TEXT&sender=HROTPs&entityId=1101407690000029629&templateId=1507166789848358346&mobile=${mobileNumber}&message=Dear%20${endUser.fullName}%0AYour%20OTP%20for%20Hiranandani%20Exclusive%20website%20login%20is%20${oneTimePassword}%0AValid%20for%2010%20minute%20Please%20do%20not%20share%20this%20OTP.%0ARegards%2C%0AHiranandani%20Team.`
);
ctx.send({ ok: true, message: "otp sent" });
console.log("ctx.request.body",ctx.request.body);
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
// const headers = { "Content-Type": "application/json" };
// const otpDetails = {
// api_key: process.env.SPERTO_API_KEY,
// from_name: "Hiranandani",
// from_mail: emailToSend.from,
// to: emailToSend.to,
// subject: emailToSend.subject,
// body: emailToSend.html,
// };
// await strapi.plugin("email").service("email").send(emailToSend);
// await axios.get(
// `http://vas.themultimedia.in/domestic/sendsms/bulksms.php?username=OSAPI&password=os123456&type=TEXT&sender=HROTPs&entityId=1101407690000029629&templateId=1507166789848358346&mobile=${mobileNumber}&message=Dear%20${endUser.fullName}%0AYour%20OTP%20for%20Hiranandani%20Exclusive%20website%20login%20is%20${oneTimePassword}%0AValid%20for%2010%20minute%20Please%20do%20not%20share%20this%20OTP.%0ARegards%2C%0AHiranandani%20Team.`
// );
try {
const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails,
{ headers: headers }
// const spertoResponse = await axios.post(
// "https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
// otpDetails,
// { headers: headers }
// );
const spretoOTP = await strapi
.service("api::end-user.end-user")
.sendOTPToSpreto(finalData);
// console.log("spretoOTP", spretoOTP);
// EMAIL RESPONSE
ctx.request.body.httpRequestEmailHeaders = JSON.stringify(
spretoOTP.spertoEmailResponse.headers
);
ctx.request.body.httpLoginOtpRequestHeaders = JSON.stringify(
spertoResponse.headers
ctx.request.body.httpRequestEmailMethod =
spretoOTP.spertoEmailResponse.config.method;
ctx.request.body.httpRequestEmailUrl =
spretoOTP.spertoEmailResponse.config.url;
ctx.request.body.httpsRequestEmailBody =
spretoOTP.spertoEmailResponse.config.data;
ctx.request.body.httpResposneEmailBody = JSON.stringify(
spretoOTP.spertoEmailResponse.data
);
// SMS RESPONSE
ctx.request.body.httpSMSRequestHeaders = JSON.stringify(
spretoOTP.spertoSMSResponse.headers
);
ctx.request.body.httpLoginOtpRequestMethod = spertoResponse.config.method;
ctx.request.body.httpLoginOtpRequestlUrl = spertoResponse.config.url;
ctx.request.body.httpsLoginOtpRequestBody = spertoResponse.config.data;
ctx.request.body.httpLoginOtpResposneBody = JSON.stringify(
spertoResponse.data
ctx.request.body.httpSMSRequestMethod =
spretoOTP.spertoSMSResponse.config.method;
ctx.request.body.httpSMSRequestUrl =
spretoOTP.spertoSMSResponse.config.url;
// ctx.request.body.httpsSMSRequestBody = spretoOTP.spertoSMSResponse.config.data;
ctx.request.body.httpSMSResposneBody = JSON.stringify(
spretoOTP.spertoSMSResponse.data
);
ctx.request.body.thirdPartyApiError = false;
console.log("spertoResponse", spertoResponse);
return spertoResponse;
// console.log("spretoOTP", spretoOTP);
// return spretoOTP;
} catch (error) {
ctx.request.body.httpLoginOtpRequestHeaders = JSON.stringify(
// Email errors
ctx.request.body.httpRequestEmailHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.httpLoginOtpRequestMethod = error.config.method;
ctx.request.body.httpLoginOtpRequestlUrl = error.config.url;
ctx.request.body.httpsLoginOtpRequestBody = error.config.data;
ctx.request.body.httpLoginOtpResposneBody = JSON.stringify(
error.message
ctx.request.body.httpRequestEmailMethod = error.config.method;
ctx.request.body.httpRequestEmailUrl = error.config.url;
ctx.request.body.httpsRequestEmailBody = error.config.data;
ctx.request.body.httpResposneEmailBody = JSON.stringify(error.message);
// SMS headers
ctx.request.body.httpSMSRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.httpSMSRequestMethod = error.config.method;
ctx.request.body.httpSMSRequestUrl = error.config.url;
// ctx.request.body.httpsSMSRequestBody = error.config.data;
ctx.request.body.httpSMSResposneBody = JSON.stringify(error.message);
ctx.request.body.thirdPartyApiError = true;
}
const updateUser = await getService("user").edit(user.id, {
oneTimePassword: `${oneTimePassword}`,
});
await strapi.entityService.update("api::end-user.end-user", endUser.id, {
data: {
httpRequestIsVerifiedHeaders:
ctx.request.body.httpRequestIsVerifiedHeaders,
httpsRequestIsVerifiedBody: ctx.request.body.httpsRequestIsVerifiedBody,
httpRequestIsVerifiedUrl: ctx.request.body.httpRequestIsVerifiedUrl,
httpRequestIsVerifiedMethod:
ctx.request.body.httpRequestIsVerifiedMethod,
httpResposneIsVerifiedBody: ctx.request.body.httpResposneIsVerifiedBody,
httpRequestIsVerifiedHeaders:
ctx.request.body.httpRequestIsVerifiedHeaders,
// httpsRequestIsVerifiedBody: ctx.request.body.httpsRequestIsVerifiedBody,
httpSMSRequestUrl: ctx.request.body.httpSMSRequestUrl,
httpSMSRequestMethod: ctx.request.body.httpSMSRequestMethod,
httpSMSResposneBody: ctx.request.body.httpSMSResposneBody,
httpSMSRequestHeaders: ctx.request.body.httpSMSRequestHeaders,
},
});
ctx.send({ ok: true, message: "otp sent" });
// const updateUser = await getService("user").edit(user.id, {
// oneTimePassword: `${oneTimePassword}`,
// });
// Send an email to the user.
// await getService("user").sendOTPOnEmail(emailToSend);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!