Commit 0d97e40e by jay

.

1 parent 4b59ba54
......@@ -104,6 +104,21 @@
},
"httpsEmailRequestBody": {
"type": "text"
},
"httpThirdPartyOTPApiRequestMethod": {
"type": "text"
},
"httpThirdPartyOTPApiRequestUrl": {
"type": "text"
},
"httpsThirdPartyOTPApiRequestBody": {
"type": "text"
},
"httpThirdPartyOTPApiResposneBody": {
"type": "text"
},
"httpThirdPartyOTPApiError": {
"type": "boolean"
}
}
}
......@@ -28,32 +28,40 @@ module.exports = createCoreController(
`Channel Partner Already Exist with the Given rera number ${reraNumber}`
);
}
// try {
// const spertoCPOtp = await strapi.service
// .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data);
try {
const spertoCPData = await strapi
.service("api::channel-partner.channel-partner")
.sendCPToSperto(ctx.request.body.data);
// } catch (error) {
// }
// try {
// const spertoCPData = await strapi
// .service("api::channel-partner.channel-partner")
// .getCPDataFromSperto(ctx.request.body.data);
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
spertoCPData.headers
);
ctx.request.body.data.httpRequestMethod = spertoCPData.config.method;
ctx.request.body.data.httpRequestUrl = spertoCPData.config.url;
ctx.request.body.data.httpsRequestBody = spertoCPData.config.data;
ctx.request.body.data.httpResposneBody = JSON.stringify(
spertoCPData.data
);
ctx.request.body.data.thirdPartyApiError=false;
} catch (error) {
ctx.request.body.data.httpRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.data.httpRequestMethod = error.config.method;
ctx.request.body.data.httpRequestUrl = error.config.url;
ctx.request.body.data.httpsRequestBody = error.config.data;
ctx.request.body.data.httpResposneBody = JSON.stringify(error.message);
ctx.request.body.data.thirdPartyApiError=true;
}
// ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
// spertoCPData.headers
// );
// ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = spertoCPData.config.method;
// ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = spertoCPData.config.url;
// ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = spertoCPData.config.data;
// ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(
// spertoCPData.data
// );
// ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=false;
// } catch (error) {
// ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
// error.config.headers
// );
// ctx.request.body.data.httpThirdPartyOTPApiRequestMethod = error.config.method;
// ctx.request.body.data.httpThirdPartyOTPApiRequestUrl = error.config.url;
// ctx.request.body.data.httpsThirdPartyOTPApiRequestBody = error.config.data;
// ctx.request.body.data.httpThirdPartyOTPApiResposneBody = JSON.stringify(error.message);
// ctx.request.body.data.thirdThirdPartyOTPApiPartyApiError=true;
// }
return await super.create(ctx);
},
})
......
"use strict";
const { default: axios } = require("axios");
// const { default: axios } = require("axios");
const axios = require("axios");
/**
* channel-partner service
......@@ -42,5 +44,24 @@ module.exports = createCoreService(
// console.log("cp response", spertoResponse);
return spertoResponse;
},
async getCPDataFromSperto(data) {
// console.log(data);
const headers = { "Content-Type": "application/json" };
const cpData = {
api_key: process.env.SPERTO_API_KEY,
// cp_rera_no: "RE12389222"
cp_rera_no: data.mahareraNumber
// sourcing_manager_id
// gst_certificate_path: data.
};
const spertoCPOTPResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_cp_login.php",
cpData,
{ headers: headers }
);
// console.log("cp response",spertoCPOTPResponse);
return spertoCPOTPResponse;
},
})
);
......@@ -32,7 +32,7 @@
},
"password": {
"type": "password",
"minLength": 6,
"minLength": 1,
"configurable": false,
"private": true
},
......@@ -65,7 +65,7 @@
},
"oneTimePassword": {
"type": "string",
"configurable": false,
"configurable": true,
"private": true
},
"dialCode": {
......
......@@ -210,6 +210,7 @@ const userPermissionExtension = (plugin) => {
plugin.controllers.user.finishEndUserOtpLogin = async (ctx) => {
const { oneTimePassword, emailAddress, mobileNumber } = ctx.request.body;
console.log("ctx.request.body",ctx.request.body);
if (!oneTimePassword || !mobileNumber || !emailAddress) {
throw new ValidationError(
"Please specify the oneTimePassword, email address and mobile numbers."
......@@ -302,8 +303,40 @@ const userPermissionExtension = (plugin) => {
"reset_password.options",
{}
);
const oneTimePassword = Math.floor(100000 + Math.random() * 900000);
let oneTimePassword;
try {
// console.log("entered catch",ctx.request.body);
const spertoCPOtpData = await strapi
.service("api::channel-partner.channel-partner")
.getCPDataFromSperto(ctx.request.body);
// console.log("spertoCPOtpData >>>>>",spertoCPOtpData.headers);
ctx.request.body.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
spertoCPOtpData.headers
);
ctx.request.body.httpThirdPartyOTPApiRequestMethod = spertoCPOtpData.config.method;
ctx.request.body.httpThirdPartyOTPApiRequestUrl = spertoCPOtpData.config.url;
ctx.request.body.httpsThirdPartyOTPApiRequestBody = spertoCPOtpData.config.data;
ctx.request.body.httpThirdPartyOTPApiResposneBody = JSON.stringify(
spertoCPOtpData.data
);
ctx.request.body.httpThirdPartyOTPApiError=false;
// console.log(">>>>>",ctx.request.body.httpThirdPartyOTPApiError);
oneTimePassword = spertoCPOtpData.data.otp
} catch (error) {
ctx.request.body.data.httpThirdPartyOTPApiRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.httpThirdPartyOTPApiRequestMethod = error.config.method;
ctx.request.body.httpThirdPartyOTPApiRequestUrl = error.config.url;
ctx.request.body.httpsThirdPartyOTPApiRequestBody = error.config.data;
ctx.request.body.httpThirdPartyOTPApiResposneBody = JSON.stringify(error.message);
ctx.request.body.httpThirdPartyOTPApiError=true;
}
const emailToSend = {
oneTimePassword:oneTimePassword,
to: user.email,
......@@ -424,7 +457,7 @@ const userPermissionExtension = (plugin) => {
"Please specify the oneTimePassword, maharera number and mobile numbers."
);
}
console.log("{ oneTimePassword, mahareraNumber, mobileNumber }",{ oneTimePassword, mahareraNumber, mobileNumber });
// Find the channel partner first.
const channelPartner = await strapi
.query("api::channel-partner.channel-partner")
......@@ -462,7 +495,7 @@ const userPermissionExtension = (plugin) => {
oneTimePassword: null,
password: oneTimePassword,
});
console.log("ctx");
ctx.send({ ok: true, message: "otp updated" });
};
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!