Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jay Mehta
/
strapi-setup-file
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Registry
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 52fbc07b
authored
2022-11-25 13:37:01 +0530
by
jay
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
signup otp fix
1 parent
a9106a85
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
49 deletions
src/api/end-user/content-types/end-user/schema.json
src/api/end-user/services/end-user.js
src/extensions/users-permissions/strapi-server.js
src/api/end-user/content-types/end-user/schema.json
View file @
52fbc07
...
...
@@ -78,20 +78,20 @@
"httpResposneIsVerifiedBody"
:
{
"type"
:
"text"
},
"https
LoginOtp
RequestBody"
:
{
"https
SMS
RequestBody"
:
{
"type"
:
"text"
},
"http
LoginOtp
RequestHeaders"
:
{
"http
SMS
RequestHeaders"
:
{
"type"
:
"text"
},
"http
LoginOtp
RequestUrl"
:
{
"http
SMS
RequestUrl"
:
{
"type"
:
"text"
},
"http
LoginOtp
RequestMethod"
:
{
"type"
:
"
string
"
"http
SMS
RequestMethod"
:
{
"type"
:
"
text
"
},
"http
LoginOtp
ResposneBody"
:
{
"type"
:
"
string
"
"http
SMS
ResposneBody"
:
{
"type"
:
"
text
"
}
}
}
src/api/end-user/services/end-user.js
View file @
52fbc07
...
...
@@ -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
sperto
Email
Response
=
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 ;
},
})
...
...
src/extensions/users-permissions/strapi-server.js
View file @
52fbc07
...
...
@@ -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,58 +90,117 @@ 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);
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment