@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.
Files changed (193) hide show
  1. package/client-server-app.js +7 -48
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +8 -11
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +8 -11
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +8 -11
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +9 -12
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +8 -11
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +8 -11
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +9 -12
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +8 -11
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +8 -11
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +11 -14
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +13 -16
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +16 -19
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +9 -12
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +10 -13
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +10 -13
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +13 -16
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +13 -16
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +15 -18
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +12 -15
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +12 -15
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +8 -11
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +9 -12
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +9 -12
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +9 -12
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +10 -13
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +11 -14
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +11 -14
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +11 -14
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +8 -11
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +12 -15
  62. package/collections/user.collection.js.map +1 -1
  63. package/cron/cron.js +25 -25
  64. package/cron/cron.js.map +1 -1
  65. package/fixtures/cron-jobs.js +30 -80
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +9 -59
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +344 -460
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +1 -5
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +7 -11
  74. package/http/home.js.map +1 -1
  75. package/index.js +36 -98
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +78 -157
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +323 -303
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.d.ts +14 -14
  82. package/managers/mongo.manager.js +794 -865
  83. package/managers/mongo.manager.js.map +1 -1
  84. package/managers/monitor.manager.js +171 -254
  85. package/managers/monitor.manager.js.map +1 -1
  86. package/managers/queue-method.manager.js +69 -166
  87. package/managers/queue-method.manager.js.map +1 -1
  88. package/managers/subscription.manager.js +515 -708
  89. package/managers/subscription.manager.js.map +1 -1
  90. package/methods/accounts.js +111 -183
  91. package/methods/accounts.js.map +1 -1
  92. package/methods/aws.js +156 -262
  93. package/methods/aws.js.map +1 -1
  94. package/methods/cloudconvert.js +100 -180
  95. package/methods/cloudconvert.js.map +1 -1
  96. package/methods/collections.js +114 -530
  97. package/methods/collections.js.map +1 -1
  98. package/methods/counters.js +29 -79
  99. package/methods/counters.js.map +1 -1
  100. package/methods/cron-jobs.js +819 -884
  101. package/methods/cron-jobs.js.map +1 -1
  102. package/methods/flags.js +1 -5
  103. package/methods/flags.js.map +1 -1
  104. package/methods/logs.js +258 -313
  105. package/methods/logs.js.map +1 -1
  106. package/methods/monitor.js +289 -348
  107. package/methods/monitor.js.map +1 -1
  108. package/methods/pdf.js +341 -340
  109. package/methods/pdf.js.map +1 -1
  110. package/methods/report-builder.js +565 -657
  111. package/methods/report-builder.js.map +1 -1
  112. package/methods/support.js +67 -185
  113. package/methods/support.js.map +1 -1
  114. package/models/app-status.model.js +1 -2
  115. package/models/app-version.model.js +1 -2
  116. package/models/billing-logged-in-users.model.js +1 -2
  117. package/models/collection-document.model.js +1 -2
  118. package/models/counter.model.js +1 -2
  119. package/models/cron-job-history.model.js +1 -2
  120. package/models/cron-job.model.js +1 -2
  121. package/models/dialog.model.js +1 -2
  122. package/models/email-history.model.js +1 -2
  123. package/models/email-verified.model.js +1 -2
  124. package/models/file.model.js +1 -2
  125. package/models/flag.model.js +1 -2
  126. package/models/log-method-latency.model.js +1 -2
  127. package/models/log-subscription.model.js +1 -2
  128. package/models/log.model.js +1 -2
  129. package/models/logged-in-users.model.js +1 -2
  130. package/models/method-call.model.js +1 -2
  131. package/models/method-response.model.js +1 -2
  132. package/models/method.model.js +1 -2
  133. package/models/monitor-cpu.model.js +1 -2
  134. package/models/monitor-https-inbound.model.js +1 -2
  135. package/models/monitor-https-outbound.model.js +1 -2
  136. package/models/monitor-memory.model.js +1 -2
  137. package/models/monitor-mongo.model.js +1 -2
  138. package/models/notification.model.js +1 -2
  139. package/models/pagination.model.js +2 -5
  140. package/models/pagination.model.js.map +1 -1
  141. package/models/permission.model.js +1 -2
  142. package/models/queue-method.model.js +1 -2
  143. package/models/queue-response.model.js +1 -2
  144. package/models/report-builder-dashboard-builder.model.js +1 -2
  145. package/models/report-builder-library.model.js +1 -2
  146. package/models/report-builder-report.model.js +1 -2
  147. package/models/report-builder.model.js +1 -2
  148. package/models/select-data-label.model.js +1 -2
  149. package/models/server-response.model.js +1 -2
  150. package/models/subscription.model.js +1 -2
  151. package/models/support-ticket.model.js +1 -2
  152. package/models/user-group.model.js +1 -2
  153. package/models/user-guide.model.js +1 -2
  154. package/models/user.model.js +1 -2
  155. package/package.json +1 -1
  156. package/public_api.js +70 -82
  157. package/public_api.js.map +1 -1
  158. package/publications/app-status.js +4 -8
  159. package/publications/app-status.js.map +1 -1
  160. package/publications/app-version.js +4 -8
  161. package/publications/app-version.js.map +1 -1
  162. package/publications/cron-jobs.js +9 -13
  163. package/publications/cron-jobs.js.map +1 -1
  164. package/publications/files.js +11 -15
  165. package/publications/files.js.map +1 -1
  166. package/publications/flags.js +7 -11
  167. package/publications/flags.js.map +1 -1
  168. package/publications/logs.js +31 -35
  169. package/publications/logs.js.map +1 -1
  170. package/publications/method-calls.js +4 -8
  171. package/publications/method-calls.js.map +1 -1
  172. package/publications/method-responses.js +4 -8
  173. package/publications/method-responses.js.map +1 -1
  174. package/publications/notifications.js +4 -8
  175. package/publications/notifications.js.map +1 -1
  176. package/publications/report-builder-dashboard-builders.js +8 -12
  177. package/publications/report-builder-dashboard-builders.js.map +1 -1
  178. package/publications/report-builder-libraries.js +16 -66
  179. package/publications/report-builder-libraries.js.map +1 -1
  180. package/publications/report-builder-reports.js +17 -21
  181. package/publications/report-builder-reports.js.map +1 -1
  182. package/publications/super-admin.js +3 -7
  183. package/publications/super-admin.js.map +1 -1
  184. package/publications/user-groups.js +4 -8
  185. package/publications/user-groups.js.map +1 -1
  186. package/publications/user-guides.js +4 -8
  187. package/publications/user-guides.js.map +1 -1
  188. package/server-app.js +393 -534
  189. package/server-app.js.map +1 -1
  190. package/util/common.js +55 -92
  191. package/util/common.js.map +1 -1
  192. package/util/schema-report-builder.js +76 -134
  193. package/util/schema-report-builder.js.map +1 -1
package/http/auth.js CHANGED
@@ -1,159 +1,106 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
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', function (request, response) { return __awaiter(_this, void 0, void 0, function () {
49
- var body, schema, user_1, resAuth, emailData_1, emailData_2;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
52
- case 0:
53
- if (!(request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'])) return [3 /*break*/, 1];
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 header'
34
+ result: 'Invalid Parameters'
57
35
  }));
58
- return [3 /*break*/, 8];
59
- case 1:
60
- body = request.body;
61
- schema = new simpl_schema_1.default({
62
- username: {
63
- type: String
64
- },
65
- password: {
66
- type: String
67
- }
68
- });
69
- try {
70
- schema.validate(body);
71
- }
72
- catch (errors) {
73
- if (errors) {
74
- console.error('Error in HTTP Check (/login)', errors);
75
- __1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.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));
76
- response.send(JSON.stringify({
77
- error: true,
78
- result: 'Invalid Parameters'
79
- }));
80
- return [2 /*return*/];
81
- }
82
- }
83
- return [4 /*yield*/, user_collection_1.Users.findOne({ username: body.username })];
84
- case 2:
85
- user_1 = _a.sent();
86
- if (!!user_1) return [3 /*break*/, 4];
87
- return [4 /*yield*/, user_collection_1.Users.findOne({ email: body.username })];
88
- case 3:
89
- user_1 = _a.sent();
90
- _a.label = 4;
91
- case 4:
92
- if (!user_1) {
93
- response.send(JSON.stringify({
94
- error: true,
95
- result: 'Invalid Username And Password'
96
- }));
97
- return [2 /*return*/];
98
- }
99
- return [4 /*yield*/, user_collection_1.Users.authenticate(user_1, body.password)];
100
- case 5:
101
- resAuth = _a.sent();
102
- if (!resAuth['error']) return [3 /*break*/, 6];
103
- if (resAuth['error'] === 'Too Many Attempts') {
104
- response.send(JSON.stringify({
105
- error: true,
106
- result: resAuth['error'] + '. A password reset link has been sent to your email, please reset your password.'
107
- }));
108
- user_1.services['forgot_password'] = jwt.sign({ id_user: user_1._id }, serverConfig['JWT_SECRET']);
109
- emailData_1 = {
110
- userToChangePassword: user_1.fullname,
111
- userWhoResetPassword: __1.ResolveIOServer.getClientName() + ' System',
112
- url: serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user_1.services['forgot_password']
113
- };
114
- user_collection_1.Users.updateOne({ _id: user_1._id }, { $set: { services: user_1.services } }).then(function (resUp) {
115
- mainServer.getMethodManager().readFile('email-templates/forgot-password.html').then(function (html) {
116
- var template = handlebars.compile(html);
117
- handlebars.registerHelper('equals', function (a, b) {
118
- return a === b;
119
- });
120
- mainServer.getMethodManager().sendEmail(user_1.email, 'ResolveIO (' + __1.ResolveIOServer.getClientName() + ') - Forgot Password', '', template(emailData_1));
121
- }, function (errEmail) { return console.log(errEmail); });
122
- }, function (errUp) { });
123
- }
124
- else if (resAuth['error'] === 'No Salt Value Stored') {
125
- response.send(JSON.stringify({
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
- _a.label = 8;
166
- case 8: return [2 /*return*/];
112
+ }
167
113
  }
168
- });
169
- }); });
170
- app.post('/accessToken', function (request, response) {
171
- return __awaiter(this, void 0, void 0, function () {
172
- var body, schema;
173
- var _this = this;
174
- return __generator(this, function (_a) {
175
- 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']) {
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 header'
142
+ result: 'Invalid Parameters'
179
143
  }));
144
+ return;
180
145
  }
181
- else {
182
- body = request.body;
183
- schema = new simpl_schema_1.default({
184
- refreshToken: {
185
- type: String
186
- },
187
- appVersion: {
188
- type: Number
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
- if (serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
206
- jwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], function (err, decoded) {
207
- if (err) {
208
- response.send(JSON.stringify({
209
- error: true,
210
- result: 'Invalid Token'
211
- }));
212
- }
213
- else {
214
- user_collection_1.Users.findById(decoded['id_user']).then(function (user) { return __awaiter(_this, void 0, void 0, function () {
215
- return __generator(this, function (_a) {
216
- switch (_a.label) {
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
- }); }, function (error) {
168
+ }));
169
+ }
170
+ else {
250
171
  response.send(JSON.stringify({
251
172
  error: true,
252
- result: 'Invalid Mongo Get User'
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 Token'
180
+ result: 'Invalid User'
264
181
  }));
265
182
  }
266
- else {
267
- user_collection_1.Users.findById(decoded['id_user']).then(function (user) { return __awaiter(_this, void 0, void 0, function () {
268
- return __generator(this, function (_a) {
269
- switch (_a.label) {
270
- case 0:
271
- if (!user) return [3 /*break*/, 4];
272
- if (!user.active) return [3 /*break*/, 2];
273
- return [4 /*yield*/, user_collection_1.Users.resetAttempts(user)];
274
- case 1:
275
- _a.sent();
276
- response.send(JSON.stringify({
277
- error: false,
278
- result: {
279
- token: jwt.sign({ id_user: user._id }, serverConfig['JWT_SECRET'], {
280
- expiresIn: 3 * 24 * 60 * 60 * 1000 // 3 days
281
- }),
282
- user: user
283
- }
284
- }));
285
- return [3 /*break*/, 3];
286
- case 2:
287
- response.send(JSON.stringify({
288
- error: true,
289
- result: 'Account is Disabled'
290
- }));
291
- _a.label = 3;
292
- case 3: return [3 /*break*/, 5];
293
- case 4:
294
- response.send(JSON.stringify({
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
- }); }, function (error) {
213
+ }));
214
+ }
215
+ else {
303
216
  response.send(JSON.stringify({
304
217
  error: true,
305
- result: 'Invalid Mongo Get User'
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
- return [2 /*return*/];
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
- var body_1 = request.body;
325
- var schema = new simpl_schema_1.default({
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(body_1);
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
- __1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithEnrollmentToken' + '\n\nData Being Checked\n' + JSON.stringify(body_1, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
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(body_1.enrollmentToken, serverConfig['JWT_SECRET'], function (err, decoded) {
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
- user_collection_1.Users.findOne({
275
+ Users.findOne({
353
276
  $and: [
354
277
  { _id: decoded['id_user'] },
355
- { 'services.enrollment': body_1.enrollmentToken }
278
+ { 'services.enrollment': body.enrollmentToken }
356
279
  ]
357
- }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(function (user) {
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
- }, function (error) {
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
- var body_2 = request.body;
400
- var schema = new simpl_schema_1.default({
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(body_2);
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
- __1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithEnrollmentToken' + '\n\nData Being Checked\n' + JSON.stringify(body_2, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
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(body_2.enrollmentToken, serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
423
- var _this = this;
424
- return __generator(this, function (_a) {
425
- if (err) {
426
- response.send(JSON.stringify({
427
- error: true,
428
- result: 'Invalid Token'
429
- }));
430
- }
431
- else {
432
- user_collection_1.Users.findOne({
433
- $and: [
434
- { _id: decoded['id_user'] },
435
- { 'services.enrollment': body_2.enrollmentToken }
436
- ]
437
- }).then(function (user) { return __awaiter(_this, void 0, void 0, function () {
438
- return __generator(this, function (_a) {
439
- switch (_a.label) {
440
- case 0:
441
- if (!user) return [3 /*break*/, 4];
442
- if (!user.active) return [3 /*break*/, 2];
443
- return [4 /*yield*/, user_collection_1.Users.setPassword(user, body_2.password)];
444
- case 1:
445
- _a.sent();
446
- response.send(JSON.stringify({
447
- error: false,
448
- result: true
449
- }));
450
- return [3 /*break*/, 3];
451
- case 2:
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 Mongo Get User'
376
+ result: 'Invalid User'
471
377
  }));
472
- });
473
- }
474
- return [2 /*return*/];
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
- var body_3 = request.body;
488
- var schema = new simpl_schema_1.default({
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(body_3);
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
- __1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/userWithForgotPasswordToken' + '\n\nData Being Checked\n' + JSON.stringify(body_3, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
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(body_3.forgotPasswordToken, serverConfig['JWT_SECRET'], function (err, decoded) {
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
- user_collection_1.Users.findOne({
425
+ Users.findOne({
516
426
  $and: [
517
427
  { _id: decoded['id_user'] },
518
- { 'services.forgot_password': body_3.forgotPasswordToken }
428
+ { 'services.forgot_password': body.forgotPasswordToken }
519
429
  ]
520
- }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(function (user) {
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
- }, function (error) {
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
- var body_4 = request.body;
563
- var schema = new simpl_schema_1.default({
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(body_4);
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
- __1.ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', __1.ResolveIOServer.getClientName() + 'HTTP - Error Detected', 'Match Error On HTTP ' + '/setUserWithForgotPasswordToken' + '\n\nData Being Checked\n' + JSON.stringify(body_4, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
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(body_4.forgotPasswordToken, serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
586
- var _this = this;
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 header'
498
+ result: 'Invalid Token'
651
499
  }));
652
- return [3 /*break*/, 5];
653
- case 1:
654
- body = request.body;
655
- schema = new simpl_schema_1.default({
656
- username: {
657
- type: String
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 Parameters'
526
+ result: 'Invalid User'
670
527
  }));
671
- return [2 /*return*/];
672
528
  }
673
- }
674
- return [4 /*yield*/, user_collection_1.Users.findOne({ username: body.username })];
675
- case 2:
676
- user = _a.sent();
677
- if (!!user) return [3 /*break*/, 4];
678
- return [4 /*yield*/, user_collection_1.Users.findOne({ email: body.username })];
679
- case 3:
680
- user = _a.sent();
681
- _a.label = 4;
682
- case 4:
683
- if (user) {
684
- mainServer.getMethodManager().callMethodInternal.call(mainServer.getMethodManager(), 'resetUserPassword', user._id);
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: false,
688
- result: ''
561
+ error: true,
562
+ result: 'Invalid Parameters'
689
563
  }));
690
- _a.label = 5;
691
- case 5: return [2 /*return*/];
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