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 52600bee
authored
2022-09-30 12:48:18 +0530
by
Harish Patel
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Changes for registrarion
1 parent
94c6186b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
27 deletions
src/api/end-user/controllers/end-user.js
src/api/end-user/routes/custom-routes.js
src/api/end-user/controllers/end-user.js
View file @
52600be
...
...
@@ -5,37 +5,69 @@
*/
const
{
factories
}
=
require
(
"@strapi/strapi"
);
const
{
getService
}
=
require
(
"@strapi/plugin-users-permissions/server/utils"
);
module
.
exports
=
factories
.
createCoreController
(
"api::end-user.end-user"
,
({
strapi
:
Strapi
})
=>
({
// Wrapping a core action (leaves core logic in place)
async
create
(
ctx
)
{
console
.
log
(
ctx
.
request
.
body
);
const
currentUser
=
ctx
.
state
.
user
;
// Method 1: Creating an entirely custom action
// async finishEndUserOtpVerification(ctx) {
// (await strapi.service) <
// PostService >
// "api::post.post".exampleService({});
// try {
// ctx.body = "ok";
// } catch (err) {
// ctx.body = err;
// }
// },
// Find the linked user next.
// const existingUser = await strapi
// .query("plugin::users-permissions.user")
// .findOne({ username: ctx.request.body.data.mobileNo });
// Method 1: Creating an entirely custom action
async
finishEndUserOtpVerification
(
ctx
)
{
const
{
mobileNo
,
oneTimePassword
}
=
ctx
.
request
.
body
;
// const existingUserEntries = await strapi.entityService.findMany(
// "plugin::users-permissions.user",
// {
// // fields: ['title', 'description'],
// filters: { username: ctx.request.body.data.mobileNo },
// }
// );
// console.log(`Inside end-user create, found existingUserEntries: `);
// console.log(existingUserEntries);
// if (!existingUserEntries || existingUserEntries.length === 0) {
// throw new ValidationError(
// `Unable to resolve existing user with mobileNo: ${ctx.request.body.data.mobileNo}.`
// );
// }
// 1. Identify the end-user record using the above.
const
endUser
=
await
strapi
.
query
(
"api::end-user.end-user"
).
findOne
({
populate
:
[
"user"
],
where
:
{
$and
:
[{
publishedAt
:
{
$null
:
true
}
},
{
mobileNo
:
mobileNo
}],
},
});
if
(
!
endUser
)
{
throw
new
ValidationError
(
"Invalid mobile number."
);
}
// 2. Then identify the user record using step 1.
// 3. Verify otp.
const
user
=
await
strapi
.
query
(
"plugin::users-permissions.user"
)
.
findOne
({
where
:
{
$and
:
[
{
id
:
endUser
.
user
.
id
},
{
oneTimePassword
:
oneTimePassword
},
],
},
});
if
(
!
user
||
user
.
blocked
)
{
throw
new
ValidationError
(
"Code provided is not valid."
);
}
// 4. stamp otp in user to null.
await
getService
(
"user"
).
edit
(
user
.
id
,
{
oneTimePassword
:
null
,
password
:
oneTimePassword
,
});
// TODO: at this point we might have to invoke a Hiranandani API to send the newly registered user there.
ctx
.
send
({
ok
:
true
,
message
:
"user registered"
});
},
// const existingUser = existingUserEntries[0];
// Wrapping a core action (leaves core logic in place)
async
create
(
ctx
)
{
const
currentUser
=
ctx
.
state
.
user
;
// 2. check if the current user already has an existing business listing (existingEndUser) against their name.
const
existingEndUser
=
await
strapi
.
entityService
.
findMany
(
...
...
@@ -85,9 +117,6 @@ module.exports = factories.createCoreController(
// We make sure that the newly created listing is created against the current business owner.
ctx
.
request
.
body
.
data
[
"user"
]
=
currentUser
.
id
;
console
.
log
(
`About to insert end user: `
);
console
.
log
(
ctx
.
request
.
body
.
data
);
// Now go ahead and create the listing.
return
await
super
.
create
(
ctx
);
}
...
...
src/api/end-user/routes/custom-routes.js
0 → 100644
View file @
52600be
const
routes
=
{
routes
:
[
{
method
:
"POST"
,
path
:
"/end-users/finish-otp-verification"
,
handler
:
"api::end-user.end-user.finishEndUserOtpVerification"
,
config
:
{
// some configuration...
}
}
]
};
module
.
exports
=
routes
;
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