@aeriajs/builtins 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +6 -0
- package/dist/collections/file/description.d.ts +50 -0
- package/dist/collections/file/description.js +70 -0
- package/dist/collections/file/description.mjs +258 -0
- package/dist/collections/file/download.d.ts +13 -0
- package/dist/collections/file/download.js +78 -0
- package/dist/collections/file/download.mjs +232 -0
- package/dist/collections/file/index.d.ts +1183 -0
- package/dist/collections/file/index.js +49 -0
- package/dist/collections/file/index.mjs +46 -0
- package/dist/collections/file/insert.d.ts +7 -0
- package/dist/collections/file/insert.js +44 -0
- package/dist/collections/file/insert.mjs +246 -0
- package/dist/collections/file/remove.d.ts +3 -0
- package/dist/collections/file/remove.js +28 -0
- package/dist/collections/file/remove.mjs +184 -0
- package/dist/collections/file/removeAll.d.ts +3 -0
- package/dist/collections/file/removeAll.js +30 -0
- package/dist/collections/file/removeAll.mjs +194 -0
- package/dist/collections/index.d.ts +4 -0
- package/dist/collections/index.js +20 -0
- package/dist/collections/index.mjs +4 -0
- package/dist/collections/log/index.d.ts +458 -0
- package/dist/collections/log/index.js +46 -0
- package/dist/collections/log/index.mjs +45 -0
- package/dist/collections/resourceUsage/index.d.ts +57 -0
- package/dist/collections/resourceUsage/index.js +19 -0
- package/dist/collections/resourceUsage/index.mjs +16 -0
- package/dist/collections/user/activate.d.ts +10 -0
- package/dist/collections/user/activate.js +65 -0
- package/dist/collections/user/activate.mjs +247 -0
- package/dist/collections/user/authenticate.d.ts +24 -0
- package/dist/collections/user/authenticate.js +103 -0
- package/dist/collections/user/authenticate.mjs +398 -0
- package/dist/collections/user/createAccount.d.ts +101 -0
- package/dist/collections/user/createAccount.js +66 -0
- package/dist/collections/user/createAccount.mjs +219 -0
- package/dist/collections/user/description.d.ts +103 -0
- package/dist/collections/user/description.js +146 -0
- package/dist/collections/user/description.mjs +151 -0
- package/dist/collections/user/getActivationLink.d.ts +2 -0
- package/dist/collections/user/getActivationLink.js +15 -0
- package/dist/collections/user/getActivationLink.mjs +156 -0
- package/dist/collections/user/getInfo.d.ts +14 -0
- package/dist/collections/user/getInfo.js +39 -0
- package/dist/collections/user/getInfo.mjs +192 -0
- package/dist/collections/user/index.d.ts +3992 -0
- package/dist/collections/user/index.js +37 -0
- package/dist/collections/user/index.mjs +36 -0
- package/dist/collections/user/insert.d.ts +5 -0
- package/dist/collections/user/insert.js +35 -0
- package/dist/collections/user/insert.mjs +156 -0
- package/dist/functions/describe.d.ts +2 -0
- package/dist/functions/describe.js +54 -0
- package/dist/functions/describe.mjs +302 -0
- package/dist/functions/index.d.ts +1 -0
- package/dist/functions/index.js +17 -0
- package/dist/functions/index.mjs +1 -0
- package/dist/index.d.ts +5701 -0
- package/dist/index.js +39 -0
- package/dist/index.mjs +11 -0
- package/package.json +60 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _object_spread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function ownKeys(object, enumerableOnly) {
|
|
59
|
+
var keys = Object.keys(object);
|
|
60
|
+
if (Object.getOwnPropertySymbols) {
|
|
61
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
+
if (enumerableOnly) {
|
|
63
|
+
symbols = symbols.filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
keys.push.apply(keys, symbols);
|
|
68
|
+
}
|
|
69
|
+
return keys;
|
|
70
|
+
}
|
|
71
|
+
function _object_spread_props(target, source) {
|
|
72
|
+
source = source != null ? source : {};
|
|
73
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
+
} else {
|
|
76
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
function _ts_generator(thisArg, body) {
|
|
83
|
+
var f, y, t, g, _ = {
|
|
84
|
+
label: 0,
|
|
85
|
+
sent: function() {
|
|
86
|
+
if (t[0] & 1) throw t[1];
|
|
87
|
+
return t[1];
|
|
88
|
+
},
|
|
89
|
+
trys: [],
|
|
90
|
+
ops: []
|
|
91
|
+
};
|
|
92
|
+
return g = {
|
|
93
|
+
next: verb(0),
|
|
94
|
+
"throw": verb(1),
|
|
95
|
+
"return": verb(2)
|
|
96
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
97
|
+
return this;
|
|
98
|
+
}), g;
|
|
99
|
+
function verb(n) {
|
|
100
|
+
return function(v) {
|
|
101
|
+
return step([
|
|
102
|
+
n,
|
|
103
|
+
v
|
|
104
|
+
]);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function step(op) {
|
|
108
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
109
|
+
while(_)try {
|
|
110
|
+
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;
|
|
111
|
+
if (y = 0, t) op = [
|
|
112
|
+
op[0] & 2,
|
|
113
|
+
t.value
|
|
114
|
+
];
|
|
115
|
+
switch(op[0]){
|
|
116
|
+
case 0:
|
|
117
|
+
case 1:
|
|
118
|
+
t = op;
|
|
119
|
+
break;
|
|
120
|
+
case 4:
|
|
121
|
+
_.label++;
|
|
122
|
+
return {
|
|
123
|
+
value: op[1],
|
|
124
|
+
done: false
|
|
125
|
+
};
|
|
126
|
+
case 5:
|
|
127
|
+
_.label++;
|
|
128
|
+
y = op[1];
|
|
129
|
+
op = [
|
|
130
|
+
0
|
|
131
|
+
];
|
|
132
|
+
continue;
|
|
133
|
+
case 7:
|
|
134
|
+
op = _.ops.pop();
|
|
135
|
+
_.trys.pop();
|
|
136
|
+
continue;
|
|
137
|
+
default:
|
|
138
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
139
|
+
_ = 0;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
143
|
+
_.label = op[1];
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
147
|
+
_.label = t[1];
|
|
148
|
+
t = op;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (t && _.label < t[2]) {
|
|
152
|
+
_.label = t[2];
|
|
153
|
+
_.ops.push(op);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (t[2]) _.ops.pop();
|
|
157
|
+
_.trys.pop();
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
op = body.call(thisArg, _);
|
|
161
|
+
} catch (e) {
|
|
162
|
+
op = [
|
|
163
|
+
6,
|
|
164
|
+
e
|
|
165
|
+
];
|
|
166
|
+
y = 0;
|
|
167
|
+
} finally{
|
|
168
|
+
f = t = 0;
|
|
169
|
+
}
|
|
170
|
+
if (op[0] & 5) throw op[1];
|
|
171
|
+
return {
|
|
172
|
+
value: op[0] ? op[1] : void 0,
|
|
173
|
+
done: true
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
import { compare as bcryptCompare } from "bcrypt";
|
|
178
|
+
import { signToken } from "@aeriajs/api";
|
|
179
|
+
import { left, right } from "@aeriajs/common";
|
|
180
|
+
export var AuthenticationErrors;
|
|
181
|
+
(function(AuthenticationErrors) {
|
|
182
|
+
AuthenticationErrors["Unauthenticated"] = "UNAUTHENTICATED";
|
|
183
|
+
AuthenticationErrors["InvalidCredentials"] = "INVALID_CREDENTIALS";
|
|
184
|
+
AuthenticationErrors["InactiveUser"] = "INACTIVE_USER";
|
|
185
|
+
})(AuthenticationErrors || (AuthenticationErrors = {}));
|
|
186
|
+
var getUser = function() {
|
|
187
|
+
var _ref = _async_to_generator(function(userId, context) {
|
|
188
|
+
var leanUser, tokenContent, pick, token;
|
|
189
|
+
return _ts_generator(this, function(_state) {
|
|
190
|
+
switch(_state.label){
|
|
191
|
+
case 0:
|
|
192
|
+
return [
|
|
193
|
+
4,
|
|
194
|
+
context.collection.functions.get({
|
|
195
|
+
filters: {
|
|
196
|
+
_id: userId
|
|
197
|
+
},
|
|
198
|
+
populate: [
|
|
199
|
+
"picture_file"
|
|
200
|
+
]
|
|
201
|
+
})
|
|
202
|
+
];
|
|
203
|
+
case 1:
|
|
204
|
+
leanUser = _state.sent();
|
|
205
|
+
if (!leanUser) {
|
|
206
|
+
throw new Error();
|
|
207
|
+
}
|
|
208
|
+
tokenContent = {
|
|
209
|
+
sub: leanUser._id,
|
|
210
|
+
roles: leanUser.roles,
|
|
211
|
+
userinfo: {}
|
|
212
|
+
};
|
|
213
|
+
if (!context.config.logSuccessfulAuthentications) return [
|
|
214
|
+
3,
|
|
215
|
+
3
|
|
216
|
+
];
|
|
217
|
+
return [
|
|
218
|
+
4,
|
|
219
|
+
context.log("successful authentication", {
|
|
220
|
+
email: leanUser.email,
|
|
221
|
+
roles: leanUser.roles,
|
|
222
|
+
_id: leanUser._id
|
|
223
|
+
})
|
|
224
|
+
];
|
|
225
|
+
case 2:
|
|
226
|
+
_state.sent();
|
|
227
|
+
_state.label = 3;
|
|
228
|
+
case 3:
|
|
229
|
+
if (context.config.tokenUserProperties) {
|
|
230
|
+
pick = function(obj, properties) {
|
|
231
|
+
return properties.reduce(function(a, prop) {
|
|
232
|
+
if ("prop" in obj) {
|
|
233
|
+
return a;
|
|
234
|
+
}
|
|
235
|
+
return _object_spread_props(_object_spread({}, a), _define_property({}, prop, obj[prop]));
|
|
236
|
+
}, {});
|
|
237
|
+
};
|
|
238
|
+
tokenContent.userinfo = pick(leanUser, context.config.tokenUserProperties);
|
|
239
|
+
}
|
|
240
|
+
return [
|
|
241
|
+
4,
|
|
242
|
+
signToken(tokenContent)
|
|
243
|
+
];
|
|
244
|
+
case 4:
|
|
245
|
+
token = _state.sent();
|
|
246
|
+
return [
|
|
247
|
+
2,
|
|
248
|
+
{
|
|
249
|
+
user: leanUser,
|
|
250
|
+
token: {
|
|
251
|
+
type: "bearer",
|
|
252
|
+
content: token
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
return function getUser(userId, context) {
|
|
260
|
+
return _ref.apply(this, arguments);
|
|
261
|
+
};
|
|
262
|
+
}();
|
|
263
|
+
export var authenticate = function() {
|
|
264
|
+
var _ref = _async_to_generator(function(props, context) {
|
|
265
|
+
var _tmp, token, user, _tmp1;
|
|
266
|
+
return _ts_generator(this, function(_state) {
|
|
267
|
+
switch(_state.label){
|
|
268
|
+
case 0:
|
|
269
|
+
if (!("revalidate" in props)) return [
|
|
270
|
+
3,
|
|
271
|
+
4
|
|
272
|
+
];
|
|
273
|
+
if (!context.token.authenticated) return [
|
|
274
|
+
3,
|
|
275
|
+
2
|
|
276
|
+
];
|
|
277
|
+
return [
|
|
278
|
+
4,
|
|
279
|
+
getUser(context.token.sub, context)
|
|
280
|
+
];
|
|
281
|
+
case 1:
|
|
282
|
+
_tmp = right.apply(void 0, [
|
|
283
|
+
_state.sent()
|
|
284
|
+
]);
|
|
285
|
+
return [
|
|
286
|
+
3,
|
|
287
|
+
3
|
|
288
|
+
];
|
|
289
|
+
case 2:
|
|
290
|
+
_tmp = left("UNAUTHENTICATED");
|
|
291
|
+
_state.label = 3;
|
|
292
|
+
case 3:
|
|
293
|
+
return [
|
|
294
|
+
2,
|
|
295
|
+
_tmp
|
|
296
|
+
];
|
|
297
|
+
case 4:
|
|
298
|
+
if (typeof props.email !== "string") {
|
|
299
|
+
return [
|
|
300
|
+
2,
|
|
301
|
+
left("INVALID_CREDENTIALS")
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
if (!context.config.defaultUser) return [
|
|
305
|
+
3,
|
|
306
|
+
6
|
|
307
|
+
];
|
|
308
|
+
if (!(props.email === context.config.defaultUser.username && props.password === context.config.defaultUser.password)) return [
|
|
309
|
+
3,
|
|
310
|
+
6
|
|
311
|
+
];
|
|
312
|
+
return [
|
|
313
|
+
4,
|
|
314
|
+
signToken({
|
|
315
|
+
_id: null,
|
|
316
|
+
roles: [
|
|
317
|
+
"root"
|
|
318
|
+
]
|
|
319
|
+
})
|
|
320
|
+
];
|
|
321
|
+
case 5:
|
|
322
|
+
token = _state.sent();
|
|
323
|
+
return [
|
|
324
|
+
2,
|
|
325
|
+
right({
|
|
326
|
+
user: {
|
|
327
|
+
_id: null,
|
|
328
|
+
name: "God Mode",
|
|
329
|
+
email: "",
|
|
330
|
+
roles: [
|
|
331
|
+
"root"
|
|
332
|
+
],
|
|
333
|
+
active: true
|
|
334
|
+
},
|
|
335
|
+
token: {
|
|
336
|
+
type: "bearer",
|
|
337
|
+
content: token
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
];
|
|
341
|
+
case 6:
|
|
342
|
+
return [
|
|
343
|
+
4,
|
|
344
|
+
context.collection.model.findOne({
|
|
345
|
+
email: props.email
|
|
346
|
+
}, {
|
|
347
|
+
projection: {
|
|
348
|
+
email: 1,
|
|
349
|
+
password: 1,
|
|
350
|
+
active: 1
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
];
|
|
354
|
+
case 7:
|
|
355
|
+
user = _state.sent();
|
|
356
|
+
_tmp1 = !user || !user.password;
|
|
357
|
+
if (_tmp1) return [
|
|
358
|
+
3,
|
|
359
|
+
9
|
|
360
|
+
];
|
|
361
|
+
return [
|
|
362
|
+
4,
|
|
363
|
+
bcryptCompare(props.password, user.password)
|
|
364
|
+
];
|
|
365
|
+
case 8:
|
|
366
|
+
_tmp1 = !_state.sent();
|
|
367
|
+
_state.label = 9;
|
|
368
|
+
case 9:
|
|
369
|
+
if (_tmp1) {
|
|
370
|
+
return [
|
|
371
|
+
2,
|
|
372
|
+
left("INVALID_CREDENTIALS")
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
if (!user.active) {
|
|
376
|
+
return [
|
|
377
|
+
2,
|
|
378
|
+
left("INACTIVE_USER")
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
return [
|
|
382
|
+
4,
|
|
383
|
+
getUser(user._id, context)
|
|
384
|
+
];
|
|
385
|
+
case 10:
|
|
386
|
+
return [
|
|
387
|
+
2,
|
|
388
|
+
right.apply(void 0, [
|
|
389
|
+
_state.sent()
|
|
390
|
+
])
|
|
391
|
+
];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
return function authenticate(props, context) {
|
|
396
|
+
return _ref.apply(this, arguments);
|
|
397
|
+
};
|
|
398
|
+
}();
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Context, Schema } from '@aeriajs/types';
|
|
2
|
+
import type { description } from './description.js';
|
|
3
|
+
export declare const createAccount: (payload: Omit<Schema<typeof description>, 'roles'>, context: Context<typeof description>) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError> | import("@aeriajs/types").Right<import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<{
|
|
4
|
+
readonly $id: "user";
|
|
5
|
+
readonly required: readonly ["name", "roles", "email"];
|
|
6
|
+
readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
|
|
7
|
+
readonly indexes: readonly ["name"];
|
|
8
|
+
readonly freshItem: {
|
|
9
|
+
readonly active: true;
|
|
10
|
+
};
|
|
11
|
+
readonly properties: {
|
|
12
|
+
readonly name: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
};
|
|
15
|
+
readonly given_name: {
|
|
16
|
+
readonly getter: (document: any) => string;
|
|
17
|
+
};
|
|
18
|
+
readonly family_name: {
|
|
19
|
+
readonly getter: (document: any) => string;
|
|
20
|
+
};
|
|
21
|
+
readonly active: {
|
|
22
|
+
readonly type: "boolean";
|
|
23
|
+
};
|
|
24
|
+
readonly roles: {
|
|
25
|
+
readonly type: "array";
|
|
26
|
+
readonly items: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
readonly uniqueItems: true;
|
|
30
|
+
};
|
|
31
|
+
readonly email: {
|
|
32
|
+
readonly type: "string";
|
|
33
|
+
readonly inputType: "email";
|
|
34
|
+
readonly unique: true;
|
|
35
|
+
};
|
|
36
|
+
readonly password: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
readonly inputType: "password";
|
|
39
|
+
readonly hidden: true;
|
|
40
|
+
};
|
|
41
|
+
readonly phone_number: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
readonly mask: "(##) #####-####";
|
|
44
|
+
};
|
|
45
|
+
readonly picture_file: {
|
|
46
|
+
readonly $ref: "file";
|
|
47
|
+
readonly accept: readonly ["image/*"];
|
|
48
|
+
};
|
|
49
|
+
readonly picture: {
|
|
50
|
+
readonly getter: (value: any) => any;
|
|
51
|
+
};
|
|
52
|
+
readonly group: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
};
|
|
55
|
+
readonly self_registered: {
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
readonly readOnly: true;
|
|
58
|
+
};
|
|
59
|
+
readonly updated_at: {
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
readonly format: "date-time";
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
readonly presets: readonly ["crud", "view", "duplicate"];
|
|
65
|
+
readonly layout: {
|
|
66
|
+
readonly name: "grid";
|
|
67
|
+
readonly options: {
|
|
68
|
+
readonly title: "name";
|
|
69
|
+
readonly badge: "roles";
|
|
70
|
+
readonly picture: "picture_file";
|
|
71
|
+
readonly information: "email";
|
|
72
|
+
readonly active: "active";
|
|
73
|
+
readonly translateBadge: true;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
readonly individualActions: {
|
|
77
|
+
readonly 'ui:spawnEdit': {
|
|
78
|
+
readonly name: "Editar";
|
|
79
|
+
readonly icon: "pencil";
|
|
80
|
+
};
|
|
81
|
+
readonly 'route:/dashboard/user/changepass': {
|
|
82
|
+
readonly name: "Mudar senha";
|
|
83
|
+
readonly icon: "key";
|
|
84
|
+
readonly fetchItem: true;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
readonly icon: "users";
|
|
88
|
+
readonly filters: readonly ["name", "roles", "email", "phone_number"];
|
|
89
|
+
readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
|
|
90
|
+
readonly tableMeta: readonly ["email"];
|
|
91
|
+
readonly formLayout: {
|
|
92
|
+
readonly fields: {
|
|
93
|
+
readonly given_name: {
|
|
94
|
+
readonly span: 3;
|
|
95
|
+
};
|
|
96
|
+
readonly family_name: {
|
|
97
|
+
readonly span: 3;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}>>, "_id">>>>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAccount = void 0;
|
|
7
|
+
const common_1 = require("@aeriajs/common");
|
|
8
|
+
const validation_1 = require("@aeriajs/validation");
|
|
9
|
+
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
10
|
+
const createAccount = async (payload, context) => {
|
|
11
|
+
const user = Object.assign({}, payload);
|
|
12
|
+
if (!context.config.allowSignup) {
|
|
13
|
+
throw new Error('signup disallowed');
|
|
14
|
+
}
|
|
15
|
+
const validationEither = (0, validation_1.validate)(user, {
|
|
16
|
+
type: 'object',
|
|
17
|
+
required: [
|
|
18
|
+
'name',
|
|
19
|
+
'email',
|
|
20
|
+
'phone_number',
|
|
21
|
+
],
|
|
22
|
+
properties: {
|
|
23
|
+
name: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
},
|
|
26
|
+
email: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
},
|
|
29
|
+
phone_number: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
password: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}, {
|
|
37
|
+
extraneous: [
|
|
38
|
+
'_id',
|
|
39
|
+
'roles',
|
|
40
|
+
'active',
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
if ((0, common_1.isLeft)(validationEither)) {
|
|
44
|
+
return (0, common_1.left)((0, common_1.unwrapEither)(validationEither));
|
|
45
|
+
}
|
|
46
|
+
if (context.config.signupDefaults) {
|
|
47
|
+
Object.assign(user, context.config.signupDefaults);
|
|
48
|
+
}
|
|
49
|
+
if (user.password) {
|
|
50
|
+
user.password = await bcrypt_1.default.hash(user.password, 10);
|
|
51
|
+
}
|
|
52
|
+
if (!context.token.authenticated) {
|
|
53
|
+
Object.assign(user, {
|
|
54
|
+
self_registered: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const { insertedId } = await context.collection.model.insertOne(user);
|
|
58
|
+
const newUser = await context.collection.model.findOne({
|
|
59
|
+
_id: insertedId,
|
|
60
|
+
});
|
|
61
|
+
if (!newUser) {
|
|
62
|
+
throw new Error();
|
|
63
|
+
}
|
|
64
|
+
return (0, common_1.right)(newUser);
|
|
65
|
+
};
|
|
66
|
+
exports.createAccount = createAccount;
|