@nymphjs/tilmeld 1.0.0-alpha.1 → 1.0.0-alpha.5

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/dist/User.js CHANGED
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const nymph_1 = __importDefault(require("@nymphjs/nymph"));
16
15
  const strtotime_1 = __importDefault(require("locutus/php/datetime/strtotime"));
17
16
  const nanoid_1 = require("nanoid");
18
17
  const nanoid_dictionary_1 = require("nanoid-dictionary");
@@ -21,8 +20,6 @@ const sha256_1 = __importDefault(require("crypto-js/sha256"));
21
20
  const md5_1 = __importDefault(require("crypto-js/md5"));
22
21
  const lodash_1 = require("lodash");
23
22
  const AbleObject_1 = __importDefault(require("./AbleObject"));
24
- const Group_1 = __importDefault(require("./Group"));
25
- const Tilmeld_1 = __importDefault(require("./Tilmeld"));
26
23
  const errors_1 = require("./errors");
27
24
  class User extends AbleObject_1.default {
28
25
  constructor(guid) {
@@ -52,7 +49,7 @@ class User extends AbleObject_1.default {
52
49
  return __awaiter(this, void 0, void 0, function* () {
53
50
  const entity = new this();
54
51
  if (username != null) {
55
- const entity = yield nymph_1.default.getEntity({
52
+ const entity = yield this.nymph.getEntity({
56
53
  class: this,
57
54
  }, {
58
55
  type: '&',
@@ -69,15 +66,15 @@ class User extends AbleObject_1.default {
69
66
  return super.factorySync(guid);
70
67
  }
71
68
  static current(returnObjectIfNotExist) {
72
- if (Tilmeld_1.default.currentUser == null) {
69
+ if (this.tilmeld.currentUser == null) {
73
70
  return returnObjectIfNotExist ? this.factorySync() : null;
74
71
  }
75
- return Tilmeld_1.default.currentUser;
72
+ return this.tilmeld.currentUser;
76
73
  }
77
74
  static sendRecovery(data) {
78
75
  var _a, _b, _c, _d;
79
76
  return __awaiter(this, void 0, void 0, function* () {
80
- if (!Tilmeld_1.default.config.pwRecovery) {
77
+ if (!this.tilmeld.config.pwRecovery) {
81
78
  return {
82
79
  result: false,
83
80
  message: 'Account recovery is not allowed.',
@@ -85,8 +82,9 @@ class User extends AbleObject_1.default {
85
82
  }
86
83
  let user;
87
84
  const options = {};
88
- if (!Tilmeld_1.default.config.emailUsernames && data.recoveryType === 'username') {
89
- const getUser = yield nymph_1.default.getEntity({ class: User, skipAc: true }, {
85
+ if (!this.tilmeld.config.emailUsernames &&
86
+ data.recoveryType === 'username') {
87
+ const getUser = yield this.nymph.getEntity({ class: this.tilmeld.User, skipAc: true }, {
90
88
  type: '&',
91
89
  ilike: ['email', data.account.replace(/([\\%_])/g, (s) => `\\${s}`)],
92
90
  });
@@ -107,7 +105,7 @@ class User extends AbleObject_1.default {
107
105
  options.locals = {};
108
106
  }
109
107
  else if (data.recoveryType === 'password') {
110
- const getUser = yield User.factoryUsername(data.account);
108
+ const getUser = yield this.tilmeld.User.factoryUsername(data.account);
111
109
  if (getUser.guid == null) {
112
110
  return {
113
111
  result: false,
@@ -129,13 +127,13 @@ class User extends AbleObject_1.default {
129
127
  };
130
128
  options.locals = {
131
129
  recoverCode: getUser.recoverSecret,
132
- timeLimit: Tilmeld_1.default.config.pwRecoveryTimeLimit,
130
+ timeLimit: this.tilmeld.config.pwRecoveryTimeLimit,
133
131
  };
134
132
  }
135
133
  else {
136
134
  return { result: false, message: 'Invalid recovery type.' };
137
135
  }
138
- if (yield Tilmeld_1.default.config.sendEmail(options, user)) {
136
+ if (yield this.tilmeld.config.sendEmail(this.tilmeld, options, user)) {
139
137
  return {
140
138
  result: true,
141
139
  message: "We've sent an email to your registered address. Please " +
@@ -150,17 +148,17 @@ class User extends AbleObject_1.default {
150
148
  static recover(data) {
151
149
  var _a;
152
150
  return __awaiter(this, void 0, void 0, function* () {
153
- if (!Tilmeld_1.default.config.pwRecovery) {
151
+ if (!this.tilmeld.config.pwRecovery) {
154
152
  return {
155
153
  result: false,
156
154
  message: 'Account recovery is not allowed.',
157
155
  };
158
156
  }
159
- const user = yield User.factoryUsername(data.username);
157
+ const user = yield this.tilmeld.User.factoryUsername(data.username);
160
158
  if (user.guid == null ||
161
159
  user.recoverSecret == null ||
162
160
  data.secret !== user.recoverSecret ||
163
- (0, strtotime_1.default)('+' + Tilmeld_1.default.config.pwRecoveryTimeLimit, Math.floor(((_a = user.recoverSecretDate) !== null && _a !== void 0 ? _a : 0) / 1000)) *
161
+ (0, strtotime_1.default)('+' + this.tilmeld.config.pwRecoveryTimeLimit, Math.floor(((_a = user.recoverSecretDate) !== null && _a !== void 0 ? _a : 0) / 1000)) *
164
162
  1000 <
165
163
  Date.now()) {
166
164
  return {
@@ -187,14 +185,14 @@ class User extends AbleObject_1.default {
187
185
  }
188
186
  static getClientConfig() {
189
187
  return {
190
- regFields: Tilmeld_1.default.config.regFields,
191
- userFields: Tilmeld_1.default.config.userFields,
192
- emailUsernames: Tilmeld_1.default.config.emailUsernames,
193
- allowRegistration: Tilmeld_1.default.config.allowRegistration,
194
- allowUsernameChange: Tilmeld_1.default.config.allowUsernameChange,
195
- pwRecovery: Tilmeld_1.default.config.pwRecovery,
196
- verifyEmail: Tilmeld_1.default.config.verifyEmail,
197
- unverifiedAccess: Tilmeld_1.default.config.unverifiedAccess,
188
+ regFields: this.tilmeld.config.regFields,
189
+ userFields: this.tilmeld.config.userFields,
190
+ emailUsernames: this.tilmeld.config.emailUsernames,
191
+ allowRegistration: this.tilmeld.config.allowRegistration,
192
+ allowUsernameChange: this.tilmeld.config.allowUsernameChange,
193
+ pwRecovery: this.tilmeld.config.pwRecovery,
194
+ verifyEmail: this.tilmeld.config.verifyEmail,
195
+ unverifiedAccess: this.tilmeld.config.unverifiedAccess,
198
196
  };
199
197
  }
200
198
  static loginUser(data) {
@@ -202,7 +200,7 @@ class User extends AbleObject_1.default {
202
200
  if (!('username' in data) || !data.username.length) {
203
201
  return { result: false, message: 'Incorrect login/password.' };
204
202
  }
205
- const user = yield User.factoryUsername(data.username);
203
+ const user = yield this.tilmeld.User.factoryUsername(data.username);
206
204
  const result = user.$login(data);
207
205
  if (result.result) {
208
206
  user.$updateDataProtection();
@@ -212,6 +210,7 @@ class User extends AbleObject_1.default {
212
210
  });
213
211
  }
214
212
  $login(data) {
213
+ const tilmeld = this.$nymph.tilmeld;
215
214
  if (this.guid == null) {
216
215
  return { result: false, message: 'Incorrect login/password.' };
217
216
  }
@@ -224,13 +223,14 @@ class User extends AbleObject_1.default {
224
223
  if (!this.$checkPassword(data.password)) {
225
224
  return { result: false, message: 'Incorrect login/password.' };
226
225
  }
227
- if (!Tilmeld_1.default.login(this, true)) {
226
+ if (!tilmeld.login(this, true)) {
228
227
  return { result: false, message: 'Incorrect login/password.' };
229
228
  }
230
229
  return { result: true, message: 'You are logged in.' };
231
230
  }
232
231
  $logout() {
233
- Tilmeld_1.default.logout();
232
+ const tilmeld = this.$nymph.tilmeld;
233
+ tilmeld.logout();
234
234
  return { result: true, message: 'You have been logged out.' };
235
235
  }
236
236
  $getAvatar() {
@@ -273,24 +273,26 @@ class User extends AbleObject_1.default {
273
273
  return this.$descendantGroups;
274
274
  }
275
275
  $jsonAcceptData(input, allowConflict = false) {
276
- var _a;
276
+ var _a, _b;
277
+ const tilmeld = this.$nymph.tilmeld;
277
278
  this.$referenceWake();
278
- if (input.data.abilities.indexOf('system/admin') !== -1 &&
279
- ((_a = this.$data.abilities) === null || _a === void 0 ? void 0 : _a.indexOf('system/admin')) === -1 &&
280
- Tilmeld_1.default.gatekeeper('tilmeld/admin') &&
281
- !Tilmeld_1.default.gatekeeper('system/admin')) {
279
+ if (((_a = input.data.abilities) === null || _a === void 0 ? void 0 : _a.indexOf('system/admin')) !== -1 &&
280
+ ((_b = this.$data.abilities) === null || _b === void 0 ? void 0 : _b.indexOf('system/admin')) === -1 &&
281
+ tilmeld.gatekeeper('tilmeld/admin') &&
282
+ !tilmeld.gatekeeper('system/admin')) {
282
283
  throw new errors_1.BadDataError("You don't have the authority to make this user a system admin.");
283
284
  }
284
285
  this.$originalEmail = this.$data.email;
285
286
  super.$jsonAcceptData(input, allowConflict);
286
287
  }
287
288
  $jsonAcceptPatch(patch, allowConflict = false) {
288
- var _a;
289
+ var _a, _b;
290
+ const tilmeld = this.$nymph.tilmeld;
289
291
  this.$referenceWake();
290
- if (patch.set.abilities.indexOf('system/admin') !== -1 &&
291
- ((_a = this.$data.abilities) === null || _a === void 0 ? void 0 : _a.indexOf('system/admin')) === -1 &&
292
- Tilmeld_1.default.gatekeeper('tilmeld/admin') &&
293
- !Tilmeld_1.default.gatekeeper('system/admin')) {
292
+ if (((_a = patch.set.abilities) === null || _a === void 0 ? void 0 : _a.indexOf('system/admin')) !== -1 &&
293
+ ((_b = this.$data.abilities) === null || _b === void 0 ? void 0 : _b.indexOf('system/admin')) === -1 &&
294
+ tilmeld.gatekeeper('tilmeld/admin') &&
295
+ !tilmeld.gatekeeper('system/admin')) {
294
296
  throw new errors_1.BadDataError("You don't have the authority to make this user a system admin.");
295
297
  }
296
298
  this.$originalEmail = this.$data.email;
@@ -302,11 +304,12 @@ class User extends AbleObject_1.default {
302
304
  }
303
305
  $updateDataProtection(givenUser) {
304
306
  var _a;
305
- let user = givenUser !== null && givenUser !== void 0 ? givenUser : User.current();
307
+ const tilmeld = this.$nymph.tilmeld;
308
+ let user = givenUser !== null && givenUser !== void 0 ? givenUser : tilmeld.User.current();
306
309
  this.$clientEnabledMethods = User.DEFAULT_CLIENT_ENABLED_METHODS;
307
310
  this.$privateData = User.DEFAULT_PRIVATE_DATA;
308
311
  this.$allowlistData = User.DEFAULT_ALLOWLIST_DATA;
309
- if (Tilmeld_1.default.config.emailUsernames) {
312
+ if (tilmeld.config.emailUsernames) {
310
313
  this.$privateData.push('username');
311
314
  }
312
315
  const isCurrentUser = user != null && user.$is(this);
@@ -327,20 +330,20 @@ class User extends AbleObject_1.default {
327
330
  this.$allowlistData = undefined;
328
331
  }
329
332
  else if (isCurrentUser || isNewUser) {
330
- if (Tilmeld_1.default.config.allowUsernameChange || isNewUser) {
333
+ if (tilmeld.config.allowUsernameChange || isNewUser) {
331
334
  this.$allowlistData.push('username');
332
335
  }
333
336
  this.$allowlistData.push('avatar');
334
- if (Tilmeld_1.default.config.userFields.indexOf('name') !== -1) {
337
+ if (tilmeld.config.userFields.indexOf('name') !== -1) {
335
338
  this.$allowlistData.push('nameFirst');
336
339
  this.$allowlistData.push('nameMiddle');
337
340
  this.$allowlistData.push('nameLast');
338
341
  this.$allowlistData.push('name');
339
342
  }
340
- if (Tilmeld_1.default.config.userFields.indexOf('email') !== -1) {
343
+ if (tilmeld.config.userFields.indexOf('email') !== -1) {
341
344
  this.$allowlistData.push('email');
342
345
  }
343
- if (Tilmeld_1.default.config.userFields.indexOf('phone') !== -1) {
346
+ if (tilmeld.config.userFields.indexOf('phone') !== -1) {
344
347
  this.$allowlistData.push('phone');
345
348
  }
346
349
  this.$privateData = [
@@ -358,8 +361,9 @@ class User extends AbleObject_1.default {
358
361
  }
359
362
  $gatekeeper(ability) {
360
363
  var _a, _b, _c, _d, _e, _f;
364
+ const tilmeld = this.$nymph.tilmeld;
361
365
  if (ability == null) {
362
- return (_b = (_a = User.current()) === null || _a === void 0 ? void 0 : _a.$is(this)) !== null && _b !== void 0 ? _b : false;
366
+ return (_b = (_a = tilmeld.User.current()) === null || _a === void 0 ? void 0 : _a.$is(this)) !== null && _b !== void 0 ? _b : false;
363
367
  }
364
368
  if (this.$gatekeeperCache == null) {
365
369
  let abilities = (_c = this.$data.abilities) !== null && _c !== void 0 ? _c : [];
@@ -389,16 +393,17 @@ class User extends AbleObject_1.default {
389
393
  $sendEmailVerification() {
390
394
  var _a, _b, _c, _d, _e, _f, _g;
391
395
  return __awaiter(this, void 0, void 0, function* () {
396
+ const tilmeld = this.$nymph.tilmeld;
392
397
  if (this.guid == null) {
393
398
  return false;
394
399
  }
395
400
  let success = true;
396
- const verifyUrl = `${Tilmeld_1.default.config.appUrl.replace(/\/$/, () => '')}${Tilmeld_1.default.config.setupPath}/verify`;
401
+ const verifyUrl = `${tilmeld.config.appUrl.replace(/\/$/, () => '')}${tilmeld.config.setupPath}/verify`;
397
402
  if (this.$data.secret != null) {
398
403
  const link = `${verifyUrl}?action=verify&id=${encodeURIComponent(this.guid)}&secret=${encodeURIComponent(this.$data.secret)}`;
399
404
  success =
400
405
  success &&
401
- (yield Tilmeld_1.default.config.sendEmail({
406
+ (yield tilmeld.config.sendEmail(tilmeld, {
402
407
  template: 'VerifyEmail',
403
408
  message: {
404
409
  to: {
@@ -415,7 +420,7 @@ class User extends AbleObject_1.default {
415
420
  const link = `${verifyUrl}?action=verifychange&id=${encodeURIComponent(this.guid)}&secret=${encodeURIComponent(this.$data.newEmailSecret)}`;
416
421
  success =
417
422
  success &&
418
- (yield Tilmeld_1.default.config.sendEmail({
423
+ (yield tilmeld.config.sendEmail(tilmeld, {
419
424
  template: 'VerifyEmailChange',
420
425
  message: {
421
426
  to: {
@@ -434,7 +439,7 @@ class User extends AbleObject_1.default {
434
439
  const link = `${verifyUrl}?action=cancelchange&id=${encodeURIComponent(this.guid)}&secret=${encodeURIComponent(this.$data.cancelEmailSecret)}`;
435
440
  success =
436
441
  success &&
437
- (yield Tilmeld_1.default.config.sendEmail({
442
+ (yield tilmeld.config.sendEmail(tilmeld, {
438
443
  template: 'CancelEmailChange',
439
444
  message: {
440
445
  to: {
@@ -463,7 +468,8 @@ class User extends AbleObject_1.default {
463
468
  return true;
464
469
  }
465
470
  $checkPassword(password) {
466
- switch (Tilmeld_1.default.config.pwMethod) {
471
+ const tilmeld = this.$nymph.tilmeld;
472
+ switch (tilmeld.config.pwMethod) {
467
473
  case 'plain':
468
474
  return this.$data.password === password;
469
475
  case 'digest':
@@ -534,7 +540,8 @@ class User extends AbleObject_1.default {
534
540
  });
535
541
  }
536
542
  $password(password) {
537
- switch (Tilmeld_1.default.config.pwMethod) {
543
+ const tilmeld = this.$nymph.tilmeld;
544
+ switch (tilmeld.config.pwMethod) {
538
545
  case 'plain':
539
546
  delete this.$data.salt;
540
547
  this.$data.password = password;
@@ -553,29 +560,30 @@ class User extends AbleObject_1.default {
553
560
  }
554
561
  $checkUsername() {
555
562
  return __awaiter(this, void 0, void 0, function* () {
556
- if (!Tilmeld_1.default.config.emailUsernames) {
563
+ const tilmeld = this.$nymph.tilmeld;
564
+ if (!tilmeld.config.emailUsernames) {
557
565
  if (this.$data.username == null || !this.$data.username.length) {
558
566
  return { result: false, message: 'Please specify a username.' };
559
567
  }
560
- if (Tilmeld_1.default.config.maxUsernameLength > 0 &&
561
- this.$data.username.length > Tilmeld_1.default.config.maxUsernameLength) {
568
+ if (tilmeld.config.maxUsernameLength > 0 &&
569
+ this.$data.username.length > tilmeld.config.maxUsernameLength) {
562
570
  return {
563
571
  result: false,
564
572
  message: 'Usernames must not exceed ' +
565
- Tilmeld_1.default.config.maxUsernameLength +
573
+ tilmeld.config.maxUsernameLength +
566
574
  ' characters.',
567
575
  };
568
576
  }
569
- if ((0, lodash_1.difference)(this.$data.username.split(''), Tilmeld_1.default.config.validChars.split('')).length) {
577
+ if ((0, lodash_1.difference)(this.$data.username.split(''), tilmeld.config.validChars.split('')).length) {
570
578
  return {
571
579
  result: false,
572
- message: Tilmeld_1.default.config.validCharsNotice,
580
+ message: tilmeld.config.validCharsNotice,
573
581
  };
574
582
  }
575
- if (!Tilmeld_1.default.config.validRegex.test(this.$data.username)) {
583
+ if (!tilmeld.config.validRegex.test(this.$data.username)) {
576
584
  return {
577
585
  result: false,
578
- message: Tilmeld_1.default.config.validRegexNotice,
586
+ message: tilmeld.config.validRegexNotice,
579
587
  };
580
588
  }
581
589
  const selector = {
@@ -588,7 +596,7 @@ class User extends AbleObject_1.default {
588
596
  if (this.guid != null) {
589
597
  selector['!guid'] = this.guid;
590
598
  }
591
- const test = yield nymph_1.default.getEntity({ class: User, skipAc: true }, selector);
599
+ const test = yield this.$nymph.getEntity({ class: tilmeld.User, skipAc: true }, selector);
592
600
  if (test != null) {
593
601
  return { result: false, message: 'That username is taken.' };
594
602
  }
@@ -602,12 +610,12 @@ class User extends AbleObject_1.default {
602
610
  if (this.$data.username == null || !this.$data.username.length) {
603
611
  return { result: false, message: 'Please specify an email.' };
604
612
  }
605
- if (Tilmeld_1.default.config.maxUsernameLength > 0 &&
606
- this.$data.username.length > Tilmeld_1.default.config.maxUsernameLength) {
613
+ if (tilmeld.config.maxUsernameLength > 0 &&
614
+ this.$data.username.length > tilmeld.config.maxUsernameLength) {
607
615
  return {
608
616
  result: false,
609
617
  message: 'Emails must not exceed ' +
610
- Tilmeld_1.default.config.maxUsernameLength +
618
+ tilmeld.config.maxUsernameLength +
611
619
  ' characters.',
612
620
  };
613
621
  }
@@ -617,18 +625,19 @@ class User extends AbleObject_1.default {
617
625
  }
618
626
  $checkEmail() {
619
627
  return __awaiter(this, void 0, void 0, function* () {
628
+ const tilmeld = this.$nymph.tilmeld;
620
629
  if (this.$data.email == null || !this.$data.email.length) {
621
- if (Tilmeld_1.default.config.verifyEmail) {
630
+ if (tilmeld.config.verifyEmail) {
622
631
  return { result: false, message: 'Please specify an email.' };
623
632
  }
624
633
  else {
625
634
  return { result: true, message: '' };
626
635
  }
627
636
  }
628
- if (!Tilmeld_1.default.config.validEmailRegex.test(this.$data.email)) {
637
+ if (!tilmeld.config.validEmailRegex.test(this.$data.email)) {
629
638
  return {
630
639
  result: false,
631
- message: Tilmeld_1.default.config.validEmailRegexNotice,
640
+ message: tilmeld.config.validEmailRegexNotice,
632
641
  };
633
642
  }
634
643
  const selector = {
@@ -638,7 +647,7 @@ class User extends AbleObject_1.default {
638
647
  if (this.guid != null) {
639
648
  selector['!guid'] = this.guid;
640
649
  }
641
- const test = yield nymph_1.default.getEntity({ class: User, skipAc: true }, selector);
650
+ const test = yield this.$nymph.getEntity({ class: tilmeld.User, skipAc: true }, selector);
642
651
  if (test != null) {
643
652
  return {
644
653
  result: false,
@@ -653,6 +662,7 @@ class User extends AbleObject_1.default {
653
662
  }
654
663
  $checkPhone() {
655
664
  return __awaiter(this, void 0, void 0, function* () {
665
+ const tilmeld = this.$nymph.tilmeld;
656
666
  if (this.$data.phone == null || !this.$data.phone.length) {
657
667
  return { result: false, message: 'Please specify a phone number.' };
658
668
  }
@@ -670,7 +680,7 @@ class User extends AbleObject_1.default {
670
680
  if (this.guid != null) {
671
681
  selector['!guid'] = this.guid;
672
682
  }
673
- const test = yield nymph_1.default.getEntity({ class: User, skipAc: true }, selector);
683
+ const test = yield this.$nymph.getEntity({ class: tilmeld.User, skipAc: true }, selector);
674
684
  if (test != null) {
675
685
  return { result: false, message: 'Phone number is in use.' };
676
686
  }
@@ -682,7 +692,8 @@ class User extends AbleObject_1.default {
682
692
  }
683
693
  $register(data) {
684
694
  return __awaiter(this, void 0, void 0, function* () {
685
- if (!Tilmeld_1.default.config.allowRegistration) {
695
+ const tilmeld = this.$nymph.tilmeld;
696
+ if (!tilmeld.config.allowRegistration) {
686
697
  return {
687
698
  result: false,
688
699
  loggedin: false,
@@ -708,7 +719,7 @@ class User extends AbleObject_1.default {
708
719
  return Object.assign(Object.assign({}, unCheck), { loggedin: false });
709
720
  }
710
721
  this.$password(data.password);
711
- if (Tilmeld_1.default.config.regFields.indexOf('name') !== -1) {
722
+ if (tilmeld.config.regFields.indexOf('name') !== -1) {
712
723
  this.$data.name =
713
724
  this.$data.nameFirst +
714
725
  (this.$data.nameMiddle == null ? '' : ' ' + this.$data.nameMiddle) +
@@ -717,20 +728,20 @@ class User extends AbleObject_1.default {
717
728
  this.$data.name = this.$data.username;
718
729
  }
719
730
  }
720
- if (Tilmeld_1.default.config.emailUsernames) {
731
+ if (tilmeld.config.emailUsernames) {
721
732
  this.$data.email = this.$data.username;
722
733
  }
723
734
  const transaction = 'tilmeld-register-' + (0, nanoid_1.nanoid)();
724
- yield nymph_1.default.startTransaction(transaction);
735
+ const tnymph = yield this.$nymph.startTransaction(transaction);
725
736
  try {
726
737
  let generatedPrimaryGroup = null;
727
- if (Tilmeld_1.default.config.generatePrimary) {
728
- generatedPrimaryGroup = yield Group_1.default.factory();
738
+ if (tilmeld.config.generatePrimary) {
739
+ generatedPrimaryGroup = yield tilmeld.Group.factory();
729
740
  generatedPrimaryGroup.groupname = this.$data.username;
730
741
  generatedPrimaryGroup.avatar = this.$data.avatar;
731
742
  generatedPrimaryGroup.name = this.$data.name;
732
743
  generatedPrimaryGroup.email = this.$data.email;
733
- const parent = yield nymph_1.default.getEntity({ class: Group_1.default }, {
744
+ const parent = yield tnymph.getEntity({ class: tilmeld.Group }, {
734
745
  type: '&',
735
746
  equal: ['defaultPrimary', true],
736
747
  });
@@ -738,7 +749,7 @@ class User extends AbleObject_1.default {
738
749
  generatedPrimaryGroup.parent = parent;
739
750
  }
740
751
  if (!(yield generatedPrimaryGroup.$saveSkipAC())) {
741
- yield nymph_1.default.rollback(transaction);
752
+ yield tnymph.rollback(transaction);
742
753
  return {
743
754
  result: false,
744
755
  loggedin: false,
@@ -748,7 +759,7 @@ class User extends AbleObject_1.default {
748
759
  this.$data.group = generatedPrimaryGroup;
749
760
  }
750
761
  else {
751
- const group = yield nymph_1.default.getEntity({ class: Group_1.default }, {
762
+ const group = yield tnymph.getEntity({ class: tilmeld.Group }, {
752
763
  type: '&',
753
764
  equal: ['defaultPrimary', true],
754
765
  });
@@ -756,20 +767,20 @@ class User extends AbleObject_1.default {
756
767
  this.$data.group = group;
757
768
  }
758
769
  }
759
- if (Tilmeld_1.default.config.verifyEmail && Tilmeld_1.default.config.unverifiedAccess) {
760
- this.$data.groups = yield nymph_1.default.getEntities({ class: Group_1.default }, {
770
+ if (tilmeld.config.verifyEmail && tilmeld.config.unverifiedAccess) {
771
+ this.$data.groups = yield tnymph.getEntities({ class: tilmeld.Group }, {
761
772
  type: '&',
762
773
  equal: ['unverifiedSecondary', true],
763
774
  });
764
775
  }
765
776
  else {
766
- this.$data.groups = yield nymph_1.default.getEntities({ class: Group_1.default }, {
777
+ this.$data.groups = yield tnymph.getEntities({ class: tilmeld.Group }, {
767
778
  type: '&',
768
779
  equal: ['defaultSecondary', true],
769
780
  });
770
781
  }
771
- if (Tilmeld_1.default.config.verifyEmail) {
772
- if (!Tilmeld_1.default.config.unverifiedAccess) {
782
+ if (tilmeld.config.verifyEmail) {
783
+ if (!tilmeld.config.unverifiedAccess) {
773
784
  this.$data.enabled = false;
774
785
  }
775
786
  }
@@ -777,9 +788,9 @@ class User extends AbleObject_1.default {
777
788
  this.$data.enabled = true;
778
789
  }
779
790
  let madeAdmin = false;
780
- if (Tilmeld_1.default.config.createAdmin) {
781
- const otherUsers = yield nymph_1.default.getEntities({
782
- class: User,
791
+ if (tilmeld.config.createAdmin) {
792
+ const otherUsers = yield tnymph.getEntities({
793
+ class: tilmeld.User,
783
794
  skipAc: true,
784
795
  limit: 1,
785
796
  return: 'guid',
@@ -791,11 +802,11 @@ class User extends AbleObject_1.default {
791
802
  }
792
803
  }
793
804
  if (yield this.$saveSkipAC()) {
794
- if (Tilmeld_1.default.config.userRegisteredRecipient != null) {
795
- yield Tilmeld_1.default.config.sendEmail({
805
+ if (tilmeld.config.userRegisteredRecipient != null) {
806
+ yield tilmeld.config.sendEmail(tilmeld, {
796
807
  template: 'UserRegistered',
797
808
  message: {
798
- to: Tilmeld_1.default.config.userRegisteredRecipient,
809
+ to: tilmeld.config.userRegisteredRecipient,
799
810
  },
800
811
  locals: {
801
812
  userUsername: this.$data.username,
@@ -812,7 +823,7 @@ class User extends AbleObject_1.default {
812
823
  if (generatedPrimaryGroup != null) {
813
824
  generatedPrimaryGroup.user = this;
814
825
  if (!(yield generatedPrimaryGroup.$saveSkipAC())) {
815
- yield nymph_1.default.rollback(transaction);
826
+ yield tnymph.rollback(transaction);
816
827
  return {
817
828
  result: false,
818
829
  loggedin: false,
@@ -820,17 +831,17 @@ class User extends AbleObject_1.default {
820
831
  };
821
832
  }
822
833
  }
823
- if (Tilmeld_1.default.config.verifyEmail &&
824
- !Tilmeld_1.default.config.unverifiedAccess &&
834
+ if (tilmeld.config.verifyEmail &&
835
+ !tilmeld.config.unverifiedAccess &&
825
836
  !madeAdmin) {
826
837
  message +=
827
838
  `Almost there. An email has been sent to ${this.$data.email} ` +
828
839
  'with a verification link for you to finish registration.';
829
840
  }
830
- else if (Tilmeld_1.default.config.verifyEmail &&
831
- Tilmeld_1.default.config.unverifiedAccess &&
841
+ else if (tilmeld.config.verifyEmail &&
842
+ tilmeld.config.unverifiedAccess &&
832
843
  !madeAdmin) {
833
- Tilmeld_1.default.login(this, true);
844
+ tilmeld.login(this, true);
834
845
  message +=
835
846
  "You're now logged in! An email has been sent to " +
836
847
  `${this.$data.email} with a verification link for you to finish ` +
@@ -838,11 +849,11 @@ class User extends AbleObject_1.default {
838
849
  loggedin = true;
839
850
  }
840
851
  else {
841
- Tilmeld_1.default.login(this, true);
852
+ tilmeld.login(this, true);
842
853
  message += "You're now registered and logged in!";
843
854
  loggedin = true;
844
855
  }
845
- yield nymph_1.default.commit(transaction);
856
+ yield tnymph.commit(transaction);
846
857
  return {
847
858
  result: true,
848
859
  loggedin,
@@ -850,7 +861,7 @@ class User extends AbleObject_1.default {
850
861
  };
851
862
  }
852
863
  else {
853
- yield nymph_1.default.rollback(transaction);
864
+ yield tnymph.rollback(transaction);
854
865
  return {
855
866
  result: false,
856
867
  loggedin: false,
@@ -859,7 +870,7 @@ class User extends AbleObject_1.default {
859
870
  }
860
871
  }
861
872
  catch (e) {
862
- yield nymph_1.default.rollback(transaction);
873
+ yield tnymph.rollback(transaction);
863
874
  throw e;
864
875
  }
865
876
  });
@@ -870,17 +881,18 @@ class User extends AbleObject_1.default {
870
881
  });
871
882
  var _a, _b, _c, _d, _e, _f;
872
883
  return __awaiter(this, void 0, void 0, function* () {
884
+ const tilmeld = this.$nymph.tilmeld;
873
885
  if (this.$data.username == null || !this.$data.username.trim().length) {
874
886
  return false;
875
887
  }
876
- if (Tilmeld_1.default.gatekeeper('tilmeld/admin') &&
877
- !Tilmeld_1.default.gatekeeper('system/admin') &&
888
+ if (tilmeld.gatekeeper('tilmeld/admin') &&
889
+ !tilmeld.gatekeeper('system/admin') &&
878
890
  this.$gatekeeper('system/admin')) {
879
891
  throw new errors_1.BadDataError("You don't have the authority to modify system admins.");
880
892
  }
881
893
  let sendVerification = false;
882
894
  this.$data.username = this.$data.username.trim();
883
- if (Tilmeld_1.default.config.emailUsernames) {
895
+ if (tilmeld.config.emailUsernames) {
884
896
  this.$data.email = this.$data.username;
885
897
  }
886
898
  this.$data.nameFirst = ((_a = this.$data.nameFirst) !== null && _a !== void 0 ? _a : '').trim();
@@ -950,14 +962,14 @@ class User extends AbleObject_1.default {
950
962
  if (!unCheck.result) {
951
963
  throw new errors_1.BadUsernameError(unCheck.message);
952
964
  }
953
- if (!Tilmeld_1.default.config.emailUsernames) {
965
+ if (!tilmeld.config.emailUsernames) {
954
966
  const emCheck = yield this.$checkEmail();
955
967
  if (!emCheck.result) {
956
968
  throw new errors_1.BadEmailError(emCheck.message);
957
969
  }
958
970
  }
959
- if (!Tilmeld_1.default.gatekeeper('tilmeld/admin')) {
960
- if (Tilmeld_1.default.config.verifyEmail) {
971
+ if (!tilmeld.gatekeeper('tilmeld/admin')) {
972
+ if (tilmeld.config.verifyEmail) {
961
973
  if (this.guid == null) {
962
974
  if (((_f = (_e = this.$data.abilities) === null || _e === void 0 ? void 0 : _e.indexOf('system/admin')) !== null && _f !== void 0 ? _f : -1) === -1) {
963
975
  this.$data.secret = (0, nanoid_1.nanoid)();
@@ -966,27 +978,27 @@ class User extends AbleObject_1.default {
966
978
  }
967
979
  else if (this.$originalEmail != null &&
968
980
  this.$originalEmail !== this.$data.email) {
969
- if (Tilmeld_1.default.config.emailRateLimit !== '' &&
981
+ if (tilmeld.config.emailRateLimit !== '' &&
970
982
  this.$data.emailChangeDate != null &&
971
983
  this.$data.emailChangeDate >=
972
- (0, strtotime_1.default)('-' + Tilmeld_1.default.config.emailRateLimit) * 1000) {
984
+ (0, strtotime_1.default)('-' + tilmeld.config.emailRateLimit) * 1000) {
973
985
  throw new errors_1.EmailChangeRateLimitExceededError('You already changed your email address recently. Please wait until ' +
974
- new Date((0, strtotime_1.default)('+' + Tilmeld_1.default.config.emailRateLimit, Math.floor(this.$data.emailChangeDate / 1000)) * 1000).toString() +
986
+ new Date((0, strtotime_1.default)('+' + tilmeld.config.emailRateLimit, Math.floor(this.$data.emailChangeDate / 1000)) * 1000).toString() +
975
987
  ' to change your email address again.');
976
988
  }
977
989
  else {
978
990
  if (this.$data.newEmailSecret == null &&
979
- Tilmeld_1.default.config.emailRateLimit !== '' &&
991
+ tilmeld.config.emailRateLimit !== '' &&
980
992
  (this.$data.emailChangeDate == null ||
981
993
  this.$data.emailChangeDate <
982
- (0, strtotime_1.default)('-' + Tilmeld_1.default.config.emailRateLimit) * 1000)) {
994
+ (0, strtotime_1.default)('-' + tilmeld.config.emailRateLimit) * 1000)) {
983
995
  this.$data.cancelEmailAddress = this.$originalEmail;
984
996
  this.$data.cancelEmailSecret = (0, nanoid_1.nanoid)();
985
997
  this.$data.emailChangeDate = Date.now();
986
998
  }
987
999
  this.$data.newEmailAddress = this.$data.email;
988
1000
  this.$data.email = this.$originalEmail;
989
- if (Tilmeld_1.default.config.emailUsernames) {
1001
+ if (tilmeld.config.emailUsernames) {
990
1002
  this.$data.username = this.$data.email;
991
1003
  }
992
1004
  this.$data.newEmailSecret = (0, nanoid_1.nanoid)();
@@ -999,7 +1011,7 @@ class User extends AbleObject_1.default {
999
1011
  this.$originalEmail !== this.$data.email &&
1000
1012
  (this.$data.emailChangeDate == null ||
1001
1013
  this.$data.emailChangeDate <
1002
- (0, strtotime_1.default)('-' + Tilmeld_1.default.config.emailRateLimit) * 1000)) {
1014
+ (0, strtotime_1.default)('-' + tilmeld.config.emailRateLimit) * 1000)) {
1003
1015
  this.$data.cancelEmailAddress = this.$originalEmail;
1004
1016
  this.$data.cancelEmailSecret = (0, nanoid_1.nanoid)();
1005
1017
  sendVerification = true;
@@ -1013,13 +1025,13 @@ class User extends AbleObject_1.default {
1013
1025
  throw new errors_1.BadDataError('A password is required.');
1014
1026
  }
1015
1027
  try {
1016
- Tilmeld_1.default.config.validatorUser(this);
1028
+ tilmeld.config.validatorUser(this);
1017
1029
  }
1018
1030
  catch (e) {
1019
1031
  throw new errors_1.BadDataError(e === null || e === void 0 ? void 0 : e.message);
1020
1032
  }
1021
1033
  const transaction = 'tilmeld-save-' + (0, nanoid_1.nanoid)();
1022
- yield nymph_1.default.startTransaction(transaction);
1034
+ const tnymph = yield this.$nymph.startTransaction(transaction);
1023
1035
  if (this.$data.group != null &&
1024
1036
  this.$data.group.user != null &&
1025
1037
  this.$is(this.$data.group.user)) {
@@ -1032,7 +1044,7 @@ class User extends AbleObject_1.default {
1032
1044
  yield this.$data.group.$saveSkipAC();
1033
1045
  }
1034
1046
  catch (e) {
1035
- yield nymph_1.default.rollback(transaction);
1047
+ yield tnymph.rollback(transaction);
1036
1048
  throw e;
1037
1049
  }
1038
1050
  }
@@ -1044,28 +1056,28 @@ class User extends AbleObject_1.default {
1044
1056
  ret = yield _super.$save.call(this);
1045
1057
  }
1046
1058
  catch (e) {
1047
- yield nymph_1.default.rollback(transaction);
1059
+ yield tnymph.rollback(transaction);
1048
1060
  throw e;
1049
1061
  }
1050
1062
  if (ret) {
1051
1063
  if (sendVerification) {
1052
1064
  if (!(yield this.$sendEmailVerification())) {
1053
- yield nymph_1.default.rollback(transaction);
1065
+ yield tnymph.rollback(transaction);
1054
1066
  this.guid = preGuid;
1055
1067
  this.cdate = preCdate;
1056
1068
  this.mdate = preMdate;
1057
1069
  throw new Error("Couldn't send verification email.");
1058
1070
  }
1059
1071
  }
1060
- if (User.current(true).$is(this)) {
1061
- Tilmeld_1.default.fillSession(this);
1072
+ if (tilmeld.User.current(true).$is(this)) {
1073
+ tilmeld.fillSession(this);
1062
1074
  }
1063
1075
  this.$descendantGroups = undefined;
1064
1076
  this.$gatekeeperCache = undefined;
1065
- yield nymph_1.default.commit(transaction);
1077
+ yield tnymph.commit(transaction);
1066
1078
  }
1067
1079
  else {
1068
- yield nymph_1.default.rollback(transaction);
1080
+ yield tnymph.rollback(transaction);
1069
1081
  }
1070
1082
  return ret;
1071
1083
  });
@@ -1088,14 +1100,15 @@ class User extends AbleObject_1.default {
1088
1100
  $delete: { get: () => super.$delete }
1089
1101
  });
1090
1102
  return __awaiter(this, void 0, void 0, function* () {
1091
- if (!Tilmeld_1.default.gatekeeper('tilmeld/admin')) {
1103
+ const tilmeld = this.$nymph.tilmeld;
1104
+ if (!tilmeld.gatekeeper('tilmeld/admin')) {
1092
1105
  throw new errors_1.BadDataError("You don't have the authority to delete users.");
1093
1106
  }
1094
- if (!Tilmeld_1.default.gatekeeper('system/admin') &&
1107
+ if (!tilmeld.gatekeeper('system/admin') &&
1095
1108
  this.$gatekeeper('system/admin')) {
1096
1109
  throw new errors_1.BadDataError("You don't have the authority to delete system admins.");
1097
1110
  }
1098
- if (User.current(true).$is(this)) {
1111
+ if (tilmeld.User.current(true).$is(this)) {
1099
1112
  this.$logout();
1100
1113
  }
1101
1114
  return yield _super.$delete.call(this);
@@ -1140,5 +1153,4 @@ User.clientEnabledStaticMethods = [
1140
1153
  'getClientConfig',
1141
1154
  ];
1142
1155
  User.searchRestrictedData = User.DEFAULT_PRIVATE_DATA;
1143
- nymph_1.default.setEntityClass(User.class, User);
1144
1156
  //# sourceMappingURL=User.js.map