@resolveio/server-lib 9.0.34 → 9.0.35

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 (192) hide show
  1. package/client-server-app.js +48 -7
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +11 -8
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +11 -8
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +11 -8
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +12 -9
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +11 -8
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +11 -8
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +12 -9
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +11 -8
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +11 -8
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +14 -11
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +16 -13
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +19 -16
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +12 -9
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +13 -10
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +13 -10
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +16 -13
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +16 -13
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +18 -15
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +15 -12
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +15 -12
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +11 -8
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +12 -9
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +12 -9
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +12 -9
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +13 -10
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +14 -11
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +14 -11
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +14 -11
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +11 -8
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +15 -12
  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 +80 -30
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +59 -9
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +460 -344
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +5 -1
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +11 -7
  74. package/http/home.js.map +1 -1
  75. package/index.js +98 -36
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +157 -78
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +302 -314
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.js +1001 -739
  82. package/managers/mongo.manager.js.map +1 -1
  83. package/managers/monitor.manager.js +254 -171
  84. package/managers/monitor.manager.js.map +1 -1
  85. package/managers/queue-method.manager.js +166 -69
  86. package/managers/queue-method.manager.js.map +1 -1
  87. package/managers/subscription.manager.js +714 -515
  88. package/managers/subscription.manager.js.map +1 -1
  89. package/methods/accounts.js +183 -111
  90. package/methods/accounts.js.map +1 -1
  91. package/methods/aws.js +262 -156
  92. package/methods/aws.js.map +1 -1
  93. package/methods/cloudconvert.js +180 -100
  94. package/methods/cloudconvert.js.map +1 -1
  95. package/methods/collections.js +110 -103
  96. package/methods/collections.js.map +1 -1
  97. package/methods/counters.js +79 -29
  98. package/methods/counters.js.map +1 -1
  99. package/methods/cron-jobs.js +884 -819
  100. package/methods/cron-jobs.js.map +1 -1
  101. package/methods/flags.js +5 -1
  102. package/methods/flags.js.map +1 -1
  103. package/methods/logs.js +313 -258
  104. package/methods/logs.js.map +1 -1
  105. package/methods/monitor.js +348 -289
  106. package/methods/monitor.js.map +1 -1
  107. package/methods/pdf.js +340 -341
  108. package/methods/pdf.js.map +1 -1
  109. package/methods/report-builder.js +657 -565
  110. package/methods/report-builder.js.map +1 -1
  111. package/methods/support.js +185 -67
  112. package/methods/support.js.map +1 -1
  113. package/models/app-status.model.js +2 -1
  114. package/models/app-version.model.js +2 -1
  115. package/models/billing-logged-in-users.model.js +2 -1
  116. package/models/collection-document.model.js +2 -1
  117. package/models/counter.model.js +2 -1
  118. package/models/cron-job-history.model.js +2 -1
  119. package/models/cron-job.model.js +2 -1
  120. package/models/dialog.model.js +2 -1
  121. package/models/email-history.model.js +2 -1
  122. package/models/email-verified.model.js +2 -1
  123. package/models/file.model.js +2 -1
  124. package/models/flag.model.js +2 -1
  125. package/models/log-method-latency.model.js +2 -1
  126. package/models/log-subscription.model.js +2 -1
  127. package/models/log.model.js +2 -1
  128. package/models/logged-in-users.model.js +2 -1
  129. package/models/method-call.model.js +2 -1
  130. package/models/method-response.model.js +2 -1
  131. package/models/method.model.js +2 -1
  132. package/models/monitor-cpu.model.js +2 -1
  133. package/models/monitor-https-inbound.model.js +2 -1
  134. package/models/monitor-https-outbound.model.js +2 -1
  135. package/models/monitor-memory.model.js +2 -1
  136. package/models/monitor-mongo.model.js +2 -1
  137. package/models/notification.model.js +2 -1
  138. package/models/pagination.model.js +5 -2
  139. package/models/pagination.model.js.map +1 -1
  140. package/models/permission.model.js +2 -1
  141. package/models/queue-method.model.js +2 -1
  142. package/models/queue-response.model.js +2 -1
  143. package/models/report-builder-dashboard-builder.model.js +2 -1
  144. package/models/report-builder-library.model.js +2 -1
  145. package/models/report-builder-report.model.js +2 -1
  146. package/models/report-builder.model.js +2 -1
  147. package/models/select-data-label.model.js +2 -1
  148. package/models/server-response.model.js +2 -1
  149. package/models/subscription.model.js +2 -1
  150. package/models/support-ticket.model.js +2 -1
  151. package/models/user-group.model.js +2 -1
  152. package/models/user-guide.model.js +2 -1
  153. package/models/user.model.js +2 -1
  154. package/package.json +1 -1
  155. package/public_api.js +82 -70
  156. package/public_api.js.map +1 -1
  157. package/publications/app-status.js +8 -4
  158. package/publications/app-status.js.map +1 -1
  159. package/publications/app-version.js +8 -4
  160. package/publications/app-version.js.map +1 -1
  161. package/publications/cron-jobs.js +13 -9
  162. package/publications/cron-jobs.js.map +1 -1
  163. package/publications/files.js +15 -11
  164. package/publications/files.js.map +1 -1
  165. package/publications/flags.js +11 -7
  166. package/publications/flags.js.map +1 -1
  167. package/publications/logs.js +35 -31
  168. package/publications/logs.js.map +1 -1
  169. package/publications/method-calls.js +8 -4
  170. package/publications/method-calls.js.map +1 -1
  171. package/publications/method-responses.js +8 -4
  172. package/publications/method-responses.js.map +1 -1
  173. package/publications/notifications.js +8 -4
  174. package/publications/notifications.js.map +1 -1
  175. package/publications/report-builder-dashboard-builders.js +12 -8
  176. package/publications/report-builder-dashboard-builders.js.map +1 -1
  177. package/publications/report-builder-libraries.js +66 -16
  178. package/publications/report-builder-libraries.js.map +1 -1
  179. package/publications/report-builder-reports.js +21 -17
  180. package/publications/report-builder-reports.js.map +1 -1
  181. package/publications/super-admin.js +7 -3
  182. package/publications/super-admin.js.map +1 -1
  183. package/publications/user-groups.js +8 -4
  184. package/publications/user-groups.js.map +1 -1
  185. package/publications/user-guides.js +8 -4
  186. package/publications/user-guides.js.map +1 -1
  187. package/server-app.js +534 -393
  188. package/server-app.js.map +1 -1
  189. package/util/common.js +92 -55
  190. package/util/common.js.map +1 -1
  191. package/util/schema-report-builder.js +134 -76
  192. package/util/schema-report-builder.js.map +1 -1
