@nymphjs/tilmeld 1.0.0-beta.13 → 1.0.0-beta.131
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/CHANGELOG.md +604 -0
- package/README.md +21 -5
- package/dist/AbleObject.d.ts +15 -0
- package/dist/AbleObject.js +18 -6
- package/dist/AbleObject.js.map +1 -1
- package/dist/Group.d.ts +183 -19
- package/dist/Group.js +814 -440
- package/dist/Group.js.map +1 -1
- package/dist/Group.testArtifacts.d.ts +3 -0
- package/dist/Group.testArtifacts.js +120 -0
- package/dist/Group.testArtifacts.js.map +1 -0
- package/dist/Tilmeld.d.ts +241 -12
- package/dist/Tilmeld.js +725 -286
- package/dist/Tilmeld.js.map +1 -1
- package/dist/Tilmeld.types.d.ts +5 -5
- package/dist/Tilmeld.types.js +1 -2
- package/dist/User.d.ts +396 -26
- package/dist/User.js +1955 -1058
- package/dist/User.js.map +1 -1
- package/dist/User.testArtifacts.d.ts +3 -0
- package/dist/User.testArtifacts.js +175 -0
- package/dist/User.testArtifacts.js.map +1 -0
- package/dist/conf/defaults.d.ts +1 -1
- package/dist/conf/defaults.js +196 -141
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +355 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/requireAbility.d.ts +10 -0
- package/dist/decorators/requireAbility.js +21 -0
- package/dist/decorators/requireAbility.js.map +1 -0
- package/dist/decorators/requireAuthentication.d.ts +8 -0
- package/dist/decorators/requireAuthentication.js +16 -0
- package/dist/decorators/requireAuthentication.js.map +1 -0
- package/dist/enforceTilmeld.d.ts +3 -0
- package/dist/enforceTilmeld.js +18 -0
- package/dist/enforceTilmeld.js.map +1 -0
- package/dist/errors/AccessControlError.d.ts +2 -1
- package/dist/errors/AccessControlError.js +3 -6
- package/dist/errors/AccessControlError.js.map +1 -1
- package/dist/errors/BadDataError.d.ts +2 -1
- package/dist/errors/BadDataError.js +3 -6
- package/dist/errors/BadDataError.js.map +1 -1
- package/dist/errors/BadEmailError.d.ts +2 -1
- package/dist/errors/BadEmailError.js +3 -6
- package/dist/errors/BadEmailError.js.map +1 -1
- package/dist/errors/BadUsernameError.d.ts +2 -1
- package/dist/errors/BadUsernameError.js +3 -6
- package/dist/errors/BadUsernameError.js.map +1 -1
- package/dist/errors/CouldNotChangeDefaultPrimaryGroupError.js +1 -5
- package/dist/errors/CouldNotChangeDefaultPrimaryGroupError.js.map +1 -1
- package/dist/errors/EmailChangeRateLimitExceededError.js +1 -5
- package/dist/errors/EmailChangeRateLimitExceededError.js.map +1 -1
- package/dist/errors/index.d.ts +6 -6
- package/dist/errors/index.js +6 -22
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.js +17 -35
- package/dist/index.js.map +1 -1
- package/dist/testArtifacts.d.ts +23 -0
- package/dist/testArtifacts.js +1317 -0
- package/dist/testArtifacts.js.map +1 -0
- package/dist/tilmeldJoiProps.d.ts +3 -3
- package/dist/tilmeldJoiProps.js +13 -18
- package/dist/tilmeldJoiProps.js.map +1 -1
- package/jest.config.js +31 -5
- package/package.json +49 -36
- package/src/AbleObject.ts +2 -2
- package/src/Group.testArtifacts.ts +159 -0
- package/src/Group.ts +647 -241
- package/src/Tilmeld.ts +550 -315
- package/src/Tilmeld.types.ts +5 -5
- package/src/User.testArtifacts.ts +226 -0
- package/src/User.ts +1657 -637
- package/src/conf/defaults.ts +172 -109
- package/src/conf/index.ts +370 -2
- package/src/decorators/index.ts +2 -0
- package/src/decorators/requireAbility.ts +26 -0
- package/src/decorators/requireAuthentication.ts +19 -0
- package/src/enforceTilmeld.ts +20 -0
- package/src/errors/AccessControlError.ts +4 -2
- package/src/errors/BadDataError.ts +4 -2
- package/src/errors/BadEmailError.ts +4 -2
- package/src/errors/BadUsernameError.ts +4 -2
- package/src/errors/index.ts +6 -6
- package/src/index.ts +13 -10
- package/src/testArtifacts.ts +2098 -0
- package/src/tilmeldJoiProps.ts +8 -23
- package/tsconfig.json +6 -3
- package/typedoc.json +4 -0
- package/dist/Group.test.d.ts +0 -1
- package/dist/Group.test.js +0 -48
- package/dist/Group.test.js.map +0 -1
- package/dist/User.test.d.ts +0 -1
- package/dist/User.test.js +0 -51
- package/dist/User.test.js.map +0 -1
- package/dist/conf/d.d.ts +0 -55
- package/dist/conf/d.js +0 -3
- package/dist/conf/d.js.map +0 -1
- package/src/Group.test.ts +0 -58
- package/src/User.test.ts +0 -61
- package/src/conf/d.ts +0 -303
package/dist/User.d.ts
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
1
|
-
import { EntityData, EntityJson, EntityPatch, SerializedEntityData } from '@nymphjs/nymph';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
export type EventType = 'beforeRegister' | 'afterRegister' | 'beforeLogin' | 'afterLogin' | 'beforeLogout' | 'afterLogout';
|
|
1
|
+
import { type EntityData, type EntityJson, type EntityPatch, type SerializedEntityData } from '@nymphjs/nymph';
|
|
2
|
+
import AbleObject from './AbleObject.js';
|
|
3
|
+
import GroupClass from './Group.js';
|
|
4
|
+
import type { GroupData } from './Group.js';
|
|
5
|
+
export type EventType = 'checkUsername' | 'beforeRegister' | 'afterRegister' | 'beforeSave' | 'afterSave' | 'beforeLogin' | 'afterLogin' | 'beforeLogout' | 'afterLogout' | 'beforeDelete' | 'afterDelete';
|
|
6
|
+
/**
|
|
7
|
+
* This is run when the user has entered an otherwise valid username into the
|
|
8
|
+
* signup form. It should return a result, which when false will stop the
|
|
9
|
+
* process and return the included message, disallowing the username.
|
|
10
|
+
*/
|
|
11
|
+
export type TilmeldCheckUsernameCallback = (user: User & UserData, data: {
|
|
12
|
+
username: string;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
result: boolean;
|
|
15
|
+
message?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* This is run before the user data checks, so the only checks before are
|
|
19
|
+
* whether registration is allowed and whether the user is already registered.
|
|
20
|
+
*/
|
|
6
21
|
export type TilmeldBeforeRegisterCallback = (user: User & UserData, data: {
|
|
7
22
|
password: string;
|
|
8
23
|
additionalData?: {
|
|
9
24
|
[k: string]: any;
|
|
10
25
|
};
|
|
11
26
|
}) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* This is run before the transaction is committed, and you can perform
|
|
29
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
30
|
+
*/
|
|
12
31
|
export type TilmeldAfterRegisterCallback = (user: User & UserData, result: {
|
|
13
32
|
loggedin: boolean;
|
|
14
33
|
message: string;
|
|
15
34
|
}) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* This is run just before the user is saved, so all checks have passed.
|
|
37
|
+
*
|
|
38
|
+
* The transaction is available in `user.$nymph`.
|
|
39
|
+
*/
|
|
40
|
+
export type TilmeldBeforeSaveCallback = (user: User & UserData) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* This is run before the transaction is committed, and you can perform
|
|
43
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
44
|
+
*
|
|
45
|
+
* This is run after a new email verification email has been sent, so throwing
|
|
46
|
+
* an error will cause confusion for the user if they've changed their email.
|
|
47
|
+
*/
|
|
48
|
+
export type TilmeldAfterSaveCallback = (user: User & UserData) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* This is run after the authentication checks, but before the login action.
|
|
51
|
+
*/
|
|
16
52
|
export type TilmeldBeforeLoginCallback = (user: User & UserData, data: {
|
|
17
53
|
username: string;
|
|
18
54
|
password: string;
|
|
@@ -23,42 +59,151 @@ export type TilmeldBeforeLoginCallback = (user: User & UserData, data: {
|
|
|
23
59
|
export type TilmeldAfterLoginCallback = (user: User & UserData) => Promise<void>;
|
|
24
60
|
export type TilmeldBeforeLogoutCallback = (user: User & UserData) => Promise<void>;
|
|
25
61
|
export type TilmeldAfterLogoutCallback = (user: User & UserData) => Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* This is run before the user is logged out (if the current user is being
|
|
64
|
+
* deleted).
|
|
65
|
+
*
|
|
66
|
+
* The transaction is available in `user.$nymph`.
|
|
67
|
+
*/
|
|
68
|
+
export type TilmeldBeforeDeleteCallback = (user: User & UserData) => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* This is run before the transaction is committed, and you can perform
|
|
71
|
+
* additional functions on the transaction, which is available in `user.$nymph`.
|
|
72
|
+
*/
|
|
73
|
+
export type TilmeldAfterDeleteCallback = (user: User & UserData) => Promise<void>;
|
|
26
74
|
export type UserData = {
|
|
75
|
+
/**
|
|
76
|
+
* The abilities granted to the user.
|
|
77
|
+
*/
|
|
27
78
|
abilities?: string[];
|
|
79
|
+
/**
|
|
80
|
+
* The user's username.
|
|
81
|
+
*/
|
|
28
82
|
username?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The user's first name.
|
|
85
|
+
*/
|
|
29
86
|
nameFirst?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The user's middle name.
|
|
89
|
+
*/
|
|
30
90
|
nameMiddle?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The user's last name.
|
|
93
|
+
*/
|
|
31
94
|
nameLast?: string;
|
|
95
|
+
/**
|
|
96
|
+
* The user's full name. This is generated from the first, middle, and last
|
|
97
|
+
* names.
|
|
98
|
+
*/
|
|
32
99
|
name?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The user's email address.
|
|
102
|
+
*/
|
|
33
103
|
email?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The user's avatar URL. (Use $getAvatar() to support Gravatar.)
|
|
106
|
+
*/
|
|
34
107
|
avatar?: string;
|
|
108
|
+
/**
|
|
109
|
+
* The user's telephone number.
|
|
110
|
+
*/
|
|
35
111
|
phone?: string;
|
|
36
|
-
|
|
37
|
-
|
|
112
|
+
/**
|
|
113
|
+
* The user's primary group.
|
|
114
|
+
*/
|
|
115
|
+
group?: GroupClass & GroupData;
|
|
116
|
+
/**
|
|
117
|
+
* The user's secondary groups.
|
|
118
|
+
*/
|
|
119
|
+
groups?: (GroupClass & GroupData)[];
|
|
120
|
+
/**
|
|
121
|
+
* Whether the user should inherit the abilities of his groups.
|
|
122
|
+
*/
|
|
38
123
|
inheritAbilities?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Whether the user can log in.
|
|
126
|
+
*/
|
|
39
127
|
enabled?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* A verification secret.
|
|
130
|
+
*/
|
|
40
131
|
secret?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The timestamp of when the email address was last changed.
|
|
134
|
+
*/
|
|
41
135
|
emailChangeDate?: number;
|
|
136
|
+
/**
|
|
137
|
+
* An email change proceed secret.
|
|
138
|
+
*/
|
|
42
139
|
newEmailSecret?: string;
|
|
140
|
+
/**
|
|
141
|
+
* If the user has changed their email address, this is the new one, awaiting
|
|
142
|
+
* verification.
|
|
143
|
+
*/
|
|
43
144
|
newEmailAddress?: string;
|
|
145
|
+
/**
|
|
146
|
+
* An email change cancellation secret.
|
|
147
|
+
*/
|
|
44
148
|
cancelEmailSecret?: string;
|
|
149
|
+
/**
|
|
150
|
+
* The old email address.
|
|
151
|
+
*/
|
|
45
152
|
cancelEmailAddress?: string;
|
|
153
|
+
/**
|
|
154
|
+
* A recovery secret.
|
|
155
|
+
*/
|
|
46
156
|
recoverSecret?: string;
|
|
157
|
+
/**
|
|
158
|
+
* The timestamp of when the recovery secret was issued.
|
|
159
|
+
*/
|
|
47
160
|
recoverSecretDate?: number;
|
|
161
|
+
/**
|
|
162
|
+
* The password hash salt.
|
|
163
|
+
*/
|
|
48
164
|
salt?: string;
|
|
165
|
+
/**
|
|
166
|
+
* The password or password hash.
|
|
167
|
+
*/
|
|
49
168
|
password?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Temporary storage for passwords. This will be hashed before going into the
|
|
171
|
+
* database.
|
|
172
|
+
*/
|
|
50
173
|
passwordTemp?: string;
|
|
174
|
+
/**
|
|
175
|
+
* If set, this timestamp is the cutoff point for JWT issue dates. Any token
|
|
176
|
+
* issued before this date will not authenticate the user.
|
|
177
|
+
*/
|
|
178
|
+
revokeTokenDate?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Two factor auth secret.
|
|
181
|
+
*/
|
|
182
|
+
totpSecret?: string;
|
|
51
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* A user data model.
|
|
186
|
+
*
|
|
187
|
+
* Written by Hunter Perrin for SciActive.
|
|
188
|
+
*
|
|
189
|
+
* @author Hunter Perrin <hperrin@port87.com>
|
|
190
|
+
* @copyright SciActive Inc
|
|
191
|
+
* @see http://nymph.io/
|
|
192
|
+
*/
|
|
52
193
|
export default class User extends AbleObject<UserData> {
|
|
53
|
-
static tilmeld: Tilmeld;
|
|
54
194
|
static ETYPE: string;
|
|
55
195
|
static class: string;
|
|
196
|
+
private static checkUsernameCallbacks;
|
|
56
197
|
private static beforeRegisterCallbacks;
|
|
57
198
|
private static afterRegisterCallbacks;
|
|
199
|
+
private static beforeSaveCallbacks;
|
|
200
|
+
private static afterSaveCallbacks;
|
|
58
201
|
private static beforeLoginCallbacks;
|
|
59
202
|
private static afterLoginCallbacks;
|
|
60
203
|
private static beforeLogoutCallbacks;
|
|
61
204
|
private static afterLogoutCallbacks;
|
|
205
|
+
private static beforeDeleteCallbacks;
|
|
206
|
+
private static afterDeleteCallbacks;
|
|
62
207
|
private static DEFAULT_CLIENT_ENABLED_METHODS;
|
|
63
208
|
private static DEFAULT_PRIVATE_DATA;
|
|
64
209
|
private static DEFAULT_ALLOWLIST_DATA;
|
|
@@ -68,16 +213,47 @@ export default class User extends AbleObject<UserData> {
|
|
|
68
213
|
static searchRestrictedData: string[];
|
|
69
214
|
protected $allowlistData?: string[] | undefined;
|
|
70
215
|
protected $allowlistTags?: string[];
|
|
216
|
+
/**
|
|
217
|
+
* Gatekeeper ability cache.
|
|
218
|
+
*
|
|
219
|
+
* Gatekeeper will cache the user's abilities that it calculates, so it can
|
|
220
|
+
* check faster if that user has been checked before.
|
|
221
|
+
*/
|
|
71
222
|
private $gatekeeperCache?;
|
|
223
|
+
/**
|
|
224
|
+
* This should only be used by the backend.
|
|
225
|
+
*/
|
|
72
226
|
private $skipAcWhenSaving;
|
|
227
|
+
/**
|
|
228
|
+
* This should only be used by the backend.
|
|
229
|
+
*/
|
|
230
|
+
private $skipAcWhenDeleting;
|
|
231
|
+
/**
|
|
232
|
+
* The user's group descendants.
|
|
233
|
+
*/
|
|
73
234
|
private $descendantGroups?;
|
|
235
|
+
/**
|
|
236
|
+
* Used to save the current email address to send verification if it changes
|
|
237
|
+
* from the frontend.
|
|
238
|
+
*
|
|
239
|
+
* If you are changing a user's email address and want to bypass email
|
|
240
|
+
* verification, don't set this.
|
|
241
|
+
*/
|
|
74
242
|
$originalEmail?: string;
|
|
75
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Used to save the current username for domain admin permissions.
|
|
245
|
+
*/
|
|
246
|
+
$originalUsername?: string;
|
|
247
|
+
static getFTSText(name: string, value: any): string | null;
|
|
76
248
|
static factoryUsername(username?: string): Promise<User & UserData>;
|
|
77
|
-
static factorySync(guid?: string): User & UserData;
|
|
78
|
-
constructor(guid?: string);
|
|
79
249
|
static current(returnObjectIfNotExist: true): User & UserData;
|
|
80
250
|
static current(returnObjectIfNotExist?: false): (User & UserData) | null;
|
|
251
|
+
/**
|
|
252
|
+
* Send an account recovery link.
|
|
253
|
+
*
|
|
254
|
+
* @param data The input data from the client.
|
|
255
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
256
|
+
*/
|
|
81
257
|
static sendRecovery(data: {
|
|
82
258
|
recoveryType: 'username' | 'password';
|
|
83
259
|
account: string;
|
|
@@ -85,6 +261,12 @@ export default class User extends AbleObject<UserData> {
|
|
|
85
261
|
result: boolean;
|
|
86
262
|
message: string;
|
|
87
263
|
}>;
|
|
264
|
+
/**
|
|
265
|
+
* Recover account details.
|
|
266
|
+
*
|
|
267
|
+
* @param data The input data from the client.
|
|
268
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
269
|
+
*/
|
|
88
270
|
static recover(data: {
|
|
89
271
|
username: string;
|
|
90
272
|
secret: string;
|
|
@@ -97,6 +279,7 @@ export default class User extends AbleObject<UserData> {
|
|
|
97
279
|
regFields: string[];
|
|
98
280
|
userFields: string[];
|
|
99
281
|
emailUsernames: boolean;
|
|
282
|
+
domainSupport: boolean;
|
|
100
283
|
allowRegistration: boolean;
|
|
101
284
|
allowUsernameChange: boolean;
|
|
102
285
|
pwRecovery: boolean;
|
|
@@ -106,59 +289,241 @@ export default class User extends AbleObject<UserData> {
|
|
|
106
289
|
static loginUser(data: {
|
|
107
290
|
username: string;
|
|
108
291
|
password: string;
|
|
292
|
+
code?: string;
|
|
109
293
|
additionalData?: {
|
|
110
294
|
[k: string]: any;
|
|
111
295
|
};
|
|
112
296
|
}): Promise<{
|
|
113
297
|
result: boolean;
|
|
114
298
|
message: string;
|
|
115
|
-
user?:
|
|
299
|
+
user?: User & UserData;
|
|
116
300
|
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Get the users in a domain. This is only accessible to the domain's admins.
|
|
303
|
+
*/
|
|
304
|
+
static getDomainUsers(domain: string, options?: {
|
|
305
|
+
limit?: number;
|
|
306
|
+
offset?: number;
|
|
307
|
+
sort?: string;
|
|
308
|
+
reverse?: boolean;
|
|
309
|
+
}): Promise<(User & UserData)[]>;
|
|
310
|
+
constructor();
|
|
311
|
+
$getUniques(): Promise<string[]>;
|
|
117
312
|
$login(data: {
|
|
118
313
|
username: string;
|
|
119
314
|
password: string;
|
|
315
|
+
code?: string;
|
|
120
316
|
additionalData?: {
|
|
121
317
|
[k: string]: any;
|
|
122
318
|
};
|
|
123
319
|
}): Promise<{
|
|
320
|
+
result: boolean;
|
|
321
|
+
needTOTP: boolean;
|
|
322
|
+
message: string;
|
|
323
|
+
} | {
|
|
324
|
+
needTOTP?: undefined;
|
|
124
325
|
result: boolean;
|
|
125
326
|
message: any;
|
|
126
327
|
}>;
|
|
328
|
+
$switchUser(data?: {
|
|
329
|
+
additionalData?: {
|
|
330
|
+
[k: string]: any;
|
|
331
|
+
};
|
|
332
|
+
}): Promise<{
|
|
333
|
+
result: boolean;
|
|
334
|
+
message: string;
|
|
335
|
+
}>;
|
|
336
|
+
/**
|
|
337
|
+
* Log a user out of the system.
|
|
338
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
339
|
+
*/
|
|
127
340
|
$logout(): Promise<{
|
|
128
341
|
result: boolean;
|
|
129
|
-
message:
|
|
342
|
+
message: string;
|
|
130
343
|
}>;
|
|
131
344
|
$getAvatar(): string;
|
|
132
|
-
$
|
|
133
|
-
$
|
|
345
|
+
$getGid(): string | null;
|
|
346
|
+
$getGids(): string[] | null;
|
|
347
|
+
/**
|
|
348
|
+
* Get the user's group descendants.
|
|
349
|
+
*/
|
|
350
|
+
$getDescendantGroups(): Promise<(GroupClass & GroupData)[]>;
|
|
134
351
|
$jsonAcceptData(input: EntityJson, allowConflict?: boolean): void;
|
|
135
352
|
$jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
|
|
136
|
-
$
|
|
353
|
+
private $checkIncomingAbilities;
|
|
354
|
+
$putData(data: EntityData, sdata?: SerializedEntityData, source?: 'server'): void;
|
|
355
|
+
/**
|
|
356
|
+
* Update the data protection arrays for a user.
|
|
357
|
+
*
|
|
358
|
+
* @param givenUser User to update protection for. If undefined, will use the currently logged in user.
|
|
359
|
+
*/
|
|
137
360
|
$updateDataProtection(givenUser?: User & UserData): void;
|
|
138
|
-
$
|
|
361
|
+
$updateGroupDataProtection(): void;
|
|
362
|
+
/**
|
|
363
|
+
* Check to see if a user has an ability.
|
|
364
|
+
*
|
|
365
|
+
* This function will check both user and group abilities, if the user is
|
|
366
|
+
* marked to inherit the abilities of its group.
|
|
367
|
+
*
|
|
368
|
+
* If `ability` is undefined, it will check to see if the user is currently
|
|
369
|
+
* logged in.
|
|
370
|
+
*
|
|
371
|
+
* If the user has the "system/admin" ability, this function will return true.
|
|
372
|
+
*
|
|
373
|
+
* @param ability The ability.
|
|
374
|
+
* @returns True or false.
|
|
375
|
+
*/
|
|
376
|
+
$gatekeeper(ability?: string): Promise<boolean>;
|
|
377
|
+
/**
|
|
378
|
+
* Build a gatekeeper cache object.
|
|
379
|
+
*/
|
|
380
|
+
$getGatekeeperCache(): Promise<{
|
|
381
|
+
[k: string]: true;
|
|
382
|
+
}>;
|
|
139
383
|
$clearCache(): void;
|
|
384
|
+
/**
|
|
385
|
+
* Send the user email verification/change/cancellation links.
|
|
386
|
+
*
|
|
387
|
+
* @returns True on success, false on failure.
|
|
388
|
+
*/
|
|
140
389
|
$sendEmailVerification(): Promise<boolean>;
|
|
141
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Add the user to a (secondary) group.
|
|
392
|
+
*
|
|
393
|
+
* @param group The group.
|
|
394
|
+
* @returns True if the user is already in the group. The resulting array of groups if the user was not.
|
|
395
|
+
*/
|
|
396
|
+
$addGroup(group: GroupClass & GroupData): Promise<true | (GroupClass & GroupData)[]>;
|
|
397
|
+
/**
|
|
398
|
+
* Check the given password against the user's.
|
|
399
|
+
*
|
|
400
|
+
* @param password The password in question.
|
|
401
|
+
* @returns True if the passwords match, otherwise false.
|
|
402
|
+
*/
|
|
142
403
|
$checkPassword(password: string): boolean;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Remove the user from a (secondary) group.
|
|
406
|
+
*
|
|
407
|
+
* @param group The group.
|
|
408
|
+
* @returns True if the user wasn't in the group. The resulting array of groups if the user was.
|
|
409
|
+
*/
|
|
410
|
+
$delGroup(group: GroupClass & GroupData): Promise<true | (GroupClass & GroupData)[]>;
|
|
411
|
+
/**
|
|
412
|
+
* Check whether the user is in a (primary or secondary) group.
|
|
413
|
+
*
|
|
414
|
+
* @param group The group, or the group's GUID.
|
|
415
|
+
* @returns True or false.
|
|
416
|
+
*/
|
|
417
|
+
$inGroup(group: (GroupClass & GroupData) | string): Promise<boolean>;
|
|
418
|
+
/**
|
|
419
|
+
* Check whether the user is a descendant of a group.
|
|
420
|
+
*
|
|
421
|
+
* @param group The group, or the group's GUID.
|
|
422
|
+
* @returns True or false.
|
|
423
|
+
*/
|
|
424
|
+
$isDescendant(group: (GroupClass & GroupData) | string): Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* A frontend accessible method to change the user's password.
|
|
427
|
+
*
|
|
428
|
+
* @param data The input data from the client.
|
|
429
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
430
|
+
*/
|
|
146
431
|
$changePassword(data: {
|
|
147
432
|
newPassword: string;
|
|
148
433
|
currentPassword: string;
|
|
434
|
+
revokeCurrentTokens?: boolean;
|
|
149
435
|
}): Promise<{
|
|
150
436
|
result: boolean;
|
|
151
437
|
message: string;
|
|
152
438
|
}>;
|
|
439
|
+
/**
|
|
440
|
+
* Change the user's password.
|
|
441
|
+
*
|
|
442
|
+
* @param password The new password.
|
|
443
|
+
* @returns The resulting password or hash which is stored in the entity.
|
|
444
|
+
*/
|
|
153
445
|
$password(password: string): string;
|
|
446
|
+
/**
|
|
447
|
+
* A frontend accessible method to revoke all currently issued tokens.
|
|
448
|
+
*
|
|
449
|
+
* @param data The input data from the client.
|
|
450
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
451
|
+
*/
|
|
452
|
+
$revokeCurrentTokens(data: {
|
|
453
|
+
password: string;
|
|
454
|
+
}): Promise<{
|
|
455
|
+
result: boolean;
|
|
456
|
+
message: string;
|
|
457
|
+
}>;
|
|
458
|
+
$hasTOTPSecret(): boolean;
|
|
459
|
+
/**
|
|
460
|
+
* Check the given code against the user's TOTP secret.
|
|
461
|
+
*
|
|
462
|
+
* @param code The code in question.
|
|
463
|
+
* @returns True if the code is valid, otherwise false.
|
|
464
|
+
*/
|
|
465
|
+
$checkTOTPCode(code: string): boolean;
|
|
466
|
+
/**
|
|
467
|
+
* A frontend accessible method to generate a new TOTP secret.
|
|
468
|
+
*
|
|
469
|
+
* @returns An object with 'uri', 'qrcode', and 'secret'.
|
|
470
|
+
*/
|
|
471
|
+
$getNewTOTPSecret(): Promise<{
|
|
472
|
+
uri: string;
|
|
473
|
+
qrcode: string;
|
|
474
|
+
secret: string;
|
|
475
|
+
}>;
|
|
476
|
+
/**
|
|
477
|
+
* A frontend accessible method to save a TOTP secret into the user's account.
|
|
478
|
+
*
|
|
479
|
+
* @param data The input data from the client.
|
|
480
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
481
|
+
*/
|
|
482
|
+
$saveTOTPSecret(data: {
|
|
483
|
+
password: string;
|
|
484
|
+
secret: string;
|
|
485
|
+
code: string;
|
|
486
|
+
}): Promise<{
|
|
487
|
+
result: boolean;
|
|
488
|
+
message: string;
|
|
489
|
+
}>;
|
|
490
|
+
/**
|
|
491
|
+
* A frontend accessible method to remove the TOTP secret from the user's
|
|
492
|
+
* account.
|
|
493
|
+
*
|
|
494
|
+
* @param data The input data from the client.
|
|
495
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
496
|
+
*/
|
|
497
|
+
$removeTOTPSecret(data?: {
|
|
498
|
+
password: string;
|
|
499
|
+
code: string;
|
|
500
|
+
}): Promise<{
|
|
501
|
+
result: boolean;
|
|
502
|
+
message: string;
|
|
503
|
+
}>;
|
|
504
|
+
/**
|
|
505
|
+
* Check that a username is valid.
|
|
506
|
+
*
|
|
507
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
508
|
+
*/
|
|
154
509
|
$checkUsername(): Promise<{
|
|
155
510
|
result: boolean;
|
|
156
511
|
message: string;
|
|
157
512
|
}>;
|
|
513
|
+
/**
|
|
514
|
+
* Check that an email is unique.
|
|
515
|
+
*
|
|
516
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
517
|
+
*/
|
|
158
518
|
$checkEmail(): Promise<{
|
|
159
519
|
result: boolean;
|
|
160
520
|
message: string;
|
|
161
521
|
}>;
|
|
522
|
+
/**
|
|
523
|
+
* Check that a phone number is unique.
|
|
524
|
+
*
|
|
525
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
526
|
+
*/
|
|
162
527
|
$checkPhone(): Promise<{
|
|
163
528
|
result: boolean;
|
|
164
529
|
message: string;
|
|
@@ -173,10 +538,15 @@ export default class User extends AbleObject<UserData> {
|
|
|
173
538
|
loggedin: boolean;
|
|
174
539
|
message: string;
|
|
175
540
|
}>;
|
|
176
|
-
$save(): Promise<
|
|
177
|
-
|
|
541
|
+
$save(): Promise<void>;
|
|
542
|
+
/**
|
|
543
|
+
* This should *never* be accessible on the client.
|
|
544
|
+
*/
|
|
545
|
+
$saveSkipAC(): Promise<void>;
|
|
178
546
|
$tilmeldSaveSkipAC(): boolean;
|
|
179
|
-
$delete(): Promise<
|
|
180
|
-
|
|
181
|
-
|
|
547
|
+
$delete(): Promise<void>;
|
|
548
|
+
$deleteSkipAC(): Promise<void>;
|
|
549
|
+
$tilmeldDeleteSkipAC(): boolean;
|
|
550
|
+
static on<T extends EventType>(event: T, callback: T extends 'checkUsername' ? TilmeldCheckUsernameCallback : T extends 'beforeRegister' ? TilmeldBeforeRegisterCallback : T extends 'afterRegister' ? TilmeldAfterRegisterCallback : T extends 'beforeSave' ? TilmeldBeforeSaveCallback : T extends 'afterSave' ? TilmeldAfterSaveCallback : T extends 'beforeLogin' ? TilmeldBeforeLoginCallback : T extends 'afterLogin' ? TilmeldAfterLoginCallback : T extends 'beforeLogout' ? TilmeldBeforeLogoutCallback : T extends 'afterLogout' ? TilmeldAfterLogoutCallback : T extends 'beforeDelete' ? TilmeldBeforeDeleteCallback : T extends 'afterDelete' ? TilmeldAfterDeleteCallback : never): () => boolean;
|
|
551
|
+
static off<T extends EventType>(event: T, callback: T extends 'checkUsername' ? TilmeldCheckUsernameCallback : T extends 'beforeRegister' ? TilmeldBeforeRegisterCallback : T extends 'afterRegister' ? TilmeldAfterRegisterCallback : T extends 'beforeSave' ? TilmeldBeforeSaveCallback : T extends 'afterSave' ? TilmeldAfterSaveCallback : T extends 'beforeLogin' ? TilmeldBeforeLoginCallback : T extends 'afterLogin' ? TilmeldAfterLoginCallback : T extends 'beforeLogout' ? TilmeldBeforeLogoutCallback : T extends 'afterLogout' ? TilmeldAfterLogoutCallback : T extends 'beforeDelete' ? TilmeldBeforeDeleteCallback : T extends 'afterDelete' ? TilmeldAfterDeleteCallback : never): boolean;
|
|
182
552
|
}
|