@nymphjs/tilmeld 1.0.0-beta.9 → 1.0.0-beta.91
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 +414 -0
- package/README.md +15 -2
- 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 +181 -15
- package/dist/Group.js +551 -192
- package/dist/Group.js.map +1 -1
- package/dist/Group.test.js +83 -13
- package/dist/Group.test.js.map +1 -1
- package/dist/Tilmeld.d.ts +241 -12
- package/dist/Tilmeld.js +636 -254
- package/dist/Tilmeld.js.map +1 -1
- package/dist/Tilmeld.types.d.ts +2 -2
- package/dist/Tilmeld.types.js +1 -2
- package/dist/User.d.ts +395 -22
- package/dist/User.js +1316 -365
- package/dist/User.js.map +1 -1
- package/dist/User.test.js +132 -13
- package/dist/User.test.js.map +1 -1
- package/dist/conf/d.d.ts +287 -7
- package/dist/conf/d.js +1 -2
- package/dist/conf/defaults.d.ts +1 -1
- package/dist/conf/defaults.js +188 -141
- package/dist/conf/defaults.js.map +1 -1
- package/dist/conf/index.d.ts +2 -2
- package/dist/conf/index.js +2 -8
- package/dist/conf/index.js.map +1 -1
- 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 +11 -10
- package/dist/index.js +16 -35
- package/dist/index.js.map +1 -1
- package/dist/tilmeldJoiProps.js +13 -18
- package/dist/tilmeldJoiProps.js.map +1 -1
- package/jest.config.js +11 -2
- package/package.json +34 -31
- package/src/AbleObject.ts +2 -2
- package/src/Group.test.ts +104 -6
- package/src/Group.ts +661 -226
- package/src/Tilmeld.ts +420 -254
- package/src/Tilmeld.types.ts +2 -2
- package/src/User.test.ts +163 -6
- package/src/User.ts +1557 -454
- package/src/conf/d.ts +63 -17
- package/src/conf/defaults.ts +162 -109
- package/src/conf/index.ts +2 -2
- 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 +12 -10
- package/src/tilmeldJoiProps.ts +11 -11
- package/src/type/locutus.d.ts +3 -0
- package/tsconfig.json +5 -3
- package/typedoc.json +4 -0
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 { Nymph, EntityData, EntityJson, EntityPatch, 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,154 @@ 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@gmail.com>
|
|
190
|
+
* @copyright SciActive Inc
|
|
191
|
+
* @see http://nymph.io/
|
|
192
|
+
*/
|
|
52
193
|
export default class User extends AbleObject<UserData> {
|
|
53
|
-
|
|
194
|
+
/**
|
|
195
|
+
* The instance of Tilmeld to use for queries.
|
|
196
|
+
*/
|
|
54
197
|
static ETYPE: string;
|
|
55
198
|
static class: string;
|
|
199
|
+
private static checkUsernameCallbacks;
|
|
56
200
|
private static beforeRegisterCallbacks;
|
|
57
201
|
private static afterRegisterCallbacks;
|
|
202
|
+
private static beforeSaveCallbacks;
|
|
203
|
+
private static afterSaveCallbacks;
|
|
58
204
|
private static beforeLoginCallbacks;
|
|
59
205
|
private static afterLoginCallbacks;
|
|
60
206
|
private static beforeLogoutCallbacks;
|
|
61
207
|
private static afterLogoutCallbacks;
|
|
208
|
+
private static beforeDeleteCallbacks;
|
|
209
|
+
private static afterDeleteCallbacks;
|
|
62
210
|
private static DEFAULT_CLIENT_ENABLED_METHODS;
|
|
63
211
|
private static DEFAULT_PRIVATE_DATA;
|
|
64
212
|
private static DEFAULT_ALLOWLIST_DATA;
|
|
@@ -68,16 +216,46 @@ export default class User extends AbleObject<UserData> {
|
|
|
68
216
|
static searchRestrictedData: string[];
|
|
69
217
|
protected $allowlistData?: string[] | undefined;
|
|
70
218
|
protected $allowlistTags?: string[];
|
|
219
|
+
/**
|
|
220
|
+
* Gatekeeper ability cache.
|
|
221
|
+
*
|
|
222
|
+
* Gatekeeper will cache the user's abilities that it calculates, so it can
|
|
223
|
+
* check faster if that user has been checked before.
|
|
224
|
+
*/
|
|
71
225
|
private $gatekeeperCache?;
|
|
226
|
+
/**
|
|
227
|
+
* This should only be used by the backend.
|
|
228
|
+
*/
|
|
72
229
|
private $skipAcWhenSaving;
|
|
230
|
+
/**
|
|
231
|
+
* This should only be used by the backend.
|
|
232
|
+
*/
|
|
233
|
+
private $skipAcWhenDeleting;
|
|
234
|
+
/**
|
|
235
|
+
* The user's group descendants.
|
|
236
|
+
*/
|
|
73
237
|
private $descendantGroups?;
|
|
238
|
+
/**
|
|
239
|
+
* Used to save the current email address to send verification if it changes
|
|
240
|
+
* from the frontend.
|
|
241
|
+
*
|
|
242
|
+
* If you are changing a user's email address and want to bypass email
|
|
243
|
+
* verification, don't set this.
|
|
244
|
+
*/
|
|
74
245
|
$originalEmail?: string;
|
|
75
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Used to save the current username for domain admin permissions.
|
|
248
|
+
*/
|
|
249
|
+
$originalUsername?: string;
|
|
76
250
|
static factoryUsername(username?: string): Promise<User & UserData>;
|
|
77
|
-
static factorySync(guid?: string): User & UserData;
|
|
78
|
-
constructor(guid?: string);
|
|
79
251
|
static current(returnObjectIfNotExist: true): User & UserData;
|
|
80
252
|
static current(returnObjectIfNotExist?: false): (User & UserData) | null;
|
|
253
|
+
/**
|
|
254
|
+
* Send an account recovery link.
|
|
255
|
+
*
|
|
256
|
+
* @param data The input data from the client.
|
|
257
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
258
|
+
*/
|
|
81
259
|
static sendRecovery(data: {
|
|
82
260
|
recoveryType: 'username' | 'password';
|
|
83
261
|
account: string;
|
|
@@ -85,6 +263,12 @@ export default class User extends AbleObject<UserData> {
|
|
|
85
263
|
result: boolean;
|
|
86
264
|
message: string;
|
|
87
265
|
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Recover account details.
|
|
268
|
+
*
|
|
269
|
+
* @param data The input data from the client.
|
|
270
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
271
|
+
*/
|
|
88
272
|
static recover(data: {
|
|
89
273
|
username: string;
|
|
90
274
|
secret: string;
|
|
@@ -97,6 +281,7 @@ export default class User extends AbleObject<UserData> {
|
|
|
97
281
|
regFields: string[];
|
|
98
282
|
userFields: string[];
|
|
99
283
|
emailUsernames: boolean;
|
|
284
|
+
domainSupport: boolean;
|
|
100
285
|
allowRegistration: boolean;
|
|
101
286
|
allowUsernameChange: boolean;
|
|
102
287
|
pwRecovery: boolean;
|
|
@@ -106,59 +291,242 @@ export default class User extends AbleObject<UserData> {
|
|
|
106
291
|
static loginUser(data: {
|
|
107
292
|
username: string;
|
|
108
293
|
password: string;
|
|
294
|
+
code?: string;
|
|
109
295
|
additionalData?: {
|
|
110
296
|
[k: string]: any;
|
|
111
297
|
};
|
|
112
298
|
}): Promise<{
|
|
113
299
|
result: boolean;
|
|
114
300
|
message: string;
|
|
115
|
-
user?:
|
|
301
|
+
user?: User & UserData;
|
|
116
302
|
}>;
|
|
303
|
+
/**
|
|
304
|
+
* Get the users in a domain. This is only accessible to the domain's admins.
|
|
305
|
+
*/
|
|
306
|
+
static getDomainUsers(domain: string, options?: {
|
|
307
|
+
limit?: number;
|
|
308
|
+
offset?: number;
|
|
309
|
+
sort?: string;
|
|
310
|
+
reverse?: boolean;
|
|
311
|
+
}): Promise<(User & UserData)[]>;
|
|
312
|
+
constructor();
|
|
313
|
+
$setNymph(nymph: Nymph): void;
|
|
314
|
+
$getUniques(): Promise<string[]>;
|
|
117
315
|
$login(data: {
|
|
118
316
|
username: string;
|
|
119
317
|
password: string;
|
|
318
|
+
code?: string;
|
|
120
319
|
additionalData?: {
|
|
121
320
|
[k: string]: any;
|
|
122
321
|
};
|
|
123
322
|
}): Promise<{
|
|
323
|
+
result: boolean;
|
|
324
|
+
needTOTP: boolean;
|
|
325
|
+
message: string;
|
|
326
|
+
} | {
|
|
124
327
|
result: boolean;
|
|
125
328
|
message: any;
|
|
329
|
+
needTOTP?: undefined;
|
|
126
330
|
}>;
|
|
331
|
+
$switchUser(data?: {
|
|
332
|
+
additionalData?: {
|
|
333
|
+
[k: string]: any;
|
|
334
|
+
};
|
|
335
|
+
}): Promise<{
|
|
336
|
+
result: boolean;
|
|
337
|
+
message: any;
|
|
338
|
+
}>;
|
|
339
|
+
/**
|
|
340
|
+
* Log a user out of the system.
|
|
341
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
342
|
+
*/
|
|
127
343
|
$logout(): Promise<{
|
|
128
344
|
result: boolean;
|
|
129
345
|
message: any;
|
|
130
346
|
}>;
|
|
131
347
|
$getAvatar(): string;
|
|
132
|
-
$
|
|
133
|
-
$
|
|
348
|
+
$getGid(): string | null;
|
|
349
|
+
$getGids(): string[] | null;
|
|
350
|
+
/**
|
|
351
|
+
* Get the user's group descendants.
|
|
352
|
+
*/
|
|
353
|
+
$getDescendantGroups(): Promise<(GroupClass & GroupData)[]>;
|
|
134
354
|
$jsonAcceptData(input: EntityJson, allowConflict?: boolean): void;
|
|
135
355
|
$jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void;
|
|
136
|
-
$
|
|
356
|
+
private $checkIncomingAbilities;
|
|
357
|
+
$putData(data: EntityData, sdata?: SerializedEntityData, source?: 'server'): void;
|
|
358
|
+
/**
|
|
359
|
+
* Update the data protection arrays for a user.
|
|
360
|
+
*
|
|
361
|
+
* @param givenUser User to update protection for. If undefined, will use the currently logged in user.
|
|
362
|
+
*/
|
|
137
363
|
$updateDataProtection(givenUser?: User & UserData): void;
|
|
138
|
-
$
|
|
364
|
+
$updateGroupDataProtection(): void;
|
|
365
|
+
/**
|
|
366
|
+
* Check to see if a user has an ability.
|
|
367
|
+
*
|
|
368
|
+
* This function will check both user and group abilities, if the user is
|
|
369
|
+
* marked to inherit the abilities of its group.
|
|
370
|
+
*
|
|
371
|
+
* If `ability` is undefined, it will check to see if the user is currently
|
|
372
|
+
* logged in.
|
|
373
|
+
*
|
|
374
|
+
* If the user has the "system/admin" ability, this function will return true.
|
|
375
|
+
*
|
|
376
|
+
* @param ability The ability.
|
|
377
|
+
* @returns True or false.
|
|
378
|
+
*/
|
|
379
|
+
$gatekeeper(ability?: string): Promise<boolean>;
|
|
380
|
+
/**
|
|
381
|
+
* Build a gatekeeper cache object.
|
|
382
|
+
*/
|
|
383
|
+
$getGatekeeperCache(): Promise<{
|
|
384
|
+
[k: string]: true;
|
|
385
|
+
}>;
|
|
139
386
|
$clearCache(): void;
|
|
387
|
+
/**
|
|
388
|
+
* Send the user email verification/change/cancellation links.
|
|
389
|
+
*
|
|
390
|
+
* @returns True on success, false on failure.
|
|
391
|
+
*/
|
|
140
392
|
$sendEmailVerification(): Promise<boolean>;
|
|
141
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Add the user to a (secondary) group.
|
|
395
|
+
*
|
|
396
|
+
* @param group The group.
|
|
397
|
+
* @returns True if the user is already in the group. The resulting array of groups if the user was not.
|
|
398
|
+
*/
|
|
399
|
+
$addGroup(group: GroupClass & GroupData): Promise<true | (GroupClass & GroupData)[]>;
|
|
400
|
+
/**
|
|
401
|
+
* Check the given password against the user's.
|
|
402
|
+
*
|
|
403
|
+
* @param password The password in question.
|
|
404
|
+
* @returns True if the passwords match, otherwise false.
|
|
405
|
+
*/
|
|
142
406
|
$checkPassword(password: string): boolean;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Remove the user from a (secondary) group.
|
|
409
|
+
*
|
|
410
|
+
* @param group The group.
|
|
411
|
+
* @returns True if the user wasn't in the group. The resulting array of groups if the user was.
|
|
412
|
+
*/
|
|
413
|
+
$delGroup(group: GroupClass & GroupData): Promise<true | (GroupClass & GroupData)[]>;
|
|
414
|
+
/**
|
|
415
|
+
* Check whether the user is in a (primary or secondary) group.
|
|
416
|
+
*
|
|
417
|
+
* @param group The group, or the group's GUID.
|
|
418
|
+
* @returns True or false.
|
|
419
|
+
*/
|
|
420
|
+
$inGroup(group: (GroupClass & GroupData) | string): Promise<boolean>;
|
|
421
|
+
/**
|
|
422
|
+
* Check whether the user is a descendant of a group.
|
|
423
|
+
*
|
|
424
|
+
* @param group The group, or the group's GUID.
|
|
425
|
+
* @returns True or false.
|
|
426
|
+
*/
|
|
427
|
+
$isDescendant(group: (GroupClass & GroupData) | string): Promise<boolean>;
|
|
428
|
+
/**
|
|
429
|
+
* A frontend accessible method to change the user's password.
|
|
430
|
+
*
|
|
431
|
+
* @param data The input data from the client.
|
|
432
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
433
|
+
*/
|
|
146
434
|
$changePassword(data: {
|
|
147
435
|
newPassword: string;
|
|
148
436
|
currentPassword: string;
|
|
437
|
+
revokeCurrentTokens?: boolean;
|
|
149
438
|
}): Promise<{
|
|
150
439
|
result: boolean;
|
|
151
440
|
message: string;
|
|
152
441
|
}>;
|
|
442
|
+
/**
|
|
443
|
+
* Change the user's password.
|
|
444
|
+
*
|
|
445
|
+
* @param password The new password.
|
|
446
|
+
* @returns The resulting password or hash which is stored in the entity.
|
|
447
|
+
*/
|
|
153
448
|
$password(password: string): string;
|
|
449
|
+
/**
|
|
450
|
+
* A frontend accessible method to revoke all currently issued tokens.
|
|
451
|
+
*
|
|
452
|
+
* @param data The input data from the client.
|
|
453
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
454
|
+
*/
|
|
455
|
+
$revokeCurrentTokens(data: {
|
|
456
|
+
password: string;
|
|
457
|
+
}): Promise<{
|
|
458
|
+
result: boolean;
|
|
459
|
+
message: string;
|
|
460
|
+
}>;
|
|
461
|
+
$hasTOTPSecret(): Promise<boolean>;
|
|
462
|
+
/**
|
|
463
|
+
* Check the given code against the user's TOTP secret.
|
|
464
|
+
*
|
|
465
|
+
* @param code The code in question.
|
|
466
|
+
* @returns True if the code is valid, otherwise false.
|
|
467
|
+
*/
|
|
468
|
+
$checkTOTPCode(code: string): boolean;
|
|
469
|
+
/**
|
|
470
|
+
* A frontend accessible method to generate a new TOTP secret.
|
|
471
|
+
*
|
|
472
|
+
* @returns An object with 'uri', 'qrcode', and 'secret'.
|
|
473
|
+
*/
|
|
474
|
+
$getNewTOTPSecret(): Promise<{
|
|
475
|
+
uri: string;
|
|
476
|
+
qrcode: string;
|
|
477
|
+
secret: string;
|
|
478
|
+
}>;
|
|
479
|
+
/**
|
|
480
|
+
* A frontend accessible method to save a TOTP secret into the user's account.
|
|
481
|
+
*
|
|
482
|
+
* @param data The input data from the client.
|
|
483
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
484
|
+
*/
|
|
485
|
+
$saveTOTPSecret(data: {
|
|
486
|
+
password: string;
|
|
487
|
+
secret: string;
|
|
488
|
+
code: string;
|
|
489
|
+
}): Promise<{
|
|
490
|
+
result: boolean;
|
|
491
|
+
message: string;
|
|
492
|
+
}>;
|
|
493
|
+
/**
|
|
494
|
+
* A frontend accessible method to remove the TOTP secret from the user's
|
|
495
|
+
* account.
|
|
496
|
+
*
|
|
497
|
+
* @param data The input data from the client.
|
|
498
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
499
|
+
*/
|
|
500
|
+
$removeTOTPSecret(data?: {
|
|
501
|
+
password: string;
|
|
502
|
+
code: string;
|
|
503
|
+
}): Promise<{
|
|
504
|
+
result: boolean;
|
|
505
|
+
message: string;
|
|
506
|
+
}>;
|
|
507
|
+
/**
|
|
508
|
+
* Check that a username is valid.
|
|
509
|
+
*
|
|
510
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
511
|
+
*/
|
|
154
512
|
$checkUsername(): Promise<{
|
|
155
513
|
result: boolean;
|
|
156
514
|
message: string;
|
|
157
515
|
}>;
|
|
516
|
+
/**
|
|
517
|
+
* Check that an email is unique.
|
|
518
|
+
*
|
|
519
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
520
|
+
*/
|
|
158
521
|
$checkEmail(): Promise<{
|
|
159
522
|
result: boolean;
|
|
160
523
|
message: string;
|
|
161
524
|
}>;
|
|
525
|
+
/**
|
|
526
|
+
* Check that a phone number is unique.
|
|
527
|
+
*
|
|
528
|
+
* @returns An object with a boolean 'result' entry and a 'message' entry.
|
|
529
|
+
*/
|
|
162
530
|
$checkPhone(): Promise<{
|
|
163
531
|
result: boolean;
|
|
164
532
|
message: string;
|
|
@@ -174,9 +542,14 @@ export default class User extends AbleObject<UserData> {
|
|
|
174
542
|
message: string;
|
|
175
543
|
}>;
|
|
176
544
|
$save(): Promise<boolean>;
|
|
545
|
+
/**
|
|
546
|
+
* This should *never* be accessible on the client.
|
|
547
|
+
*/
|
|
177
548
|
$saveSkipAC(): Promise<boolean>;
|
|
178
549
|
$tilmeldSaveSkipAC(): boolean;
|
|
179
550
|
$delete(): Promise<boolean>;
|
|
180
|
-
|
|
181
|
-
|
|
551
|
+
$deleteSkipAC(): Promise<boolean>;
|
|
552
|
+
$tilmeldDeleteSkipAC(): boolean;
|
|
553
|
+
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;
|
|
554
|
+
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
555
|
}
|