package/http/auth.js CHANGED
@@ -1,106 +1,159 @@
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) {
7
- // Login via HTTP, return refresh token if authenticated
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));
32
- response.send(JSON.stringify({
33
- error: true,
34
- result: 'Invalid Parameters'
35
- }));
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;
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;
49
32
  }
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 {
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;
47
+ // 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];
95
54
  response.send(JSON.stringify({
96
55
  error: true,
97
- result: resAuth['error']
56
+ result: 'Invalid header'
98
57
  }));
99
- }
100
- }
101
- else {
102
- if (resAuth && resAuth['data'] && resAuth['data'].active) {
103
- await Users.resetAttempts(resAuth['data']);
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();
104
157
  response.send(JSON.stringify({
105
158
  error: false,
106
159
  result: {
@@ -109,132 +162,156 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
109
162
  })
110
163
  }
111
164
  }));
112
- }
165
+ _a.label = 8;
166
+ case 8: return [2 /*return*/];
113
167
  }
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));
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']) {
140
176
  response.send(JSON.stringify({
141
177
  error: true,
142
- result: 'Invalid Parameters'
178
+ result: 'Invalid header'
143
179
  }));
144
- return;
145
180
  }
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
- }));
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);
154
193
  }
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
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
+ }
204
+ }
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*/];
167
247
  }
168
- }));
169
- }
170
- else {
248
+ });
249
+ }); }, function (error) {
171
250
  response.send(JSON.stringify({
172
251
  error: true,
173
- result: 'Account is Disabled'
252
+ result: 'Invalid Mongo Get User'
174
253
  }));
175
- }
254
+ });
176
255
  }
177
- else {
256
+ });
257
+ }
258
+ else {
259
+ jwt.verify(body.refreshToken, serverConfig['JWT_SECRET'], function (err, decoded) {
260
+ if (err) {
178
261
  response.send(JSON.stringify({
179
262
  error: true,
180
- result: 'Invalid User'
263
+ result: 'Invalid Token'
181
264
  }));
182
265
  }
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
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*/];
212
300
  }
213
- }));
214
- }
215
- else {
301
+ });
302
+ }); }, function (error) {
216
303
  response.send(JSON.stringify({
217
304
  error: true,
218
- result: 'Account is Disabled'
305
+ result: 'Invalid Mongo Get User'
219
306
  }));
220
- }
307
+ });
221
308
  }
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
- }));
233
309
  });
