@ozdao/prometheus-framework 0.2.137 → 0.2.139
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/auth.server.js +29 -14
- package/dist/auth.server.mjs +29 -14
- package/dist/community.server.js +3 -3
- package/dist/community.server.mjs +3 -3
- package/dist/events.server.js +3 -3
- package/dist/events.server.mjs +3 -3
- package/dist/files.server.js +3 -3
- package/dist/files.server.mjs +3 -3
- package/dist/gallery.server.js +4 -4
- package/dist/gallery.server.mjs +4 -4
- package/dist/index-DNI4aUP2.js +259 -0
- package/dist/index-Tcyehi73.mjs +260 -0
- package/dist/main-DTHFR7H_.mjs +14510 -0
- package/dist/main-wXdocsbd.js +92 -0
- package/dist/main.css +1 -1
- package/dist/orders.server.js +9 -8
- package/dist/orders.server.mjs +9 -8
- package/dist/organizations.server.js +32 -17
- package/dist/organizations.server.mjs +32 -17
- package/dist/products.server.js +37 -5
- package/dist/products.server.mjs +37 -5
- package/dist/prometheus-framework/src/components/Block/Block.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Block/Block.vue.js +1 -1
- package/dist/prometheus-framework/src/components/Completion/Completion.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Completion/Completion.vue.js +19 -19
- package/dist/prometheus-framework/src/components/Feed/Feed.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Feed/Feed.vue.js +1 -1
- package/dist/prometheus-framework/src/components/Map/Map.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Map/Map.vue.js +3 -2
- package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/auth/components/pages/Invite.vue.js +32 -31
- package/dist/prometheus-framework/src/modules/auth/store/auth.cjs +1 -1
- package/dist/prometheus-framework/src/modules/auth/store/auth.js +50 -47
- package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/community/components/sections/HotPosts.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/globals/components/blocks/CardHeader.vue.js +2 -2
- package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/legal/components/pages/Legal.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.cjs +1 -1
- package/dist/prometheus-framework/src/modules/marketplace/store/marketplace.js +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +12 -12
- package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.js +2 -2
- package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/blocks/CardOrganization.vue.js +41 -38
- package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/Members.vue.js +123 -114
- package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.js +51 -52
- package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/DetailsTab.vue.js +16 -15
- package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.js +120 -60
- package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/organizations/store/invites.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/store/invites.js +25 -24
- package/dist/prometheus-framework/src/modules/spots/components/blocks/CardSpot.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/spots/components/blocks/CardSpot.vue.js +7 -7
- package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/spots/components/layouts/Spots.vue.js +3 -3
- package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/spots/components/pages/Map.vue.js +65 -66
- package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.js +81 -76
- package/dist/prometheus-framework/src/modules/spots/router/spots.cjs +1 -1
- package/dist/prometheus-framework/src/modules/spots/router/spots.js +1 -1
- package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/users/components/pages/Profile.vue.js +2 -2
- package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/users/components/pages/ProfileEdit.vue.js +78 -74
- package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.js +2 -2
- package/dist/prometheus-framework.cjs.js +1 -1
- package/dist/prometheus-framework.es.js +1 -1
- package/dist/reports.server.js +0 -3
- package/dist/reports.server.mjs +0 -3
- package/dist/spots.server.js +3 -3
- package/dist/spots.server.mjs +3 -3
- package/dist/style.css +1 -1
- package/dist/wallet.server.js +5 -5
- package/dist/wallet.server.mjs +8 -8
- package/dist/web-Dh669DqQ.mjs +54 -0
- package/dist/web-Dt2RCU54.js +1 -0
- package/package.json +1 -1
- package/src/components/Completion/Completion.vue +29 -30
- package/src/components/Map/Map.vue +2 -2
- package/src/modules/auth/components/pages/Invite.vue +4 -2
- package/src/modules/auth/controllers/auth.controller.js +30 -12
- package/src/modules/auth/middlewares/authJwt.js +80 -0
- package/src/modules/{middlewares/server → auth/middlewares}/index.js +1 -3
- package/src/modules/{middlewares/server → auth/middlewares}/verifyAccesses.js +1 -1
- package/src/modules/auth/routes/auth.routes.js +2 -2
- package/src/modules/auth/routes/twofa.routes.js +1 -1
- package/src/modules/auth/store/auth.js +9 -0
- package/src/modules/chats/routes/chats.routes.js +1 -1
- package/src/modules/community/routes/blog.routes.js +2 -2
- package/src/modules/events/routes/events.routes.js +2 -2
- package/src/modules/files/routes/files.routes.js +2 -2
- package/src/modules/gallery/routes/gallery.routes.js +4 -5
- package/src/modules/globals/services/globals.crud.js +2 -2
- package/src/modules/marketplace/store/marketplace.js +1 -1
- package/src/modules/orders/components/pages/OrderCreateBackoffice.vue +2 -2
- package/src/modules/orders/components/sections/FormAddCustomer.vue +2 -2
- package/src/modules/orders/controllers/orders.controller.js +1 -0
- package/src/modules/orders/routes/applications.routes.js +2 -2
- package/src/modules/orders/routes/orders.routes.js +2 -2
- package/src/modules/organizations/components/blocks/CardOrganization.vue +9 -7
- package/src/modules/organizations/components/pages/Members.vue +26 -15
- package/src/modules/organizations/components/pages/Organization.vue +3 -3
- package/src/modules/organizations/components/sections/DetailsTab.vue +1 -1
- package/src/modules/organizations/components/sections/MembersAdd.vue +101 -43
- package/src/modules/organizations/controllers/invites.controller.js +18 -13
- package/src/modules/organizations/controllers/memberships.controller.js +18 -11
- package/src/modules/organizations/controllers/organizations.controller.js +3 -4
- package/src/modules/organizations/models/membership.model.js +2 -0
- package/src/modules/organizations/models/organization.model.js +4 -0
- package/src/modules/organizations/routes/invites.routes.js +2 -2
- package/src/modules/organizations/store/invites.js +2 -1
- package/src/modules/products/controllers/leftovers.controller.js +1 -1
- package/src/modules/products/middlewares/index.js +11 -0
- package/src/modules/products/routes/categories.routes.js +2 -2
- package/src/modules/reports/routes/reports.routes.js +2 -2
- package/src/modules/spots/components/blocks/CardSpot.vue +0 -1
- package/src/modules/spots/components/layouts/Spots.vue +2 -2
- package/src/modules/spots/components/pages/Map.vue +79 -78
- package/src/modules/spots/components/pages/SpotEdit.vue +8 -5
- package/src/modules/spots/controllers/spots.controller.js +1 -5
- package/src/modules/spots/router/spots.js +1 -1
- package/src/modules/users/components/pages/ProfileEdit.vue +37 -22
- package/src/modules/wallet/controllers/routes/payments.routes.js +2 -2
- package/src/modules/wallet/controllers/routes/rewards.routes.js +2 -2
- package/src/modules/middlewares/server/authJwt.js +0 -68
- /package/src/modules/{middlewares/server → auth/middlewares}/authSecret.js +0 -0
- /package/src/modules/{middlewares/server → auth/middlewares}/verifyInvites.js +0 -0
- /package/src/modules/{middlewares/server → auth/middlewares}/verifySignUp.js +0 -0
- /package/src/modules/{middlewares/server → auth/middlewares}/verifyUser.js +0 -0
- /package/src/modules/globals/services/{globals.cashe.js → globals.cache.js} +0 -0
- /package/src/modules/{middlewares/server → products/middlewares}/verifyCategory.js +0 -0
@@ -96,7 +96,8 @@
|
|
96
96
|
<Address
|
97
97
|
:apiKey="GOOGLE_MAPS_API_KEY"
|
98
98
|
:address="spots.state.spot.address"
|
99
|
-
:location="spots.state.spot.location"
|
99
|
+
:location="spots.state.spot.location"
|
100
|
+
:locale="$i18n.locale"
|
100
101
|
label="Address"
|
101
102
|
placeholder="Enter delivery address"
|
102
103
|
class="
|
@@ -114,7 +115,8 @@
|
|
114
115
|
|
115
116
|
:address="spots.state.spot.address"
|
116
117
|
:location="spots.state.spot.location"
|
117
|
-
|
118
|
+
:locale="$i18n.locale"
|
119
|
+
|
118
120
|
class="h-20r mn-b-small radius-bl-medium radius-br-medium o-hidden"
|
119
121
|
@update:location="newLocation => {
|
120
122
|
spots.state.spot.location = newLocation;
|
@@ -144,7 +146,7 @@
|
|
144
146
|
</Block>
|
145
147
|
</div>
|
146
148
|
|
147
|
-
<Button :submit="onDelete" :callback="
|
149
|
+
<Button :submit="onDelete" :callback="redirectDash" class="w-100 bg-light">Delete Spot</Button>
|
148
150
|
</div>
|
149
151
|
</template>
|
150
152
|
|
@@ -211,7 +213,8 @@ async function onSubmit() {
|
|
211
213
|
}
|
212
214
|
|
213
215
|
function redirectTo() {
|
214
|
-
router.replace({ name: "Spot", params: { _id: route.params._id, spot: spots.state.spot._id } });
|
216
|
+
// router.replace({ name: "Spot", params: { _id: route.params._id, spot: spots.state.spot._id } });
|
217
|
+
router.push({ name: "Organization", params: { _id: route.params._id }});
|
215
218
|
}
|
216
219
|
|
217
220
|
async function onDelete() {
|
@@ -222,7 +225,7 @@ async function onDelete() {
|
|
222
225
|
}
|
223
226
|
|
224
227
|
function redirectDash() {
|
225
|
-
router.
|
228
|
+
router.push({ name: "Organization", params: { _id: route.params._id }});
|
226
229
|
}
|
227
230
|
</script>
|
228
231
|
|
@@ -3,8 +3,6 @@ const controllerFactory = (db) => {
|
|
3
3
|
|
4
4
|
const readOne = (req, res) => {
|
5
5
|
Spot.findOne({_id: req.params._id})
|
6
|
-
.populate('members.user')
|
7
|
-
.populate('subspots')
|
8
6
|
.then(spot => {
|
9
7
|
if (!spot) {
|
10
8
|
return res.status(404).send({ message: "Отдел не найден" });
|
@@ -18,8 +16,6 @@ const controllerFactory = (db) => {
|
|
18
16
|
|
19
17
|
const read = (req, res) => {
|
20
18
|
Spot.find({ organization: req.params._id })
|
21
|
-
.populate('members.user')
|
22
|
-
.populate('subspots')
|
23
19
|
.then(spots => {
|
24
20
|
if (!spots) {
|
25
21
|
return res.status(404).send({ message: "Spots not found" });
|
@@ -60,7 +56,7 @@ const controllerFactory = (db) => {
|
|
60
56
|
};
|
61
57
|
|
62
58
|
const deleteSpot = (req, res) => {
|
63
|
-
Spot.
|
59
|
+
Spot.findOneAndDelete({ _id: req.body._id, organization: req.params._id })
|
64
60
|
.then(spot => {
|
65
61
|
if (!spot) {
|
66
62
|
return res.status(404).send({ message: "Spot not found" });
|
@@ -1,17 +1,17 @@
|
|
1
1
|
<template>
|
2
|
-
<div class="pd-medium for-transition w-100">
|
2
|
+
<div v-if="show" class="pd-medium for-transition w-100">
|
3
3
|
|
4
4
|
<ProfileCompletion
|
5
5
|
v-if="route.params._id === auth.state.user._id"
|
6
|
-
:user="auth.state.user._id"
|
7
|
-
:target="
|
6
|
+
:user="auth.state.user._id"
|
7
|
+
:target="users.state.current"
|
8
8
|
:cta="false"
|
9
9
|
/>
|
10
10
|
<!-- -->
|
11
11
|
<h3 class="mn-b-small">Username</h3>
|
12
12
|
|
13
13
|
<Field
|
14
|
-
v-model:field="
|
14
|
+
v-model:field="users.state.current.username"
|
15
15
|
label="@"
|
16
16
|
placeholder="Not specified"
|
17
17
|
class="mn-b-thin w-100 bg-light pd-medium radius-small"
|
@@ -25,15 +25,15 @@
|
|
25
25
|
|
26
26
|
<div class="mn-b-thin radius-small w-100 h-10r bg-light flex-center flex-column flex">
|
27
27
|
<UploadImage
|
28
|
-
v-model:photo="
|
29
|
-
:uploadPath="'users/' +
|
28
|
+
v-model:photo="users.state.current.profile.photo"
|
29
|
+
:uploadPath="'users/' + users.state.current._id + '/avatars'"
|
30
30
|
class="h-4r w-4r aspect-1x1 o-hidden bg-white mn-b-thin radius-extra"
|
31
31
|
/>
|
32
32
|
<h4>Upload userpic</h4>
|
33
33
|
</div>
|
34
34
|
|
35
35
|
<Field
|
36
|
-
v-model:field="
|
36
|
+
v-model:field="users.state.current.profile.name"
|
37
37
|
label="Name"
|
38
38
|
placeholder="Not specified"
|
39
39
|
class="mn-b-thin bg-light pd-medium radius-small"
|
@@ -41,18 +41,17 @@
|
|
41
41
|
/>
|
42
42
|
|
43
43
|
<Field
|
44
|
-
v-model:field="
|
44
|
+
v-model:field="users.state.current.profile.description"
|
45
45
|
label="Description"
|
46
46
|
placeholder="Not specified"
|
47
47
|
class="mn-b-semi bg-light pd-medium radius-small"
|
48
|
-
disabled="true"
|
49
48
|
:validation="organizationName"
|
50
49
|
/>
|
51
50
|
|
52
51
|
<!-- <p class="mn-b-thin">Select your birthday if you want to receive your birthday gift.</p>
|
53
52
|
|
54
53
|
<Field
|
55
|
-
v-model:field="
|
54
|
+
v-model:field="users.state.current.birthday"
|
56
55
|
label="Birthday"
|
57
56
|
type="date"
|
58
57
|
placeholder="Not specified"
|
@@ -63,25 +62,25 @@
|
|
63
62
|
<p class="mn-b-thin">Please provide only the username for social media profiles, without full links.</p>
|
64
63
|
|
65
64
|
<Field
|
66
|
-
v-model:field="
|
65
|
+
v-model:field="users.state.current.socials.instagram"
|
67
66
|
label="Instagram"
|
68
67
|
placeholder=""
|
69
68
|
class="mn-b-thin bg-light pd-medium radius-small"
|
70
69
|
/>
|
71
70
|
<Field
|
72
|
-
v-model:field="
|
71
|
+
v-model:field="users.state.current.socials.twitter"
|
73
72
|
label="Twitter"
|
74
73
|
placeholder=""
|
75
74
|
class="mn-b-thin bg-light pd-medium radius-small"
|
76
75
|
/>
|
77
76
|
<Field
|
78
|
-
v-model:field="
|
77
|
+
v-model:field="users.state.current.socials.facebook"
|
79
78
|
label="Facebook"
|
80
79
|
placeholder=""
|
81
80
|
class="mn-b-thin bg-light pd-medium radius-small"
|
82
81
|
/>
|
83
82
|
<Field
|
84
|
-
v-model:field="
|
83
|
+
v-model:field="users.state.current.socials.telegram"
|
85
84
|
label="Telegram"
|
86
85
|
placeholder=""
|
87
86
|
class="mn-b-semi bg-light pd-medium radius-small"
|
@@ -90,7 +89,7 @@
|
|
90
89
|
<h3 class="mn-b-small">Account</h3>
|
91
90
|
|
92
91
|
<Field
|
93
|
-
v-model:field="
|
92
|
+
v-model:field="users.state.current.phone"
|
94
93
|
label="Phone"
|
95
94
|
placeholder="Not specified"
|
96
95
|
class="mn-b-thin bg-light pd-medium mn-b-thin radius-small"
|
@@ -99,17 +98,29 @@
|
|
99
98
|
/>
|
100
99
|
|
101
100
|
<Field
|
102
|
-
v-model:field="
|
101
|
+
v-model:field="users.state.current.email"
|
103
102
|
label="Email"
|
104
103
|
placeholder="Not specified"
|
105
|
-
class="mn-b-semi
|
104
|
+
class="mn-b-semi bg-light pd-medium radius-small"
|
106
105
|
:disabled="true"
|
107
106
|
:validation="organizationName"
|
108
107
|
/>
|
109
108
|
|
110
|
-
<Button
|
109
|
+
<Button
|
110
|
+
:submit="onSubmit"
|
111
|
+
:callback="redirectTo"
|
112
|
+
class="mn-b-thin bg-main w-100"
|
113
|
+
>
|
114
|
+
Save
|
115
|
+
</Button>
|
111
116
|
|
112
|
-
<Button
|
117
|
+
<Button
|
118
|
+
:submit="onSubmitDelete"
|
119
|
+
:callback="a = () => {router.push({name: 'Sign In'})}"
|
120
|
+
class="mn-b-thin w-100 bg-red t-white"
|
121
|
+
>
|
122
|
+
Delete Account
|
123
|
+
</Button>
|
113
124
|
</div>
|
114
125
|
</template>
|
115
126
|
|
@@ -132,10 +143,14 @@
|
|
132
143
|
// Accessing router
|
133
144
|
const route = useRoute()
|
134
145
|
const router = useRouter()
|
135
|
-
|
136
|
-
const user = ref(
|
146
|
+
|
147
|
+
const user = ref(null)
|
148
|
+
const show = ref(false)
|
149
|
+
|
150
|
+
|
137
151
|
onMounted(async () => {
|
138
|
-
await users.actions.read({ _id: route.params._id });
|
152
|
+
await users.actions.read({ _id: route.params._id, user: auth.state.user._id });
|
153
|
+
show.value = true
|
139
154
|
})
|
140
155
|
// Methods
|
141
156
|
async function onSubmit() {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Middlewares
|
2
|
-
const
|
2
|
+
const middlewareFactoryAuth = require('@pf/src/modules/auth/middlewares');
|
3
3
|
// Factories
|
4
4
|
const controllerFactory = require("../factories/payments.factory");
|
5
5
|
const controllerFactoryTickets = require("@pf/src/modules/events/controllers/tickets.controller");
|
@@ -16,7 +16,7 @@ module.exports = function(app, db, origins, publicPath) {
|
|
16
16
|
const controller = controllerFactory(db);
|
17
17
|
const controllerTickets = controllerFactoryTickets(db, publicPath);
|
18
18
|
|
19
|
-
const { verifySignUp, verifyUser } =
|
19
|
+
const { verifySignUp, verifyUser } = middlewareFactoryAuth(db);
|
20
20
|
|
21
21
|
observer.subscribe('checkout.session.completed', async (paymentIntent) => {
|
22
22
|
const event = await db.event.findOne({ _id: paymentIntent.metadata.product });
|
@@ -2,13 +2,13 @@
|
|
2
2
|
const rewardsControllerFactory = require('../factories/rewards.factory');
|
3
3
|
|
4
4
|
// Middlewares
|
5
|
-
const
|
5
|
+
const middlewareFactoryAuth = require('@pf/src/modules/auth/middlewares');
|
6
6
|
|
7
7
|
// Routes
|
8
8
|
module.exports = (app, db, wss, wdmClient, origins) => {
|
9
9
|
const controller = rewardsControllerFactory(db, wdmClient, wss);
|
10
10
|
|
11
|
-
const { authJwt, authSecret } =
|
11
|
+
const { authJwt, authSecret } = middlewareFactoryAuth(db);
|
12
12
|
|
13
13
|
app.use((req, res, next) => {
|
14
14
|
const origin = req.headers.origin;
|
@@ -1,68 +0,0 @@
|
|
1
|
-
const jwt = require("jsonwebtoken");
|
2
|
-
|
3
|
-
const middlewareFactory = (db) => {
|
4
|
-
const User = db.user;
|
5
|
-
const Role = db.role;
|
6
|
-
|
7
|
-
const verifyToken = async (req, res, next) => {
|
8
|
-
try {
|
9
|
-
if (!req.cookies.user) {
|
10
|
-
// Вместо возврата ошибки, просто устанавливаем req.userId как null
|
11
|
-
req.userId = null;
|
12
|
-
return next();
|
13
|
-
}
|
14
|
-
|
15
|
-
let user = JSON.parse(req.cookies.user);
|
16
|
-
let token = req.headers["x-access-token"] || user.accessToken;
|
17
|
-
|
18
|
-
if (!token) {
|
19
|
-
// Также устанавливаем req.userId как null
|
20
|
-
req.userId = null;
|
21
|
-
return next();
|
22
|
-
}
|
23
|
-
|
24
|
-
const decoded = jwt.verify(token, process.env.SECRET_KEY);
|
25
|
-
req.userId = decoded._id;
|
26
|
-
|
27
|
-
next();
|
28
|
-
} catch (err) {
|
29
|
-
console.log(err);
|
30
|
-
req.userId = null;
|
31
|
-
next();
|
32
|
-
}
|
33
|
-
};
|
34
|
-
|
35
|
-
const checkRole = roleToCheck => async (req, res, next) => {
|
36
|
-
try {
|
37
|
-
const user = await User.findById(req.userId).exec();
|
38
|
-
|
39
|
-
if (!user) {
|
40
|
-
return res.status(404).send({ message: "User Not found." });
|
41
|
-
}
|
42
|
-
|
43
|
-
const roles = await Role.find({ _id: { $in: user.roles }}).exec();
|
44
|
-
|
45
|
-
for (let role of roles) {
|
46
|
-
if (role.name === roleToCheck) {
|
47
|
-
next();
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
res.status(403).send({ message: `Require ${roleToCheck} Role!` });
|
53
|
-
} catch (err) {
|
54
|
-
res.status(500).send({ message: err.message });
|
55
|
-
}
|
56
|
-
};
|
57
|
-
|
58
|
-
const isAdmin = checkRole("admin");
|
59
|
-
const isModerator = checkRole("moderator");
|
60
|
-
|
61
|
-
return {
|
62
|
-
verifyToken,
|
63
|
-
isAdmin,
|
64
|
-
isModerator
|
65
|
-
};
|
66
|
-
};
|
67
|
-
|
68
|
-
module.exports = middlewareFactory;
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|