Commit 52fbc07b by jay

signup otp fix

1 parent a9106a85
...@@ -78,20 +78,20 @@ ...@@ -78,20 +78,20 @@
"httpResposneIsVerifiedBody": { "httpResposneIsVerifiedBody": {
"type": "text" "type": "text"
}, },
"httpsLoginOtpRequestBody": { "httpsSMSRequestBody": {
"type": "text" "type": "text"
}, },
"httpLoginOtpRequestHeaders": { "httpSMSRequestHeaders": {
"type": "text" "type": "text"
}, },
"httpLoginOtpRequestUrl": { "httpSMSRequestUrl": {
"type": "text" "type": "text"
}, },
"httpLoginOtpRequestMethod": { "httpSMSRequestMethod": {
"type": "string" "type": "text"
}, },
"httpLoginOtpResposneBody": { "httpSMSResposneBody": {
"type": "string" "type": "text"
} }
} }
} }
...@@ -66,14 +66,15 @@ module.exports = createCoreService( ...@@ -66,14 +66,15 @@ module.exports = createCoreService(
// otp_verified_yn: "N", // otp_verified_yn: "N",
}; };
// console.log("OTPDETAILS", otpDetails); // 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 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 spertoResponse = await axios.post( const spertoEmailResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php", "https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails, otpDetails,
{ headers: headers } { headers: headers }
); );
// console.log("spertoResponse", spertoResponse); // const finalReturn = {}
return spertoResponse; console.log("spertoSMSResponse", spertoSMSResponse);
return {spertoSMSResponse, spertoEmailResponse} ;
// return ; // return ;
}, },
}) })
......
...@@ -79,6 +79,7 @@ const userPermissionExtension = (plugin) => { ...@@ -79,6 +79,7 @@ const userPermissionExtension = (plugin) => {
const emailToSend = { const emailToSend = {
to: user.email, to: user.email,
from: `contact@hiranandani.net`, from: `contact@hiranandani.net`,
oneTimePassword: oneTimePassword,
replyTo: resetPasswordSettings.response_email, replyTo: resetPasswordSettings.response_email,
subject: `Your one time password is: ${oneTimePassword}`, subject: `Your one time password is: ${oneTimePassword}`,
text: `Hello ${endUser.fullName}, Your one time password to login to your partner portal 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) => { ...@@ -89,59 +90,118 @@ const userPermissionExtension = (plugin) => {
Regards, Regards,
Hiranandani Team.`, Hiranandani Team.`,
}; };
const finalData = {
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails emailToSend: emailToSend,
const updateUser = await getService("user").edit(user.id, { mobileNo: mobileNumber,
oneTimePassword: `${oneTimePassword}`, fullName: endUser.fullName,
});
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); // NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
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.` // const headers = { "Content-Type": "application/json" };
); // const otpDetails = {
ctx.send({ ok: true, message: "otp sent" }); // api_key: process.env.SPERTO_API_KEY,
console.log("ctx.request.body",ctx.request.body); // 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 { try {
const spertoResponse = await axios.post( // const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php", // "https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails, // otpDetails,
{ headers: headers } // { 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( ctx.request.body.httpRequestEmailMethod =
spertoResponse.headers 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.httpSMSRequestMethod =
ctx.request.body.httpLoginOtpRequestlUrl = spertoResponse.config.url; spretoOTP.spertoSMSResponse.config.method;
ctx.request.body.httpsLoginOtpRequestBody = spertoResponse.config.data; ctx.request.body.httpSMSRequestUrl =
ctx.request.body.httpLoginOtpResposneBody = JSON.stringify( spretoOTP.spertoSMSResponse.config.url;
spertoResponse.data // ctx.request.body.httpsSMSRequestBody = spretoOTP.spertoSMSResponse.config.data;
ctx.request.body.httpSMSResposneBody = JSON.stringify(
spretoOTP.spertoSMSResponse.data
); );
ctx.request.body.thirdPartyApiError = false; ctx.request.body.thirdPartyApiError = false;
console.log("spertoResponse", spertoResponse); // console.log("spretoOTP", spretoOTP);
return spertoResponse;
// return spretoOTP;
} catch (error) { } catch (error) {
ctx.request.body.httpLoginOtpRequestHeaders = JSON.stringify( // Email errors
ctx.request.body.httpRequestEmailHeaders = JSON.stringify(
error.config.headers error.config.headers
); );
ctx.request.body.httpLoginOtpRequestMethod = error.config.method; ctx.request.body.httpRequestEmailMethod = error.config.method;
ctx.request.body.httpLoginOtpRequestlUrl = error.config.url; ctx.request.body.httpRequestEmailUrl = error.config.url;
ctx.request.body.httpsLoginOtpRequestBody = error.config.data; ctx.request.body.httpsRequestEmailBody = error.config.data;
ctx.request.body.httpLoginOtpResposneBody = JSON.stringify( ctx.request.body.httpResposneEmailBody = JSON.stringify(error.message);
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; 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. // Send an email to the user.
// await getService("user").sendOTPOnEmail(emailToSend); // 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!