234
310
  }
235
- });
236
- }
237
- }
311
+ }
312
+ return [2 /*return*/];
313
+ });
314
+ });
238
315
  });
239
316
  app.post('/userWithEnrollmentToken', function (request, response) {
240
317
  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']) {
@@ -244,19 +321,19 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
244
321
  }));
245
322
  }
246
323
  else {
247
- let body = request.body;
248
- let schema = new SimpleSchema({
324
+ var body_1 = request.body;
325
+ var schema = new simpl_schema_1.default({
249
326
  enrollmentToken: {
250
327
  type: String
251
328
  }
252
329
  });
253
330
  try {
254
- schema.validate(body);
331
+ schema.validate(body_1);
255
332
  }
256
333
  catch (errors) {
257
334
  if (errors) {
258
335
  console.error('Error in HTTP Check (/userWithEnrollmentToken)', errors);
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));
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));
260
337
  response.send(JSON.stringify({
261
338
  error: true,
262
339
  result: 'Invalid Parameters'
@@ -264,7 +341,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
264
341
  return;
265
342
  }
266
343
  }
267
- jwt.verify(body.enrollmentToken, serverConfig['JWT_SECRET'], (err, decoded) => {
344
+ jwt.verify(body_1.enrollmentToken, serverConfig['JWT_SECRET'], function (err, decoded) {
268
345
  if (err) {
269
346
  response.send(JSON.stringify({
270
347
  error: true,
@@ -272,12 +349,12 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
272
349
  }));
273
350
  }
274
351
  else {
275
- Users.findOne({
352
+ user_collection_1.Users.findOne({
276
353
  $and: [
277
354
  { _id: decoded['id_user'] },
278
- { 'services.enrollment': body.enrollmentToken }
355
+ { 'services.enrollment': body_1.enrollmentToken }
279
356
  ]
280
- }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then((user) => {
357
+ }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(function (user) {
281
358
  if (user) {
282
359
  if (user.active) {
283
360
  response.send(JSON.stringify({
@@ -300,7 +377,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
300
377
  result: 'Invalid User'
301
378
  }));
302
379
  }
303
- }, error => {
380
+ }, function (error) {
304
381
  response.send(JSON.stringify({
305
382
  error: true,
306
383
  result: 'Invalid Mongo Get User'
@@ -311,6 +388,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
311
388
  }
312
389
  });
313
390
  app.post('/setUserWithEnrollmentToken', function (request, response) {
391
+ var _this = this;
314
392
  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']) {
315
393
  response.send(JSON.stringify({
316
394
  error: true,
@@ -318,8 +396,8 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
318
396
  }));
319
397
  }
320
398
  else {
321
- let body = request.body;
322
- let schema = new SimpleSchema({
399
+ var body_2 = request.body;
400
+ var schema = new simpl_schema_1.default({
323
401
  enrollmentToken: {
324
402
  type: String
325
403
  },
@@ -328,12 +406,12 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
328
406
  }
329
407
  });
330
408
  try {
331
- schema.validate(body);
409
+ schema.validate(body_2);
332
410
  }
333
411
  catch (errors) {
334
412
  if (errors) {
335
413
  console.error('Error in HTTP Check (/setUserWithEnrollmentToken)', errors);
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));
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));
337
415
  response.send(JSON.stringify({
338
416
  error: true,
339
417
  result: 'Invalid Parameters'
@@ -341,49 +419,61 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
341
419
  return;
342
420
  }
343
421
  }
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 {
374
- response.send(JSON.stringify({
375
- error: true,
376
- result: 'Invalid User'
377
- }));
378
- }
379
- }, error => {
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) {
380
426
  response.send(JSON.stringify({
381
427
  error: true,
382
- result: 'Invalid Mongo Get User'
428
+ result: 'Invalid Token'
383
429
  }));
384
- });
385
- }
386
- });
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) {
468
+ response.send(JSON.stringify({
469
+ error: true,
470
+ result: 'Invalid Mongo Get User'
471
+ }));
472
+ });
473
+ }
474
+ return [2 /*return*/];
475
+ });
476
+ }); });
387
477
  }
388
478
  });
389
479
  app.post('/userWithForgotPasswordToken', function (request, response) {
@@ -394,19 +484,19 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
394
484
  }));
395
485
  }
