@resolveio/server-lib 9.0.32 → 9.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-server-app.js +7 -48
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +8 -11
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +8 -11
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +8 -11
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +9 -12
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +8 -11
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +8 -11
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +9 -12
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +8 -11
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +8 -11
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +11 -14
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +13 -16
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +16 -19
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +9 -12
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +10 -13
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +10 -13
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +13 -16
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +13 -16
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +15 -18
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +12 -15
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +12 -15
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +8 -11
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +9 -12
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +9 -12
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +9 -12
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +10 -13
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +11 -14
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +11 -14
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +11 -14
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +8 -11
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +12 -15
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +30 -80
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +9 -59
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +344 -460
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -5
- package/http/health.js.map +1 -1
- package/http/home.js +7 -11
- package/http/home.js.map +1 -1
- package/index.js +36 -98
- package/index.js.map +1 -1
- package/managers/cron.manager.js +78 -157
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +323 -303
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +14 -14
- package/managers/mongo.manager.js +794 -865
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +171 -254
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +69 -166
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +515 -708
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +111 -183
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +156 -262
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +100 -180
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +114 -530
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +29 -79
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +819 -884
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -5
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +258 -313
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +289 -348
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +341 -340
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +565 -657
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +67 -185
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/billing-logged-in-users.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/email-history.model.js +1 -2
- package/models/email-verified.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log-method-latency.model.js +1 -2
- package/models/log-subscription.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/monitor-cpu.model.js +1 -2
- package/models/monitor-https-inbound.model.js +1 -2
- package/models/monitor-https-outbound.model.js +1 -2
- package/models/monitor-memory.model.js +1 -2
- package/models/monitor-mongo.model.js +1 -2
- package/models/notification.model.js +1 -2
- package/models/pagination.model.js +2 -5
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/report-builder-dashboard-builder.model.js +1 -2
- package/models/report-builder-library.model.js +1 -2
- package/models/report-builder-report.model.js +1 -2
- package/models/report-builder.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user-group.model.js +1 -2
- package/models/user-guide.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +1 -1
- package/public_api.js +70 -82
- package/public_api.js.map +1 -1
- package/publications/app-status.js +4 -8
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +4 -8
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +9 -13
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +11 -15
- package/publications/files.js.map +1 -1
- package/publications/flags.js +7 -11
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +31 -35
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +4 -8
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +4 -8
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +4 -8
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +8 -12
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +16 -66
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +17 -21
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +3 -7
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +4 -8
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +4 -8
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +393 -534
- package/server-app.js.map +1 -1
- package/util/common.js +55 -92
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +76 -134
- package/util/schema-report-builder.js.map +1 -1
package/http/auth.js
CHANGED
|
@@ -1,159 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.setupAuthRoutes = void 0;
|
|
40
|
-
var user_collection_1 = require("../collections/user.collection");
|
|
41
|
-
var jwt = require("jsonwebtoken");
|
|
42
|
-
var handlebars = require("handlebars");
|
|
43
|
-
var __1 = require("..");
|
|
44
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
45
|
-
function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
46
|
-
var _this = this;
|
|
1
|
+
import { Users } from '../collections/user.collection';
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
3
|
+
import * as handlebars from 'handlebars';
|
|
4
|
+
import { ResolveIOServer } from '..';
|
|
5
|
+
import SimpleSchema from 'simpl-schema';
|
|
6
|
+
export function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
47
7
|
// Login via HTTP, return refresh token if authenticated
|
|
48
|
-
app.post('/login',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
8
|
+
app.post('/login', async (request, response) => {
|
|
9
|
+
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {
|
|
10
|
+
response.send(JSON.stringify({
|
|
11
|
+
error: true,
|
|
12
|
+
result: 'Invalid header'
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
let body = request.body;
|
|
17
|
+
let schema = new SimpleSchema({
|
|
18
|
+
username: {
|
|
19
|
+
type: String
|
|
20
|
+
},
|
|
21
|
+
password: {
|
|
22
|
+
type: String
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
schema.validate(body);
|
|
27
|
+
}
|
|
28
|
+
catch (errors) {
|
|
29
|
+
if (errors) {
|
|
30
|
+
console.error('Error in HTTP Check (/login)', errors);
|
|
31
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/login' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
54
32
|
response.send(JSON.stringify({
|
|
55
33
|
error: true,
|
|
56
|
-
result: 'Invalid
|
|
34
|
+
result: 'Invalid Parameters'
|
|
57
35
|
}));
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
error: true,
|
|
127
|
-
result: 'A password reset link has been sent to your email, please reset your password.'
|
|
128
|
-
}));
|
|
129
|
-
user_1.services['forgot_password'] = jwt.sign({ id_user: user_1._id }, serverConfig['JWT_SECRET']);
|
|
130
|
-
emailData_2 = {
|
|
131
|
-
userToChangePassword: user_1.fullname,
|
|
132
|
-
userWhoResetPassword: __1.ResolveIOServer.getClientName() + ' System',
|
|
133
|
-
url: serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user_1.services['forgot_password']
|
|
134
|
-
};
|
|
135
|
-
user_collection_1.Users.updateOne({ _id: user_1._id }, { $set: { services: user_1.services } }).then(function (resUp) {
|
|
136
|
-
mainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(function (html) {
|
|
137
|
-
var template = handlebars.compile(html);
|
|
138
|
-
handlebars.registerHelper('equals', function (a, b) {
|
|
139
|
-
return a === b;
|
|
140
|
-
});
|
|
141
|
-
mainServer.getMethodManager().sendEmail(user_1.email, 'ResolveIO (' + __1.ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData_2));
|
|
142
|
-
}, function (errEmail) { return console.log(errEmail); });
|
|
143
|
-
}, function (err) { });
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
response.send(JSON.stringify({
|
|
147
|
-
error: true,
|
|
148
|
-
result: resAuth['error']
|
|
149
|
-
}));
|
|
150
|
-
}
|
|
151
|
-
return [3 /*break*/, 8];
|
|
152
|
-
case 6:
|
|
153
|
-
if (!(resAuth && resAuth['data'] && resAuth['data'].active)) return [3 /*break*/, 8];
|
|
154
|
-
return [4 /*yield*/, user_collection_1.Users.resetAttempts(resAuth['data'])];
|
|
155
|
-
case 7:
|
|
156
|
-
_a.sent();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let user = await Users.findOne({ username: body.username });
|
|
40
|
+
if (!user) {
|
|
41
|
+
user = await Users.findOne({ email: body.username });
|
|
42
|
+
}
|
|
43
|
+
if (!user) {
|
|
44
|
+
response.send(JSON.stringify({
|
|
45
|
+
error: true,
|
|
46
|
+
result: 'Invalid Username And Password'
|
|
47
|
+
}));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let resAuth = await Users.authenticate(user, body.password);
|
|
51
|
+
if (resAuth['error']) {
|
|
52
|
+
if (resAuth['error'] === 'Too Many Attempts') {
|
|
53
|
+
response.send(JSON.stringify({
|
|
54
|
+
error: true,
|
|
55
|
+
result: resAuth['error'] + '. A password reset link has been sent to your email, please reset your password.'
|
|
56
|
+
}));
|
|
57
|
+
user.services['forgot_password'] = jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET']);
|
|
58
|
+
let emailData = {
|
|
59
|
+
userToChangePassword: user.fullname,
|
|
60
|
+
userWhoResetPassword: ResolveIOServer.getClientName() + ' System',
|
|
61
|
+
url: serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password']
|
|
62
|
+
};
|
|
63
|
+
Users.updateOne({ _id: user._id }, { $set: { services: user.services } }).then(resUp => {
|
|
64
|
+
mainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(html => {
|
|
65
|
+
let template = handlebars.compile(html);
|
|
66
|
+
handlebars.registerHelper('equals', (a, b) => {
|
|
67
|
+
return a === b;
|
|
68
|
+
});
|
|
69
|
+
mainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData));
|
|
70
|
+
}, errEmail => console.log(errEmail));
|
|
71
|
+
}, errUp => { });
|
|
72
|
+
}
|
|
73
|
+
else if (resAuth['error'] === 'No Salt Value Stored') {
|
|
74
|
+
response.send(JSON.stringify({
|
|
75
|
+
error: true,
|
|
76
|
+
result: 'A password reset link has been sent to your email, please reset your password.'
|
|
77
|
+
}));
|
|
78
|
+
user.services['forgot_password'] = jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET']);
|
|
79
|
+
let emailData = {
|
|
80
|
+
userToChangePassword: user.fullname,
|
|
81
|
+
userWhoResetPassword: ResolveIOServer.getClientName() + ' System',
|
|
82
|
+
url: serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user.services['forgot_password']
|
|
83
|
+
};
|
|
84
|
+
Users.updateOne({ _id: user._id }, { $set: { services: user.services } }).then(resUp => {
|
|
85
|
+
mainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(html => {
|
|
86
|
+
let template = handlebars.compile(html);
|
|
87
|
+
handlebars.registerHelper('equals', (a, b) => {
|
|
88
|
+
return a === b;
|
|
89
|
+
});
|
|
90
|
+
mainServer.getMethodManager().sendEmail(user.email, 'ResolveIO (' + ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData));
|
|
91
|
+
}, errEmail => console.log(errEmail));
|
|
92
|
+
}, err => { });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
response.send(JSON.stringify({
|
|
96
|
+
error: true,
|
|
97
|
+
result: resAuth['error']
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (resAuth && resAuth['data'] && resAuth['data'].active) {
|
|
103
|
+
await Users.resetAttempts(resAuth['data']);
|
|
157
104
|
response.send(JSON.stringify({
|
|
158
105
|
error: false,
|
|
159
106
|
result: {
|
|
@@ -162,156 +109,132 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
162
109
|
})
|
|
163
110
|
}
|
|
164
111
|
}));
|
|
165
|
-
|
|
166
|
-
case 8: return [2 /*return*/];
|
|
112
|
+
}
|
|
167
113
|
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
app.post('/accessToken', function (request, response) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
app.post('/accessToken', async function (request, response) {
|
|
117
|
+
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
118
|
+
response.send(JSON.stringify({
|
|
119
|
+
error: true,
|
|
120
|
+
result: 'Invalid header'
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
let body = request.body;
|
|
125
|
+
let schema = new SimpleSchema({
|
|
126
|
+
refreshToken: {
|
|
127
|
+
type: String
|
|
128
|
+
},
|
|
129
|
+
appVersion: {
|
|
130
|
+
type: Number
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
schema.validate(body);
|
|
135
|
+
}
|
|
136
|
+
catch (errors) {
|
|
137
|
+
if (errors) {
|
|
138
|
+
console.error('Error in HTTP Check (/accessToken)', errors);
|
|
139
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/accessToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
176
140
|
response.send(JSON.stringify({
|
|
177
141
|
error: true,
|
|
178
|
-
result: 'Invalid
|
|
142
|
+
result: 'Invalid Parameters'
|
|
179
143
|
}));
|
|
144
|
+
return;
|
|
180
145
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
try {
|
|
192
|
-
schema.validate(body);
|
|
193
|
-
}
|
|
194
|
-
catch (errors) {
|
|
195
|
-
if (errors) {
|
|
196
|
-
console.error('Error in HTTP Check (/accessToken)', errors);
|
|
197
|
-
__1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/accessToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
198
|
-
response.send(JSON.stringify({
|
|
199
|
-
error: true,
|
|
200
|
-
result: 'Invalid Parameters'
|
|
201
|
-
}));
|
|
202
|
-
return [2 /*return*/];
|
|
203
|
-
}
|
|
146
|
+
}
|
|
147
|
+
if (serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
148
|
+
jwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], (err, decoded) => {
|
|
149
|
+
if (err) {
|
|
150
|
+
response.send(JSON.stringify({
|
|
151
|
+
error: true,
|
|
152
|
+
result: 'Invalid Token'
|
|
153
|
+
}));
|
|
204
154
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
case 0:
|
|
218
|
-
if (!user) return [3 /*break*/, 4];
|
|
219
|
-
if (!user.active) return [3 /*break*/, 2];
|
|
220
|
-
return [4 /*yield*/, user_collection_1.Users.resetAttempts(user)];
|
|
221
|
-
case 1:
|
|
222
|
-
_a.sent();
|
|
223
|
-
response.send(JSON.stringify({
|
|
224
|
-
error: false,
|
|
225
|
-
result: {
|
|
226
|
-
token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
|
|
227
|
-
expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
|
|
228
|
-
}),
|
|
229
|
-
user: user
|
|
230
|
-
}
|
|
231
|
-
}));
|
|
232
|
-
return [3 /*break*/, 3];
|
|
233
|
-
case 2:
|
|
234
|
-
response.send(JSON.stringify({
|
|
235
|
-
error: true,
|
|
236
|
-
result: 'Account is Disabled'
|
|
237
|
-
}));
|
|
238
|
-
_a.label = 3;
|
|
239
|
-
case 3: return [3 /*break*/, 5];
|
|
240
|
-
case 4:
|
|
241
|
-
response.send(JSON.stringify({
|
|
242
|
-
error: true,
|
|
243
|
-
result: 'Invalid User'
|
|
244
|
-
}));
|
|
245
|
-
_a.label = 5;
|
|
246
|
-
case 5: return [2 /*return*/];
|
|
155
|
+
else {
|
|
156
|
+
Users.findById(decoded['id_user']).then(async (user) => {
|
|
157
|
+
if (user) {
|
|
158
|
+
if (user.active) {
|
|
159
|
+
await Users.resetAttempts(user);
|
|
160
|
+
response.send(JSON.stringify({
|
|
161
|
+
error: false,
|
|
162
|
+
result: {
|
|
163
|
+
token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
|
|
164
|
+
expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
|
|
165
|
+
}),
|
|
166
|
+
user: user
|
|
247
167
|
}
|
|
248
|
-
});
|
|
249
|
-
}
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
250
171
|
response.send(JSON.stringify({
|
|
251
172
|
error: true,
|
|
252
|
-
result: '
|
|
173
|
+
result: 'Account is Disabled'
|
|
253
174
|
}));
|
|
254
|
-
}
|
|
175
|
+
}
|
|
255
176
|
}
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
jwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], function (err, decoded) {
|
|
260
|
-
if (err) {
|
|
177
|
+
else {
|
|
261
178
|
response.send(JSON.stringify({
|
|
262
179
|
error: true,
|
|
263
|
-
result: 'Invalid
|
|
180
|
+
result: 'Invalid User'
|
|
264
181
|
}));
|
|
265
182
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
error: true,
|
|
296
|
-
result: 'Invalid User'
|
|
297
|
-
}));
|
|
298
|
-
_a.label = 5;
|
|
299
|
-
case 5: return [2 /*return*/];
|
|
183
|
+
}, error => {
|
|
184
|
+
response.send(JSON.stringify({
|
|
185
|
+
error: true,
|
|
186
|
+
result: 'Invalid Mongo Get User'
|
|
187
|
+
}));
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
jwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], (err, decoded) => {
|
|
194
|
+
if (err) {
|
|
195
|
+
response.send(JSON.stringify({
|
|
196
|
+
error: true,
|
|
197
|
+
result: 'Invalid Token'
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
Users.findById(decoded['id_user']).then(async (user) => {
|
|
202
|
+
if (user) {
|
|
203
|
+
if (user.active) {
|
|
204
|
+
await Users.resetAttempts(user);
|
|
205
|
+
response.send(JSON.stringify({
|
|
206
|
+
error: false,
|
|
207
|
+
result: {
|
|
208
|
+
token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
|
|
209
|
+
expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
|
|
210
|
+
}),
|
|
211
|
+
user: user
|
|
300
212
|
}
|
|
301
|
-
});
|
|
302
|
-
}
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
303
216
|
response.send(JSON.stringify({
|
|
304
217
|
error: true,
|
|
305
|
-
result: '
|
|
218
|
+
result: 'Account is Disabled'
|
|
306
219
|
}));
|
|
307
|
-
}
|
|
220
|
+
}
|
|
308
221
|
}
|
|
222
|
+
else {
|
|
223
|
+
response.send(JSON.stringify({
|
|
224
|
+
error: true,
|
|
225
|
+
result: 'Invalid User'
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
}, error => {
|
|
229
|
+
response.send(JSON.stringify({
|
|
230
|
+
error: true,
|
|
231
|
+
result: 'Invalid Mongo Get User'
|
|
232
|
+
}));
|
|
309
233
|
});
|
|
310
234
|
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
315
238
|
});
|
|
316
239
|
app.post('/userWithEnrollmentToken', function (request, response) {
|
|
317
240
|
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
@@ -321,19 +244,19 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
321
244
|
}));
|
|
322
245
|
}
|
|
323
246
|
else {
|
|
324
|
-
|
|
325
|
-
|
|
247
|
+
let body = request.body;
|
|
248
|
+
let schema = new SimpleSchema({
|
|
326
249
|
enrollmentToken: {
|
|
327
250
|
type: String
|
|
328
251
|
}
|
|
329
252
|
});
|
|
330
253
|
try {
|
|
331
|
-
schema.validate(
|
|
254
|
+
schema.validate(body);
|
|
332
255
|
}
|
|
333
256
|
catch (errors) {
|
|
334
257
|
if (errors) {
|
|
335
258
|
console.error('Error in HTTP Check (/userWithEnrollmentToken)', errors);
|
|
336
|
-
|
|
259
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithEnrollmentToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
337
260
|
response.send(JSON.stringify({
|
|
338
261
|
error: true,
|
|
339
262
|
result: 'Invalid Parameters'
|
|
@@ -341,7 +264,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
341
264
|
return;
|
|
342
265
|
}
|
|
343
266
|
}
|
|
344
|
-
jwt.verify(
|
|
267
|
+
jwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], (err, decoded) => {
|
|
345
268
|
if (err) {
|
|
346
269
|
response.send(JSON.stringify({
|
|
347
270
|
error: true,
|
|
@@ -349,12 +272,12 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
349
272
|
}));
|
|
350
273
|
}
|
|
351
274
|
else {
|
|
352
|
-
|
|
275
|
+
Users.findOne({
|
|
353
276
|
$and: [
|
|
354
277
|
{ _id: decoded['id_user'] },
|
|
355
|
-
{ 'services.enrollment':
|
|
278
|
+
{ 'services.enrollment': body.enrollmentToken }
|
|
356
279
|
]
|
|
357
|
-
}, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(
|
|
280
|
+
}, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then((user) => {
|
|
358
281
|
if (user) {
|
|
359
282
|
if (user.active) {
|
|
360
283
|
response.send(JSON.stringify({
|
|
@@ -377,7 +300,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
377
300
|
result: 'Invalid User'
|
|
378
301
|
}));
|
|
379
302
|
}
|
|
380
|
-
},
|
|
303
|
+
}, error => {
|
|
381
304
|
response.send(JSON.stringify({
|
|
382
305
|
error: true,
|
|
383
306
|
result: 'Invalid Mongo Get User'
|
|
@@ -388,7 +311,6 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
388
311
|
}
|
|
389
312
|
});
|
|
390
313
|
app.post('/setUserWithEnrollmentToken', function (request, response) {
|
|
391
|
-
var _this = this;
|
|
392
314
|
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
393
315
|
response.send(JSON.stringify({
|
|
394
316
|
error: true,
|
|
@@ -396,8 +318,8 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
396
318
|
}));
|
|
397
319
|
}
|
|
398
320
|
else {
|
|
399
|
-
|
|
400
|
-
|
|
321
|
+
let body = request.body;
|
|
322
|
+
let schema = new SimpleSchema({
|
|
401
323
|
enrollmentToken: {
|
|
402
324
|
type: String
|
|
403
325
|
},
|
|
@@ -406,12 +328,12 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
406
328
|
}
|
|
407
329
|
});
|
|
408
330
|
try {
|
|
409
|
-
schema.validate(
|
|
331
|
+
schema.validate(body);
|
|
410
332
|
}
|
|
411
333
|
catch (errors) {
|
|
412
334
|
if (errors) {
|
|
413
335
|
console.error('Error in HTTP Check (/setUserWithEnrollmentToken)', errors);
|
|
414
|
-
|
|
336
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithEnrollmentToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
415
337
|
response.send(JSON.stringify({
|
|
416
338
|
error: true,
|
|
417
339
|
result: 'Invalid Parameters'
|
|
@@ -419,61 +341,49 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
419
341
|
return;
|
|
420
342
|
}
|
|
421
343
|
}
|
|
422
|
-
jwt.verify(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
response.send(JSON.stringify({
|
|
453
|
-
error: true,
|
|
454
|
-
result: 'Account is Disabled'
|
|
455
|
-
}));
|
|
456
|
-
_a.label = 3;
|
|
457
|
-
case 3: return [3 /*break*/, 5];
|
|
458
|
-
case 4:
|
|
459
|
-
response.send(JSON.stringify({
|
|
460
|
-
error: true,
|
|
461
|
-
result: 'Invalid User'
|
|
462
|
-
}));
|
|
463
|
-
_a.label = 5;
|
|
464
|
-
case 5: return [2 /*return*/];
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
}); }, function (error) {
|
|
344
|
+
jwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], async (err, decoded) => {
|
|
345
|
+
if (err) {
|
|
346
|
+
response.send(JSON.stringify({
|
|
347
|
+
error: true,
|
|
348
|
+
result: 'Invalid Token'
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
Users.findOne({
|
|
353
|
+
$and: [
|
|
354
|
+
{ _id: decoded['id_user'] },
|
|
355
|
+
{ 'services.enrollment': body.enrollmentToken }
|
|
356
|
+
]
|
|
357
|
+
}).then(async (user) => {
|
|
358
|
+
if (user) {
|
|
359
|
+
if (user.active) {
|
|
360
|
+
await Users.setPassword(user, body.password);
|
|
361
|
+
response.send(JSON.stringify({
|
|
362
|
+
error: false,
|
|
363
|
+
result: true
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
response.send(JSON.stringify({
|
|
368
|
+
error: true,
|
|
369
|
+
result: 'Account is Disabled'
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
468
374
|
response.send(JSON.stringify({
|
|
469
375
|
error: true,
|
|
470
|
-
result: 'Invalid
|
|
376
|
+
result: 'Invalid User'
|
|
471
377
|
}));
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
378
|
+
}
|
|
379
|
+
}, error => {
|
|
380
|
+
response.send(JSON.stringify({
|
|
381
|
+
error: true,
|
|
382
|
+
result: 'Invalid Mongo Get User'
|
|
383
|
+
}));
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
});
|
|
477
387
|
}
|
|
478
388
|
});
|
|
479
389
|
app.post('/userWithForgotPasswordToken', function (request, response) {
|
|
@@ -484,19 +394,19 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
484
394
|
}));
|
|
485
395
|
}
|
|
486
396
|
else {
|
|
487
|
-
|
|
488
|
-
|
|
397
|
+
let body = request.body;
|
|
398
|
+
let schema = new SimpleSchema({
|
|
489
399
|
forgotPasswordToken: {
|
|
490
400
|
type: String
|
|
491
401
|
}
|
|
492
402
|
});
|
|
493
403
|
try {
|
|
494
|
-
schema.validate(
|
|
404
|
+
schema.validate(body);
|
|
495
405
|
}
|
|
496
406
|
catch (errors) {
|
|
497
407
|
if (errors) {
|
|
498
408
|
console.error('Error in HTTP Check (/userWithForgotPasswordToken)', errors);
|
|
499
|
-
|
|
409
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithForgotPasswordToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
500
410
|
response.send(JSON.stringify({
|
|
501
411
|
error: true,
|
|
502
412
|
result: 'Invalid Parameters'
|
|
@@ -504,7 +414,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
504
414
|
return;
|
|
505
415
|
}
|
|
506
416
|
}
|
|
507
|
-
jwt.verify(
|
|
417
|
+
jwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], (err, decoded) => {
|
|
508
418
|
if (err) {
|
|
509
419
|
response.send(JSON.stringify({
|
|
510
420
|
error: true,
|
|
@@ -512,12 +422,12 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
512
422
|
}));
|
|
513
423
|
}
|
|
514
424
|
else {
|
|
515
|
-
|
|
425
|
+
Users.findOne({
|
|
516
426
|
$and: [
|
|
517
427
|
{ _id: decoded['id_user'] },
|
|
518
|
-
{ 'services.forgot_password':
|
|
428
|
+
{ 'services.forgot_password': body.forgotPasswordToken }
|
|
519
429
|
]
|
|
520
|
-
}, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(
|
|
430
|
+
}, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then((user) => {
|
|
521
431
|
if (user) {
|
|
522
432
|
if (user.active) {
|
|
523
433
|
response.send(JSON.stringify({
|
|
@@ -540,7 +450,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
540
450
|
result: 'Invalid Token'
|
|
541
451
|
}));
|
|
542
452
|
}
|
|
543
|
-
},
|
|
453
|
+
}, error => {
|
|
544
454
|
response.send(JSON.stringify({
|
|
545
455
|
error: true,
|
|
546
456
|
result: 'Invalid Mongo Get User'
|
|
@@ -551,7 +461,6 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
551
461
|
}
|
|
552
462
|
});
|
|
553
463
|
app.post('/setUserWithForgotPasswordToken', function (request, response) {
|
|
554
|
-
var _this = this;
|
|
555
464
|
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_URL'] && request.headers.origin !== serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
556
465
|
response.send(JSON.stringify({
|
|
557
466
|
error: true,
|
|
@@ -559,8 +468,8 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
559
468
|
}));
|
|
560
469
|
}
|
|
561
470
|
else {
|
|
562
|
-
|
|
563
|
-
|
|
471
|
+
let body = request.body;
|
|
472
|
+
let schema = new SimpleSchema({
|
|
564
473
|
forgotPasswordToken: {
|
|
565
474
|
type: String
|
|
566
475
|
},
|
|
@@ -569,12 +478,12 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
569
478
|
}
|
|
570
479
|
});
|
|
571
480
|
try {
|
|
572
|
-
schema.validate(
|
|
481
|
+
schema.validate(body);
|
|
573
482
|
}
|
|
574
483
|
catch (errors) {
|
|
575
484
|
if (errors) {
|
|
576
485
|
console.error('Error in HTTP Check (/setUserWithForgotPasswordToken)', errors);
|
|
577
|
-
|
|
486
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithForgotPasswordToken' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
578
487
|
response.send(JSON.stringify({
|
|
579
488
|
error: true,
|
|
580
489
|
result: 'Invalid Parameters'
|
|
@@ -582,117 +491,92 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
|
|
|
582
491
|
return;
|
|
583
492
|
}
|
|
584
493
|
}
|
|
585
|
-
jwt.verify(
|
|
586
|
-
|
|
587
|
-
return __generator(this, function (_a) {
|
|
588
|
-
if (err) {
|
|
589
|
-
response.send(JSON.stringify({
|
|
590
|
-
error: true,
|
|
591
|
-
result: 'Invalid Token'
|
|
592
|
-
}));
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
595
|
-
user_collection_1.Users.findOne({
|
|
596
|
-
$and: [
|
|
597
|
-
{ _id: decoded['id_user'] },
|
|
598
|
-
{ 'services.forgot_password': body_4.forgotPasswordToken }
|
|
599
|
-
]
|
|
600
|
-
}).then(function (user) { return __awaiter(_this, void 0, void 0, function () {
|
|
601
|
-
return __generator(this, function (_a) {
|
|
602
|
-
switch (_a.label) {
|
|
603
|
-
case 0:
|
|
604
|
-
if (!user) return [3 /*break*/, 4];
|
|
605
|
-
if (!user.active) return [3 /*break*/, 2];
|
|
606
|
-
return [4 /*yield*/, user_collection_1.Users.setPassword(user, body_4.password)];
|
|
607
|
-
case 1:
|
|
608
|
-
_a.sent();
|
|
609
|
-
response.send(JSON.stringify({
|
|
610
|
-
error: false,
|
|
611
|
-
result: true
|
|
612
|
-
}));
|
|
613
|
-
return [3 /*break*/, 3];
|
|
614
|
-
case 2:
|
|
615
|
-
response.send(JSON.stringify({
|
|
616
|
-
error: true,
|
|
617
|
-
result: 'Account is Disabled'
|
|
618
|
-
}));
|
|
619
|
-
_a.label = 3;
|
|
620
|
-
case 3: return [3 /*break*/, 5];
|
|
621
|
-
case 4:
|
|
622
|
-
response.send(JSON.stringify({
|
|
623
|
-
error: true,
|
|
624
|
-
result: 'Invalid User'
|
|
625
|
-
}));
|
|
626
|
-
_a.label = 5;
|
|
627
|
-
case 5: return [2 /*return*/];
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
}); }, function (error) {
|
|
631
|
-
response.send(JSON.stringify({
|
|
632
|
-
error: true,
|
|
633
|
-
result: 'Invalid Mongo Get User'
|
|
634
|
-
}));
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
return [2 /*return*/];
|
|
638
|
-
});
|
|
639
|
-
}); });
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
app.post('/resetPassword', function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
643
|
-
var body, schema, user;
|
|
644
|
-
return __generator(this, function (_a) {
|
|
645
|
-
switch (_a.label) {
|
|
646
|
-
case 0:
|
|
647
|
-
if (!(request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'])) return [3 /*break*/, 1];
|
|
494
|
+
jwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], async (err, decoded) => {
|
|
495
|
+
if (err) {
|
|
648
496
|
response.send(JSON.stringify({
|
|
649
497
|
error: true,
|
|
650
|
-
result: 'Invalid
|
|
498
|
+
result: 'Invalid Token'
|
|
651
499
|
}));
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
Users.findOne({
|
|
503
|
+
$and: [
|
|
504
|
+
{ _id: decoded['id_user'] },
|
|
505
|
+
{ 'services.forgot_password': body.forgotPasswordToken }
|
|
506
|
+
]
|
|
507
|
+
}).then(async (user) => {
|
|
508
|
+
if (user) {
|
|
509
|
+
if (user.active) {
|
|
510
|
+
await Users.setPassword(user, body.password);
|
|
511
|
+
response.send(JSON.stringify({
|
|
512
|
+
error: false,
|
|
513
|
+
result: true
|
|
514
|
+
}));
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
response.send(JSON.stringify({
|
|
518
|
+
error: true,
|
|
519
|
+
result: 'Account is Disabled'
|
|
520
|
+
}));
|
|
521
|
+
}
|
|
658
522
|
}
|
|
659
|
-
|
|
660
|
-
try {
|
|
661
|
-
schema.validate(body);
|
|
662
|
-
}
|
|
663
|
-
catch (errors) {
|
|
664
|
-
if (errors) {
|
|
665
|
-
console.error('Error in HTTP Check (/resetPassword)', errors);
|
|
666
|
-
__1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resetPassword' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
523
|
+
else {
|
|
667
524
|
response.send(JSON.stringify({
|
|
668
525
|
error: true,
|
|
669
|
-
result: 'Invalid
|
|
526
|
+
result: 'Invalid User'
|
|
670
527
|
}));
|
|
671
|
-
return [2 /*return*/];
|
|
672
528
|
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
529
|
+
}, error => {
|
|
530
|
+
response.send(JSON.stringify({
|
|
531
|
+
error: true,
|
|
532
|
+
result: 'Invalid Mongo Get User'
|
|
533
|
+
}));
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
app.post('/resetPassword', async (request, response) => {
|
|
540
|
+
if (request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL']) {
|
|
541
|
+
response.send(JSON.stringify({
|
|
542
|
+
error: true,
|
|
543
|
+
result: 'Invalid header'
|
|
544
|
+
}));
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
let body = request.body;
|
|
548
|
+
let schema = new SimpleSchema({
|
|
549
|
+
username: {
|
|
550
|
+
type: String
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
try {
|
|
554
|
+
schema.validate(body);
|
|
555
|
+
}
|
|
556
|
+
catch (errors) {
|
|
557
|
+
if (errors) {
|
|
558
|
+
console.error('Error in HTTP Check (/resetPassword)', errors);
|
|
559
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/resetPassword' + '\n\nData Being Checked\n' + JSON.stringify(body, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
|
|
686
560
|
response.send(JSON.stringify({
|
|
687
|
-
error:
|
|
688
|
-
result: ''
|
|
561
|
+
error: true,
|
|
562
|
+
result: 'Invalid Parameters'
|
|
689
563
|
}));
|
|
690
|
-
|
|
691
|
-
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
let user = await Users.findOne({ username: body.username });
|
|
568
|
+
if (!user) {
|
|
569
|
+
user = await Users.findOne({ email: body.username });
|
|
570
|
+
}
|
|
571
|
+
if (user) {
|
|
572
|
+
mainServer.getMethodManager().callMethodInternal.call(mainServer.getMethodManager(), 'resetUserPassword', user._id);
|
|
692
573
|
}
|
|
693
|
-
|
|
694
|
-
|
|
574
|
+
response.send(JSON.stringify({
|
|
575
|
+
error: false,
|
|
576
|
+
result: ''
|
|
577
|
+
}));
|
|
578
|
+
}
|
|
579
|
+
});
|
|
695
580
|
}
|
|
696
|
-
exports.setupAuthRoutes = setupAuthRoutes;
|
|
697
581
|
|
|
698
582
|
//# sourceMappingURL=auth.js.map
|