@ozdao/prometheus-framework 0.2.23 → 0.2.25
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/auth.server.js +10 -3
- package/dist/auth.server.mjs +10 -3
- package/dist/community.server.js +1 -1
- package/dist/community.server.mjs +1 -1
- package/dist/events.server.js +1 -1
- package/dist/events.server.mjs +1 -1
- package/dist/files.server.js +1 -1
- package/dist/files.server.mjs +1 -1
- package/dist/gallery.server.js +1 -1
- package/dist/gallery.server.mjs +1 -1
- package/dist/globals.server.js +1 -1
- package/dist/globals.server.mjs +1 -1
- package/dist/index-05aa7cae.js +213 -0
- package/dist/index-d5066b82.mjs +214 -0
- package/dist/mailing-2e0de449.js +49 -0
- package/dist/mailing-960a41be.mjs +50 -0
- package/dist/middlewares.server.js +1 -1
- package/dist/middlewares.server.mjs +1 -1
- package/dist/prometheus-framework/src/components/Dropdown/Dropdown.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Dropdown/Dropdown.vue.js +49 -2
- package/dist/prometheus-framework/src/components/Dropdown/Dropdown.vue2.cjs +1 -1
- package/dist/prometheus-framework/src/components/Dropdown/Dropdown.vue2.js +2 -49
- package/dist/prometheus-framework/src/components/Popup/Popup.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Popup/Popup.vue.js +2 -72
- package/dist/prometheus-framework/src/components/Popup/Popup.vue2.cjs +1 -1
- package/dist/prometheus-framework/src/components/Popup/Popup.vue2.js +72 -2
- package/dist/prometheus-framework/src/components/Select/Select.vue.cjs +1 -1
- package/dist/prometheus-framework/src/components/Select/Select.vue.js +2 -78
- package/dist/prometheus-framework/src/components/Select/Select.vue2.cjs +1 -1
- package/dist/prometheus-framework/src/components/Select/Select.vue2.js +78 -2
- package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/auth/components/pages/EnterCode.vue.js +29 -25
- package/dist/prometheus-framework/src/modules/auth/store/twofa.cjs +1 -1
- package/dist/prometheus-framework/src/modules/auth/store/twofa.js +12 -11
- 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/layouts/Community.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/community/components/layouts/Community.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/community/components/pages/CreateBlogPost.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/events/components/layouts/layoutEvents.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/events/components/layouts/layoutEvents.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/EditEvent.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/Events.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/events/components/pages/Events.vue.js +3 -3
- package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/gallery/components/sections/GalleryWithCategories.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/gallery/components/sections/GalleryWithCategories.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 +1 -1
- 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/mobile/components/Menu/Menu.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/mobile/components/Menu/Menu.vue.js +11 -2
- package/dist/prometheus-framework/src/modules/mobile/components/Menu/Menu.vue2.cjs +1 -1
- package/dist/prometheus-framework/src/modules/mobile/components/Menu/Menu.vue2.js +2 -11
- package/dist/prometheus-framework/src/modules/organizations/components/blocks/DepartmentMemberModify.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/blocks/DepartmentMemberModify.vue.js +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.js +2 -2
- 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 +2 -2
- package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.js +2 -2
- 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 +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/organizations/components/sections/Documents.vue.js +1 -1
- 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 +1 -1
- 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 +3 -3
- package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.cjs +1 -1
- package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.js +2 -2
- 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/reports.server.js +1 -1
- package/dist/reports.server.mjs +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/modules/auth/components/pages/EnterCode.vue +81 -62
- package/src/modules/auth/routes/twofa.routes.js +9 -1
- package/src/modules/auth/store/twofa.js +4 -1
- package/src/modules/globals/utils/mailing.js +2 -1
- package/src/modules/middlewares/server/verifyUser.js +1 -0
package/dist/auth.server.js
CHANGED
@@ -6,8 +6,8 @@ const require$$0$1 = require("mongoose");
|
|
6
6
|
const require$$3 = require("uuidv4");
|
7
7
|
const require$$1 = require("node-fetch");
|
8
8
|
const require$$2 = require("jwk-to-pem");
|
9
|
-
const mailing = require("./mailing-
|
10
|
-
const index = require("./index-
|
9
|
+
const mailing = require("./mailing-2e0de449.js");
|
10
|
+
const index = require("./index-05aa7cae.js");
|
11
11
|
require("dotenv");
|
12
12
|
require("nodemailer");
|
13
13
|
require("axios");
|
@@ -450,7 +450,7 @@ const controllerFactory = twofa_controller;
|
|
450
450
|
const middlewareFactory = index.server;
|
451
451
|
var twofa_routes = function(app, db) {
|
452
452
|
const controller = controllerFactory();
|
453
|
-
const { verifySignUp } = middlewareFactory(db);
|
453
|
+
const { verifySignUp, verifyUser } = middlewareFactory(db);
|
454
454
|
app.use(function(req, res, next) {
|
455
455
|
res.header(
|
456
456
|
"Access-Control-Allow-Headers",
|
@@ -466,6 +466,13 @@ var twofa_routes = function(app, db) {
|
|
466
466
|
],
|
467
467
|
controller.sendcode
|
468
468
|
);
|
469
|
+
app.post(
|
470
|
+
"/api/twofa/sendcodereset",
|
471
|
+
[
|
472
|
+
verifyUser.checkUserExist
|
473
|
+
],
|
474
|
+
controller.sendcode
|
475
|
+
);
|
469
476
|
};
|
470
477
|
var role_model = (mongoose) => {
|
471
478
|
const Role = mongoose.model(
|
package/dist/auth.server.mjs
CHANGED
@@ -5,8 +5,8 @@ import require$$0$1 from "mongoose";
|
|
5
5
|
import require$$3 from "uuidv4";
|
6
6
|
import require$$1 from "node-fetch";
|
7
7
|
import require$$2 from "jwk-to-pem";
|
8
|
-
import { m as mailing } from "./mailing-
|
9
|
-
import { s as server } from "./index-
|
8
|
+
import { m as mailing } from "./mailing-960a41be.mjs";
|
9
|
+
import { s as server } from "./index-d5066b82.mjs";
|
10
10
|
import "dotenv";
|
11
11
|
import "nodemailer";
|
12
12
|
import "axios";
|
@@ -449,7 +449,7 @@ const controllerFactory = twofa_controller;
|
|
449
449
|
const middlewareFactory = server;
|
450
450
|
var twofa_routes = function(app, db) {
|
451
451
|
const controller = controllerFactory();
|
452
|
-
const { verifySignUp } = middlewareFactory(db);
|
452
|
+
const { verifySignUp, verifyUser } = middlewareFactory(db);
|
453
453
|
app.use(function(req, res, next) {
|
454
454
|
res.header(
|
455
455
|
"Access-Control-Allow-Headers",
|
@@ -465,6 +465,13 @@ var twofa_routes = function(app, db) {
|
|
465
465
|
],
|
466
466
|
controller.sendcode
|
467
467
|
);
|
468
|
+
app.post(
|
469
|
+
"/api/twofa/sendcodereset",
|
470
|
+
[
|
471
|
+
verifyUser.checkUserExist
|
472
|
+
],
|
473
|
+
controller.sendcode
|
474
|
+
);
|
468
475
|
};
|
469
476
|
var role_model = (mongoose) => {
|
470
477
|
const Role = mongoose.model(
|
package/dist/community.server.js
CHANGED
@@ -4,7 +4,7 @@ const require$$0 = require("mongoose");
|
|
4
4
|
const metadata_schema = require("./metadata.schema-e4fe5c57.js");
|
5
5
|
require("util");
|
6
6
|
require("uuid");
|
7
|
-
const index = require("./index-
|
7
|
+
const index = require("./index-05aa7cae.js");
|
8
8
|
require("jsonwebtoken");
|
9
9
|
require("mongodb");
|
10
10
|
function getPeriodConditions(period) {
|
@@ -3,7 +3,7 @@ import require$$0 from "mongoose";
|
|
3
3
|
import { q as queryProcessor$3, c as common_schema, e as engagement_schema, o as ownership_schema, m as metadata_schema } from "./metadata.schema-a539dd65.mjs";
|
4
4
|
import "util";
|
5
5
|
import "uuid";
|
6
|
-
import { s as server$1 } from "./index-
|
6
|
+
import { s as server$1 } from "./index-d5066b82.mjs";
|
7
7
|
import "jsonwebtoken";
|
8
8
|
import "mongodb";
|
9
9
|
function getPeriodConditions(period) {
|
package/dist/events.server.js
CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const _commonjsHelpers = require("./_commonjsHelpers-3b53548e.js");
|
4
4
|
const require$$0 = require("mongoose");
|
5
5
|
const metadata_schema = require("./metadata.schema-e4fe5c57.js");
|
6
|
-
const index = require("./index-
|
6
|
+
const index = require("./index-05aa7cae.js");
|
7
7
|
require("jsonwebtoken");
|
8
8
|
require("mongodb");
|
9
9
|
const ObjectId = require$$0.Types.ObjectId;
|
package/dist/events.server.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-83b1d755.mjs";
|
2
2
|
import require$$0 from "mongoose";
|
3
3
|
import { q as queryProcessor$2, c as common_schema, e as engagement_schema, o as ownership_schema, m as metadata_schema } from "./metadata.schema-a539dd65.mjs";
|
4
|
-
import { s as server$1 } from "./index-
|
4
|
+
import { s as server$1 } from "./index-d5066b82.mjs";
|
5
5
|
import "jsonwebtoken";
|
6
6
|
import "mongodb";
|
7
7
|
const ObjectId = require$$0.Types.ObjectId;
|
package/dist/files.server.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
const _commonjsHelpers = require("./_commonjsHelpers-3b53548e.js");
|
3
|
-
const index = require("./index-
|
3
|
+
const index = require("./index-05aa7cae.js");
|
4
4
|
const require$$0 = require("sharp");
|
5
5
|
const require$$1 = require("fs");
|
6
6
|
const require$$2 = require("path");
|
package/dist/files.server.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-83b1d755.mjs";
|
2
|
-
import { s as server$1 } from "./index-
|
2
|
+
import { s as server$1 } from "./index-d5066b82.mjs";
|
3
3
|
import require$$0 from "sharp";
|
4
4
|
import require$$1 from "fs";
|
5
5
|
import require$$2 from "path";
|
package/dist/gallery.server.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
const _commonjsHelpers = require("./_commonjsHelpers-3b53548e.js");
|
3
3
|
const require$$2 = require("path");
|
4
|
-
const index = require("./index-
|
4
|
+
const index = require("./index-05aa7cae.js");
|
5
5
|
require("jsonwebtoken");
|
6
6
|
require("mongodb");
|
7
7
|
const path = require$$2;
|
package/dist/gallery.server.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-83b1d755.mjs";
|
2
2
|
import require$$2 from "path";
|
3
|
-
import { s as server } from "./index-
|
3
|
+
import { s as server } from "./index-d5066b82.mjs";
|
4
4
|
import "jsonwebtoken";
|
5
5
|
import "mongodb";
|
6
6
|
const path = require$$2;
|
package/dist/globals.server.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
const _commonjsHelpers = require("./_commonjsHelpers-3b53548e.js");
|
3
3
|
const require$$0 = require("sitemap");
|
4
4
|
const require$$1 = require("zlib");
|
5
|
-
const mailing$1 = require("./mailing-
|
5
|
+
const mailing$1 = require("./mailing-2e0de449.js");
|
6
6
|
require("dotenv");
|
7
7
|
require("nodemailer");
|
8
8
|
require("axios");
|
package/dist/globals.server.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-83b1d755.mjs";
|
2
2
|
import require$$0 from "sitemap";
|
3
3
|
import require$$1 from "zlib";
|
4
|
-
import { m as mailing$1 } from "./mailing-
|
4
|
+
import { m as mailing$1 } from "./mailing-960a41be.mjs";
|
5
5
|
import "dotenv";
|
6
6
|
import "nodemailer";
|
7
7
|
import "axios";
|
@@ -0,0 +1,213 @@
|
|
1
|
+
"use strict";
|
2
|
+
const require$$0 = require("jsonwebtoken");
|
3
|
+
const require$$0$1 = require("mongodb");
|
4
|
+
const jwt = require$$0;
|
5
|
+
const middlewareFactory$4 = (db) => {
|
6
|
+
const User = db.user;
|
7
|
+
const Role = db.role;
|
8
|
+
const verifyToken = async (req, res, next) => {
|
9
|
+
try {
|
10
|
+
console.log(req.cookies);
|
11
|
+
let user = JSON.parse(req.cookies.user);
|
12
|
+
let token = req.headers["x-access-token"] || user.accessToken;
|
13
|
+
if (!token) {
|
14
|
+
return res.status(403).send({ message: "No token provided!" });
|
15
|
+
}
|
16
|
+
const decoded = jwt.verify(token, process.env.SECRET_KEY);
|
17
|
+
req.userId = decoded.id;
|
18
|
+
console.log("success");
|
19
|
+
next();
|
20
|
+
} catch (err) {
|
21
|
+
console.log(err);
|
22
|
+
return res.status(401).send({ message: "Unauthorized!" });
|
23
|
+
}
|
24
|
+
};
|
25
|
+
const checkRole = (roleToCheck) => async (req, res, next) => {
|
26
|
+
try {
|
27
|
+
const user = await User.findById(req.userId).exec();
|
28
|
+
if (!user) {
|
29
|
+
return res.status(404).send({ message: "User Not found." });
|
30
|
+
}
|
31
|
+
const roles = await Role.find({ _id: { $in: user.roles } }).exec();
|
32
|
+
for (let role of roles) {
|
33
|
+
if (role.name === roleToCheck) {
|
34
|
+
next();
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
res.status(403).send({ message: `Require ${roleToCheck} Role!` });
|
39
|
+
} catch (err) {
|
40
|
+
res.status(500).send({ message: err.message });
|
41
|
+
}
|
42
|
+
};
|
43
|
+
const isAdmin = checkRole("admin");
|
44
|
+
const isModerator = checkRole("moderator");
|
45
|
+
return {
|
46
|
+
verifyToken,
|
47
|
+
isAdmin,
|
48
|
+
isModerator
|
49
|
+
};
|
50
|
+
};
|
51
|
+
var authJwt = middlewareFactory$4;
|
52
|
+
const middlewareFactory$3 = (db) => {
|
53
|
+
const User = db.user;
|
54
|
+
db.role;
|
55
|
+
const checkDuplicateUsernameOrEmail = async (req, res, next) => {
|
56
|
+
const { type, email, phone } = req.body;
|
57
|
+
let query;
|
58
|
+
if (type === "phone" && phone) {
|
59
|
+
query = { phone };
|
60
|
+
}
|
61
|
+
if (type === "email" && email) {
|
62
|
+
query = { email };
|
63
|
+
}
|
64
|
+
try {
|
65
|
+
const user = await User.findOne(query).exec();
|
66
|
+
if (user) {
|
67
|
+
res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
next();
|
71
|
+
} catch (err) {
|
72
|
+
console.log(err);
|
73
|
+
res.status(500).send({ message: err.message });
|
74
|
+
}
|
75
|
+
};
|
76
|
+
const checkRolesExisted = (req, res, next) => {
|
77
|
+
if (req.body.roles) {
|
78
|
+
for (let i = 0; i < req.body.roles.length; i++) {
|
79
|
+
if (!ROLES.includes(req.body.roles[i])) {
|
80
|
+
res.status(400).send({
|
81
|
+
message: `Failed! Role ${req.body.roles[i]} does not exist!`
|
82
|
+
});
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
next();
|
88
|
+
};
|
89
|
+
return {
|
90
|
+
checkDuplicateUsernameOrEmail,
|
91
|
+
checkRolesExisted
|
92
|
+
};
|
93
|
+
};
|
94
|
+
var verifySignUp = middlewareFactory$3;
|
95
|
+
const middlewareFactory$2 = (db) => {
|
96
|
+
const User = db.user;
|
97
|
+
db.role;
|
98
|
+
const checkUserExist = async (req, res, next) => {
|
99
|
+
const { type, email, phone } = req.body;
|
100
|
+
let query;
|
101
|
+
if (type === "phone" && phone) {
|
102
|
+
query = { phone };
|
103
|
+
}
|
104
|
+
if (type === "email" && email) {
|
105
|
+
query = { email };
|
106
|
+
}
|
107
|
+
try {
|
108
|
+
const user = await User.findOne(query).exec();
|
109
|
+
if (!user) {
|
110
|
+
console.log(query);
|
111
|
+
res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
next();
|
115
|
+
} catch (err) {
|
116
|
+
res.status(500).send({ message: err.message });
|
117
|
+
}
|
118
|
+
};
|
119
|
+
return {
|
120
|
+
checkUserExist
|
121
|
+
};
|
122
|
+
};
|
123
|
+
var verifyUser = middlewareFactory$2;
|
124
|
+
const { ObjectId } = require$$0$1;
|
125
|
+
const middlewareFactory$1 = (db) => {
|
126
|
+
const User = db.user;
|
127
|
+
const Invite = db.invite;
|
128
|
+
const Membership = db.membership;
|
129
|
+
const checkInviteExist = async (req, res, next) => {
|
130
|
+
for (let invite of req.body) {
|
131
|
+
let query;
|
132
|
+
if (invite.contact.includes("@")) {
|
133
|
+
query = { invitedEmail: invite.contact };
|
134
|
+
} else {
|
135
|
+
query = { invitedPhone: invite.contact };
|
136
|
+
}
|
137
|
+
query.organization = req.params._id;
|
138
|
+
const userInvite = await Invite.findOne(query).exec();
|
139
|
+
if (userInvite) {
|
140
|
+
console.log(userInvite);
|
141
|
+
res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
next();
|
146
|
+
};
|
147
|
+
const checkUsersExist = async (req, res, next) => {
|
148
|
+
for (let invite of req.body) {
|
149
|
+
let query;
|
150
|
+
if (invite.contact.includes("@")) {
|
151
|
+
query = { email: invite.contact };
|
152
|
+
} else {
|
153
|
+
query = { phone: invite.contact };
|
154
|
+
}
|
155
|
+
const user = await User.findOne(query).exec();
|
156
|
+
console.log(req.params);
|
157
|
+
if (user) {
|
158
|
+
const membership = await Membership.findOne({ user: new ObjectId(user._id), organization: req.params._id }).exec();
|
159
|
+
if (membership) {
|
160
|
+
console.log(membership);
|
161
|
+
res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
next();
|
167
|
+
};
|
168
|
+
return {
|
169
|
+
checkInviteExist,
|
170
|
+
checkUsersExist
|
171
|
+
};
|
172
|
+
};
|
173
|
+
var verifyInvites = middlewareFactory$1;
|
174
|
+
const middlewareFactory = (db) => {
|
175
|
+
const Category = db.category;
|
176
|
+
const checkCategoryExistOrNot = async (req, res, next) => {
|
177
|
+
try {
|
178
|
+
const category = await Category.findOne({ url: req.body.url });
|
179
|
+
if (category) {
|
180
|
+
res.status(400).send({ message: "Failed! Category with this URL is already in use!" });
|
181
|
+
return;
|
182
|
+
}
|
183
|
+
next();
|
184
|
+
} catch (err) {
|
185
|
+
res.status(500).send({ message: err });
|
186
|
+
}
|
187
|
+
};
|
188
|
+
return {
|
189
|
+
checkCategoryExistOrNot
|
190
|
+
};
|
191
|
+
};
|
192
|
+
var verifyCategory = middlewareFactory;
|
193
|
+
const middlewareIndexFactory = (db) => {
|
194
|
+
const authJwt$1 = authJwt(db);
|
195
|
+
const verifySignUp$1 = verifySignUp(db);
|
196
|
+
const verifyUser$1 = verifyUser(db);
|
197
|
+
const verifyInvites$1 = verifyInvites(db);
|
198
|
+
const verifyCategory$1 = verifyCategory(db);
|
199
|
+
return {
|
200
|
+
authJwt: authJwt$1,
|
201
|
+
verifySignUp: verifySignUp$1,
|
202
|
+
verifyUser: verifyUser$1,
|
203
|
+
verifyInvites: verifyInvites$1,
|
204
|
+
verifyCategory: verifyCategory$1
|
205
|
+
};
|
206
|
+
};
|
207
|
+
var server = middlewareIndexFactory;
|
208
|
+
exports.authJwt = authJwt;
|
209
|
+
exports.server = server;
|
210
|
+
exports.verifyCategory = verifyCategory;
|
211
|
+
exports.verifyInvites = verifyInvites;
|
212
|
+
exports.verifySignUp = verifySignUp;
|
213
|
+
exports.verifyUser = verifyUser;
|
@@ -0,0 +1,214 @@
|
|
1
|
+
import require$$0 from "jsonwebtoken";
|
2
|
+
import require$$0$1 from "mongodb";
|
3
|
+
const jwt = require$$0;
|
4
|
+
const middlewareFactory$4 = (db) => {
|
5
|
+
const User = db.user;
|
6
|
+
const Role = db.role;
|
7
|
+
const verifyToken = async (req, res, next) => {
|
8
|
+
try {
|
9
|
+
console.log(req.cookies);
|
10
|
+
let user = JSON.parse(req.cookies.user);
|
11
|
+
let token = req.headers["x-access-token"] || user.accessToken;
|
12
|
+
if (!token) {
|
13
|
+
return res.status(403).send({ message: "No token provided!" });
|
14
|
+
}
|
15
|
+
const decoded = jwt.verify(token, process.env.SECRET_KEY);
|
16
|
+
req.userId = decoded.id;
|
17
|
+
console.log("success");
|
18
|
+
next();
|
19
|
+
} catch (err) {
|
20
|
+
console.log(err);
|
21
|
+
return res.status(401).send({ message: "Unauthorized!" });
|
22
|
+
}
|
23
|
+
};
|
24
|
+
const checkRole = (roleToCheck) => async (req, res, next) => {
|
25
|
+
try {
|
26
|
+
const user = await User.findById(req.userId).exec();
|
27
|
+
if (!user) {
|
28
|
+
return res.status(404).send({ message: "User Not found." });
|
29
|
+
}
|
30
|
+
const roles = await Role.find({ _id: { $in: user.roles } }).exec();
|
31
|
+
for (let role of roles) {
|
32
|
+
if (role.name === roleToCheck) {
|
33
|
+
next();
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
res.status(403).send({ message: `Require ${roleToCheck} Role!` });
|
38
|
+
} catch (err) {
|
39
|
+
res.status(500).send({ message: err.message });
|
40
|
+
}
|
41
|
+
};
|
42
|
+
const isAdmin = checkRole("admin");
|
43
|
+
const isModerator = checkRole("moderator");
|
44
|
+
return {
|
45
|
+
verifyToken,
|
46
|
+
isAdmin,
|
47
|
+
isModerator
|
48
|
+
};
|
49
|
+
};
|
50
|
+
var authJwt = middlewareFactory$4;
|
51
|
+
const middlewareFactory$3 = (db) => {
|
52
|
+
const User = db.user;
|
53
|
+
db.role;
|
54
|
+
const checkDuplicateUsernameOrEmail = async (req, res, next) => {
|
55
|
+
const { type, email, phone } = req.body;
|
56
|
+
let query;
|
57
|
+
if (type === "phone" && phone) {
|
58
|
+
query = { phone };
|
59
|
+
}
|
60
|
+
if (type === "email" && email) {
|
61
|
+
query = { email };
|
62
|
+
}
|
63
|
+
try {
|
64
|
+
const user = await User.findOne(query).exec();
|
65
|
+
if (user) {
|
66
|
+
res.status(400).send({ errorCode: "USER_ALREADY_REGISTERED" });
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
next();
|
70
|
+
} catch (err) {
|
71
|
+
console.log(err);
|
72
|
+
res.status(500).send({ message: err.message });
|
73
|
+
}
|
74
|
+
};
|
75
|
+
const checkRolesExisted = (req, res, next) => {
|
76
|
+
if (req.body.roles) {
|
77
|
+
for (let i = 0; i < req.body.roles.length; i++) {
|
78
|
+
if (!ROLES.includes(req.body.roles[i])) {
|
79
|
+
res.status(400).send({
|
80
|
+
message: `Failed! Role ${req.body.roles[i]} does not exist!`
|
81
|
+
});
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
next();
|
87
|
+
};
|
88
|
+
return {
|
89
|
+
checkDuplicateUsernameOrEmail,
|
90
|
+
checkRolesExisted
|
91
|
+
};
|
92
|
+
};
|
93
|
+
var verifySignUp = middlewareFactory$3;
|
94
|
+
const middlewareFactory$2 = (db) => {
|
95
|
+
const User = db.user;
|
96
|
+
db.role;
|
97
|
+
const checkUserExist = async (req, res, next) => {
|
98
|
+
const { type, email, phone } = req.body;
|
99
|
+
let query;
|
100
|
+
if (type === "phone" && phone) {
|
101
|
+
query = { phone };
|
102
|
+
}
|
103
|
+
if (type === "email" && email) {
|
104
|
+
query = { email };
|
105
|
+
}
|
106
|
+
try {
|
107
|
+
const user = await User.findOne(query).exec();
|
108
|
+
if (!user) {
|
109
|
+
console.log(query);
|
110
|
+
res.status(400).send({ errorCode: "USER_NOT_REGISTERED_YET" });
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
next();
|
114
|
+
} catch (err) {
|
115
|
+
res.status(500).send({ message: err.message });
|
116
|
+
}
|
117
|
+
};
|
118
|
+
return {
|
119
|
+
checkUserExist
|
120
|
+
};
|
121
|
+
};
|
122
|
+
var verifyUser = middlewareFactory$2;
|
123
|
+
const { ObjectId } = require$$0$1;
|
124
|
+
const middlewareFactory$1 = (db) => {
|
125
|
+
const User = db.user;
|
126
|
+
const Invite = db.invite;
|
127
|
+
const Membership = db.membership;
|
128
|
+
const checkInviteExist = async (req, res, next) => {
|
129
|
+
for (let invite of req.body) {
|
130
|
+
let query;
|
131
|
+
if (invite.contact.includes("@")) {
|
132
|
+
query = { invitedEmail: invite.contact };
|
133
|
+
} else {
|
134
|
+
query = { invitedPhone: invite.contact };
|
135
|
+
}
|
136
|
+
query.organization = req.params._id;
|
137
|
+
const userInvite = await Invite.findOne(query).exec();
|
138
|
+
if (userInvite) {
|
139
|
+
console.log(userInvite);
|
140
|
+
res.status(400).send({ message: "Инвайт c таким email или телефоном уже создан!" });
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
next();
|
145
|
+
};
|
146
|
+
const checkUsersExist = async (req, res, next) => {
|
147
|
+
for (let invite of req.body) {
|
148
|
+
let query;
|
149
|
+
if (invite.contact.includes("@")) {
|
150
|
+
query = { email: invite.contact };
|
151
|
+
} else {
|
152
|
+
query = { phone: invite.contact };
|
153
|
+
}
|
154
|
+
const user = await User.findOne(query).exec();
|
155
|
+
console.log(req.params);
|
156
|
+
if (user) {
|
157
|
+
const membership = await Membership.findOne({ user: new ObjectId(user._id), organization: req.params._id }).exec();
|
158
|
+
if (membership) {
|
159
|
+
console.log(membership);
|
160
|
+
res.status(400).send({ message: "Пользователь с таким email или телефоном уже добавлен в организацию!" });
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
next();
|
166
|
+
};
|
167
|
+
return {
|
168
|
+
checkInviteExist,
|
169
|
+
checkUsersExist
|
170
|
+
};
|
171
|
+
};
|
172
|
+
var verifyInvites = middlewareFactory$1;
|
173
|
+
const middlewareFactory = (db) => {
|
174
|
+
const Category = db.category;
|
175
|
+
const checkCategoryExistOrNot = async (req, res, next) => {
|
176
|
+
try {
|
177
|
+
const category = await Category.findOne({ url: req.body.url });
|
178
|
+
if (category) {
|
179
|
+
res.status(400).send({ message: "Failed! Category with this URL is already in use!" });
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
next();
|
183
|
+
} catch (err) {
|
184
|
+
res.status(500).send({ message: err });
|
185
|
+
}
|
186
|
+
};
|
187
|
+
return {
|
188
|
+
checkCategoryExistOrNot
|
189
|
+
};
|
190
|
+
};
|
191
|
+
var verifyCategory = middlewareFactory;
|
192
|
+
const middlewareIndexFactory = (db) => {
|
193
|
+
const authJwt$1 = authJwt(db);
|
194
|
+
const verifySignUp$1 = verifySignUp(db);
|
195
|
+
const verifyUser$1 = verifyUser(db);
|
196
|
+
const verifyInvites$1 = verifyInvites(db);
|
197
|
+
const verifyCategory$1 = verifyCategory(db);
|
198
|
+
return {
|
199
|
+
authJwt: authJwt$1,
|
200
|
+
verifySignUp: verifySignUp$1,
|
201
|
+
verifyUser: verifyUser$1,
|
202
|
+
verifyInvites: verifyInvites$1,
|
203
|
+
verifyCategory: verifyCategory$1
|
204
|
+
};
|
205
|
+
};
|
206
|
+
var server = middlewareIndexFactory;
|
207
|
+
export {
|
208
|
+
verifyInvites as a,
|
209
|
+
authJwt as b,
|
210
|
+
verifySignUp as c,
|
211
|
+
verifyCategory as d,
|
212
|
+
server as s,
|
213
|
+
verifyUser as v
|
214
|
+
};
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
const require$$0 = require("dotenv");
|
3
|
+
const require$$1 = require("nodemailer");
|
4
|
+
const require$$2 = require("axios");
|
5
|
+
require$$0.config();
|
6
|
+
const nodemailer = require$$1;
|
7
|
+
const axios = require$$2;
|
8
|
+
async function sendEmail(to, subject, text) {
|
9
|
+
const transporter = nodemailer.createTransport({
|
10
|
+
host: process.env.SMTP_HOST,
|
11
|
+
port: process.env.SMTP_PORT,
|
12
|
+
secure: process.env.SMTP_SECURE,
|
13
|
+
auth: {
|
14
|
+
user: process.env.SMTP_USER,
|
15
|
+
pass: process.env.SMTP_PASSWORD
|
16
|
+
}
|
17
|
+
});
|
18
|
+
const mailOptions = {
|
19
|
+
from: `${process.env.SMTP_NAME} <${process.env.SMTP_EMAIL}>`,
|
20
|
+
to,
|
21
|
+
subject,
|
22
|
+
text
|
23
|
+
};
|
24
|
+
try {
|
25
|
+
const info = await transporter.sendMail(mailOptions);
|
26
|
+
console.log("Email sent: " + info.response);
|
27
|
+
return true;
|
28
|
+
} catch (error) {
|
29
|
+
console.log(error);
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
async function sendSms(phone, message) {
|
34
|
+
const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&bypass_optout=true&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${encodeURIComponent(process.env.APP_NAME)}`;
|
35
|
+
console.log(`Phone:${phone} message:${message} session: ${sessionUrl}`);
|
36
|
+
try {
|
37
|
+
const response = await axios.get(sessionUrl);
|
38
|
+
console.log("SMS sent");
|
39
|
+
return true;
|
40
|
+
} catch (error) {
|
41
|
+
console.log(error);
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
var mailing = {
|
46
|
+
sendEmail,
|
47
|
+
sendSms
|
48
|
+
};
|
49
|
+
exports.mailing = mailing;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import require$$0 from "dotenv";
|
2
|
+
import require$$1 from "nodemailer";
|
3
|
+
import require$$2 from "axios";
|
4
|
+
require$$0.config();
|
5
|
+
const nodemailer = require$$1;
|
6
|
+
const axios = require$$2;
|
7
|
+
async function sendEmail(to, subject, text) {
|
8
|
+
const transporter = nodemailer.createTransport({
|
9
|
+
host: process.env.SMTP_HOST,
|
10
|
+
port: process.env.SMTP_PORT,
|
11
|
+
secure: process.env.SMTP_SECURE,
|
12
|
+
auth: {
|
13
|
+
user: process.env.SMTP_USER,
|
14
|
+
pass: process.env.SMTP_PASSWORD
|
15
|
+
}
|
16
|
+
});
|
17
|
+
const mailOptions = {
|
18
|
+
from: `${process.env.SMTP_NAME} <${process.env.SMTP_EMAIL}>`,
|
19
|
+
to,
|
20
|
+
subject,
|
21
|
+
text
|
22
|
+
};
|
23
|
+
try {
|
24
|
+
const info = await transporter.sendMail(mailOptions);
|
25
|
+
console.log("Email sent: " + info.response);
|
26
|
+
return true;
|
27
|
+
} catch (error) {
|
28
|
+
console.log(error);
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
async function sendSms(phone, message) {
|
33
|
+
const sessionUrl = `https://api.sms.to/sms/send?api_key=${process.env.SMS_API_KEY}&bypass_optout=true&to=${phone}&message=${encodeURIComponent(message)}&sender_id=${encodeURIComponent(process.env.APP_NAME)}`;
|
34
|
+
console.log(`Phone:${phone} message:${message} session: ${sessionUrl}`);
|
35
|
+
try {
|
36
|
+
const response = await axios.get(sessionUrl);
|
37
|
+
console.log("SMS sent");
|
38
|
+
return true;
|
39
|
+
} catch (error) {
|
40
|
+
console.log(error);
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
var mailing = {
|
45
|
+
sendEmail,
|
46
|
+
sendSms
|
47
|
+
};
|
48
|
+
export {
|
49
|
+
mailing as m
|
50
|
+
};
|