396
486
  else {
397
- let body = request.body;
398
- let schema = new SimpleSchema({
487
+ var body_3 = request.body;
488
+ var schema = new simpl_schema_1.default({
399
489
  forgotPasswordToken: {
400
490
  type: String
401
491
  }
402
492
  });
403
493
  try {
404
- schema.validate(body);
494
+ schema.validate(body_3);
405
495
  }
406
496
  catch (errors) {
407
497
  if (errors) {
408
498
  console.error('Error in HTTP Check (/userWithForgotPasswordToken)', errors);
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));
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));
410
500
  response.send(JSON.stringify({
411
501
  error: true,
412
502
  result: 'Invalid Parameters'
@@ -414,7 +504,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
414
504
  return;
415
505
  }
416
506
  }
417
- jwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], (err, decoded) => {
507
+ jwt.verify(body_3.forgotPasswordToken, serverConfig['JWT_SECRET'], function (err, decoded) {
418
508
  if (err) {
419
509
  response.send(JSON.stringify({
420
510
  error: true,
@@ -422,12 +512,12 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
422
512
  }));
423
513
  }
424
514
  else {
425
- Users.findOne({
515
+ user_collection_1.Users.findOne({
426
516
  $and: [
427
517
  { _id: decoded['id_user'] },
428
- { 'services.forgot_password': body.forgotPasswordToken }
518
+ { 'services.forgot_password': body_3.forgotPasswordToken }
429
519
  ]
430
- }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then((user) => {
520
+ }, { projection: { _id: 1, __v: 1, username: 1, active: 1 } }).then(function (user) {
431
521
  if (user) {
432
522
  if (user.active) {
433
523
  response.send(JSON.stringify({
@@ -450,7 +540,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
450
540
  result: 'Invalid Token'
451
541
  }));
452
542
  }
453
- }, error => {
543
+ }, function (error) {
454
544
  response.send(JSON.stringify({
455
545
  error: true,
456
546
  result: 'Invalid Mongo Get User'
@@ -461,6 +551,7 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
461
551
  }
462
552
  });
463
553
  app.post('/setUserWithForgotPasswordToken', function (request, response) {
554
+ var _this = this;
464
555
  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']) {
465
556
  response.send(JSON.stringify({
466
557
  error: true,
@@ -468,8 +559,8 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
468
559
  }));
469
560
  }
470
561
  else {
471
- let body = request.body;
472
- let schema = new SimpleSchema({
562
+ var body_4 = request.body;
563
+ var schema = new simpl_schema_1.default({
473
564
  forgotPasswordToken: {
474
565
  type: String
475
566
  },
@@ -478,12 +569,12 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
478
569
  }
479
570
  });
480
571
  try {
481
- schema.validate(body);
572
+ schema.validate(body_4);
482
573
  }
483
574
  catch (errors) {
484
575
  if (errors) {
485
576
  console.error('Error in HTTP Check (/setUserWithForgotPasswordToken)', errors);
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));
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));
487
578
  response.send(JSON.stringify({
488
579
  error: true,
489
580
  result: 'Invalid Parameters'
@@ -491,92 +582,117 @@ export function setupAuthRoutes(mainServer, app, serverConfig) {
491
582
  return;
492
583
  }
493
584
  }
494
- jwt.verify(body.forgotPasswordToken, serverConfig['JWT_SECRET'], async (err, decoded) => {
495
- if (err) {
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];
496
648
  response.send(JSON.stringify({
497
649
  error: true,
498
- result: 'Invalid Token'
650
+ result: 'Invalid header'
499
651
  }));
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
- }
652
+ return [3 /*break*/, 5];
653
+ case 1:
654
+ body = request.body;
655
+ schema = new simpl_schema_1.default({
656
+ username: {
657
+ type: String
522
658
  }
523
- else {
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));
524
667
  response.send(JSON.stringify({
525
668
  error: true,
526
- result: 'Invalid User'
669
+ result: 'Invalid Parameters'
527
670
  }));
671
+ return [2 /*return*/];
528
672
  }
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));
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
+ }
560
686
  response.send(JSON.stringify({
561
- error: true,
562
- result: 'Invalid Parameters'
687
+ error: false,
688
+ result: ''
563
689
  }));
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);
690
+ _a.label = 5;
691
+ case 5: return [2 /*return*/];
573
692
  }
574
- response.send(JSON.stringify({
575
- error: false,
576
- result: ''
577
- }));
578
- }
579
- });
693
+ });
694
+ }); });
580
695
  }
696
+ exports.setupAuthRoutes = setupAuthRoutes;
581
697
 
582
698
  //# sourceMappingURL=auth.js.map