@resolveio/server-lib 4.0.3 → 4.0.4-newrole

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.
@@ -21,13 +21,6 @@ var schema = {
21
21
  type: Date,
22
22
  optional: true
23
23
  },
24
- readonly: {
25
- type: Boolean,
26
- optional: true
27
- },
28
- active: {
29
- type: Boolean
30
- },
31
24
  attempts: {
32
25
  type: Number,
33
26
  optional: true
@@ -64,53 +57,67 @@ var schema = {
64
57
  type: String
65
58
  },
66
59
  roles: {
60
+ type: Object
61
+ },
62
+ 'roles.super_admin': {
63
+ type: Boolean
64
+ },
65
+ 'roles.approvals': {
67
66
  type: Array
68
67
  },
69
- 'roles.$': {
68
+ 'roles.approvals.$': {
69
+ type: Object
70
+ },
71
+ 'roles.approvals.$.name': {
70
72
  type: String
71
73
  },
72
- phonenumber: {
73
- type: String,
74
- optional: true
74
+ 'roles.approvals.$.type': {
75
+ type: String
75
76
  },
76
- other: {
77
- type: Object,
78
- blackbox: true,
79
- optional: true
77
+ 'roles.approvals.$.accounting_code': {
78
+ type: String
80
79
  },
81
- assets: {
82
- type: Array,
83
- optional: true
80
+ 'roles.groups': {
81
+ type: Array
84
82
  },
85
- 'assets.$': {
83
+ 'roles.groups.$': {
86
84
  type: Object
87
85
  },
88
- 'assets.$.type': {
86
+ 'roles.groups.$.name': {
89
87
  type: String
90
88
  },
91
- 'assets.$.id_asset': {
92
- type: String
89
+ 'roles.groups.$.views': {
90
+ type: Array
93
91
  },
94
- 'assets.$.asset_number': {
92
+ 'roles.groups.$.views.$': {
95
93
  type: String
96
94
  },
97
- 'assets.$.ownership': {
98
- type: String
95
+ 'roles.groups.$.yard': {
96
+ type: String,
97
+ optional: true
98
+ },
99
+ 'roles.notifications': {
100
+ type: Array
99
101
  },
100
- 'assets.$.ownership_driver': {
102
+ 'roles.notifications.$': {
101
103
  type: String
102
104
  },
103
- 'assets.$.date_start': {
104
- type: Date
105
+ 'roles.miscs': {
106
+ type: Array
105
107
  },
106
- 'assets.$.date_end': {
107
- type: Date,
108
- optional: true
108
+ 'roles.miscs.$': {
109
+ type: String
109
110
  },
110
- id_function: {
111
+ active: Boolean,
112
+ phonenumber: {
111
113
  type: String,
112
114
  optional: true
113
115
  },
116
+ other: {
117
+ type: Object,
118
+ optional: true,
119
+ blackbox: true
120
+ },
114
121
  customers: {
115
122
  type: Array,
116
123
  optional: true,
package/fixtures/init.js CHANGED
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var app_version_collection_1 = require("../collections/app-version.collection");
39
39
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
40
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
40
  var mongoose_1 = require("mongoose");
41
+ var active_subscription_collection_1 = require("../collections/active-subscription.collection");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
package/http/auth.js CHANGED
@@ -43,7 +43,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
43
43
  var _this = this;
44
44
  // Login via HTTP, return refresh token if authenticated
45
45
  app.post('/login', function (request, response) { return __awaiter(_this, void 0, void 0, function () {
46
- var user_1, username;
46
+ var user_1, username, resAuth_1, emailData_1;
47
47
  return __generator(this, function (_a) {
48
48
  switch (_a.label) {
49
49
  case 0:
@@ -52,7 +52,7 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
52
52
  error: true,
53
53
  result: 'Invalid header'
54
54
  }));
55
- return [3 /*break*/, 5];
55
+ return [3 /*break*/, 6];
56
56
  case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: request.body.username }).exec()];
57
57
  case 2:
58
58
  user_1 = _a.sent();
@@ -63,26 +63,17 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
63
63
  _a.label = 4;
64
64
  case 4:
65
65
  username = user_1 ? user_1.username : request.body.username;
66
- user_collection_1.Users.authenticate()(username, request.body.password).then(function (res) {
67
- if (res && res.user && res.user.active && !res.error) {
68
- res.user.resetAttempts(function (errAt, resAt, errorAt) {
69
- response.send(JSON.stringify({
70
- error: false,
71
- result: {
72
- token: jwt.sign({ id_user: res.user._id }, serverConfig['JWT_SECRET'], {
73
- expiresIn: 90 * 24 * 60 * 60 * 1000 // 90 days
74
- })
75
- }
76
- }));
77
- });
78
- }
79
- else if (res.error.name === 'TooManyAttemptsError') {
66
+ return [4 /*yield*/, user_collection_1.Users.authenticate()(username, request.body.password)];
67
+ case 5:
68
+ resAuth_1 = _a.sent();
69
+ if (resAuth_1.error) {
70
+ if (resAuth_1.error.name === 'TooManyAttemptsError') {
80
71
  response.send(JSON.stringify({
81
72
  error: true,
82
- result: res.error.message + '. A password reset link has been sent to your email, please reset your password.'
73
+ result: resAuth_1.error.message + '. A password reset link has been sent to your email, please reset your password.'
83
74
  }));
84
75
  user_1.services.forgot_password = jwt.sign({ id_user: user_1._id }, serverConfig['JWT_SECRET']);
85
- var emailData_1 = {
76
+ emailData_1 = {
86
77
  userToChangePassword: user_1.fullname,
87
78
  userWhoResetPassword: __1.ResolveIOServer.getClientName() + ' System',
88
79
  url: serverConfig['ROOT_URL'] + '/forgot-password?' + encodeURIComponent(serverConfig['SERVER_URL']) + '&' + user_1.services.forgot_password
@@ -100,12 +91,26 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
100
91
  else {
101
92
  response.send(JSON.stringify({
102
93
  error: true,
103
- result: res.error.message
94
+ result: resAuth_1.error.message
104
95
  }));
105
96
  }
106
- });
107
- _a.label = 5;
108
- case 5: return [2 /*return*/];
97
+ }
98
+ else {
99
+ if (resAuth_1 && resAuth_1.user && resAuth_1.user.active) {
100
+ resAuth_1.user.resetAttempts(function (errAt, resAt) {
101
+ response.send(JSON.stringify({
102
+ error: false,
103
+ result: {
104
+ token: jwt.sign({ id_user: resAuth_1.user._id }, serverConfig['JWT_SECRET'], {
105
+ expiresIn: 90 * 24 * 60 * 60 * 1000 // 90 days
106
+ })
107
+ }
108
+ }));
109
+ });
110
+ }
111
+ }
112
+ _a.label = 6;
113
+ case 6: return [2 /*return*/];
109
114
  }
110
115
  });
111
116
  }); });
@@ -464,5 +469,37 @@ function setupAuthRoutes(mainServer, app, serverConfig) {
464
469
  }); });
465
470
  }
466
471
  });
472
+ app.post('/resetPassword', function (request, response) { return __awaiter(_this, void 0, void 0, function () {
473
+ var user;
474
+ return __generator(this, function (_a) {
475
+ switch (_a.label) {
476
+ case 0:
477
+ if (!(request.headers.origin !== serverConfig['ROOT_URL'] && request.headers.origin !== serverConfig['SEC_ROOT_URL'])) return [3 /*break*/, 1];
478
+ response.send(JSON.stringify({
479
+ error: true,
480
+ result: 'Invalid header'
481
+ }));
482
+ return [3 /*break*/, 5];
483
+ case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: request.body.username }).exec()];
484
+ case 2:
485
+ user = _a.sent();
486
+ if (!!user) return [3 /*break*/, 4];
487
+ return [4 /*yield*/, user_collection_1.Users.findOne({ email: request.body.username }).exec()];
488
+ case 3:
489
+ user = _a.sent();
490
+ _a.label = 4;
491
+ case 4:
492
+ if (user) {
493
+ mainServer.getMethodManager().callMethodInternal.call(mainServer.getMethodManager(), 'resetUserPassword', user._id);
494
+ }
495
+ response.send(JSON.stringify({
496
+ error: false,
497
+ result: ''
498
+ }));
499
+ _a.label = 5;
500
+ case 5: return [2 /*return*/];
501
+ }
502
+ });
503
+ }); });
467
504
  }
468
505
  exports.setupAuthRoutes = setupAuthRoutes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.0.3",
3
+ "version": "4.0.4-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {