diff options
Diffstat (limited to 'shared/server-commands/users')
-rw-r--r-- | shared/server-commands/users/index.ts | 1 | ||||
-rw-r--r-- | shared/server-commands/users/registrations-command.ts | 151 | ||||
-rw-r--r-- | shared/server-commands/users/users-command.ts | 29 |
3 files changed, 152 insertions, 29 deletions
diff --git a/shared/server-commands/users/index.ts b/shared/server-commands/users/index.ts index 1afc02dc1..404756539 100644 --- a/shared/server-commands/users/index.ts +++ b/shared/server-commands/users/index.ts | |||
@@ -4,6 +4,7 @@ export * from './blocklist-command' | |||
4 | export * from './login' | 4 | export * from './login' |
5 | export * from './login-command' | 5 | export * from './login-command' |
6 | export * from './notifications-command' | 6 | export * from './notifications-command' |
7 | export * from './registrations-command' | ||
7 | export * from './subscriptions-command' | 8 | export * from './subscriptions-command' |
8 | export * from './two-factor-command' | 9 | export * from './two-factor-command' |
9 | export * from './users-command' | 10 | export * from './users-command' |
diff --git a/shared/server-commands/users/registrations-command.ts b/shared/server-commands/users/registrations-command.ts new file mode 100644 index 000000000..f57f54b34 --- /dev/null +++ b/shared/server-commands/users/registrations-command.ts | |||
@@ -0,0 +1,151 @@ | |||
1 | import { pick } from '@shared/core-utils' | ||
2 | import { HttpStatusCode, ResultList, UserRegistration, UserRegistrationRequest, UserRegistrationUpdateState } from '@shared/models' | ||
3 | import { unwrapBody } from '../requests' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class RegistrationsCommand extends AbstractCommand { | ||
7 | |||
8 | register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) { | ||
9 | const { password = 'password', email = options.username + '@example.com' } = options | ||
10 | const path = '/api/v1/users/register' | ||
11 | |||
12 | return this.postBodyRequest({ | ||
13 | ...options, | ||
14 | |||
15 | path, | ||
16 | fields: { | ||
17 | ...pick(options, [ 'username', 'displayName', 'channel' ]), | ||
18 | |||
19 | password, | ||
20 | |||
21 | }, | ||
22 | implicitToken: false, | ||
23 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | requestRegistration ( | ||
28 | options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'> | ||
29 | ) { | ||
30 | const { password = 'password', email = options.username + '@example.com' } = options | ||
31 | const path = '/api/v1/users/registrations/request' | ||
32 | |||
33 | return unwrapBody<UserRegistration>(this.postBodyRequest({ | ||
34 | ...options, | ||
35 | |||
36 | path, | ||
37 | fields: { | ||
38 | ...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]), | ||
39 | |||
40 | password, | ||
41 | |||
42 | }, | ||
43 | implicitToken: false, | ||
44 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
45 | })) | ||
46 | } | ||
47 | |||
48 | // --------------------------------------------------------------------------- | ||
49 | |||
50 | accept (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
51 | const { id } = options | ||
52 | const path = '/api/v1/users/registrations/' + id + '/accept' | ||
53 | |||
54 | return this.postBodyRequest({ | ||
55 | ...options, | ||
56 | |||
57 | path, | ||
58 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
59 | implicitToken: true, | ||
60 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | reject (options: OverrideCommandOptions & { id: number } & UserRegistrationUpdateState) { | ||
65 | const { id } = options | ||
66 | const path = '/api/v1/users/registrations/' + id + '/reject' | ||
67 | |||
68 | return this.postBodyRequest({ | ||
69 | ...options, | ||
70 | |||
71 | path, | ||
72 | fields: pick(options, [ 'moderationResponse', 'preventEmailDelivery' ]), | ||
73 | implicitToken: true, | ||
74 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
75 | }) | ||
76 | } | ||
77 | |||
78 | // --------------------------------------------------------------------------- | ||
79 | |||
80 | delete (options: OverrideCommandOptions & { | ||
81 | id: number | ||
82 | }) { | ||
83 | const { id } = options | ||
84 | const path = '/api/v1/users/registrations/' + id | ||
85 | |||
86 | return this.deleteRequest({ | ||
87 | ...options, | ||
88 | |||
89 | path, | ||
90 | implicitToken: true, | ||
91 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
92 | }) | ||
93 | } | ||
94 | |||
95 | // --------------------------------------------------------------------------- | ||
96 | |||
97 | list (options: OverrideCommandOptions & { | ||
98 | start?: number | ||
99 | count?: number | ||
100 | sort?: string | ||
101 | search?: string | ||
102 | } = {}) { | ||
103 | const path = '/api/v1/users/registrations' | ||
104 | |||
105 | return this.getRequestBody<ResultList<UserRegistration>>({ | ||
106 | ...options, | ||
107 | |||
108 | path, | ||
109 | query: pick(options, [ 'start', 'count', 'sort', 'search' ]), | ||
110 | implicitToken: true, | ||
111 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
112 | }) | ||
113 | } | ||
114 | |||
115 | // --------------------------------------------------------------------------- | ||
116 | |||
117 | askSendVerifyEmail (options: OverrideCommandOptions & { | ||
118 | email: string | ||
119 | }) { | ||
120 | const { email } = options | ||
121 | const path = '/api/v1/users/registrations/ask-send-verify-email' | ||
122 | |||
123 | return this.postBodyRequest({ | ||
124 | ...options, | ||
125 | |||
126 | path, | ||
127 | fields: { email }, | ||
128 | implicitToken: false, | ||
129 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | verifyEmail (options: OverrideCommandOptions & { | ||
134 | registrationId: number | ||
135 | verificationString: string | ||
136 | }) { | ||
137 | const { registrationId, verificationString } = options | ||
138 | const path = '/api/v1/users/registrations/' + registrationId + '/verify-email' | ||
139 | |||
140 | return this.postBodyRequest({ | ||
141 | ...options, | ||
142 | |||
143 | path, | ||
144 | fields: { | ||
145 | verificationString | ||
146 | }, | ||
147 | implicitToken: false, | ||
148 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
149 | }) | ||
150 | } | ||
151 | } | ||
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts index 811b9685b..8a42fafc8 100644 --- a/shared/server-commands/users/users-command.ts +++ b/shared/server-commands/users/users-command.ts | |||
@@ -214,35 +214,6 @@ export class UsersCommand extends AbstractCommand { | |||
214 | return this.server.login.getAccessToken({ username, password }) | 214 | return this.server.login.getAccessToken({ username, password }) |
215 | } | 215 | } |
216 | 216 | ||
217 | register (options: OverrideCommandOptions & { | ||
218 | username: string | ||
219 | password?: string | ||
220 | displayName?: string | ||
221 | email?: string | ||
222 | channel?: { | ||
223 | name: string | ||
224 | displayName: string | ||
225 | } | ||
226 | }) { | ||
227 | const { username, password = 'password', displayName, channel, email = username + '@example.com' } = options | ||
228 | const path = '/api/v1/users/register' | ||
229 | |||
230 | return this.postBodyRequest({ | ||
231 | ...options, | ||
232 | |||
233 | path, | ||
234 | fields: { | ||
235 | username, | ||
236 | password, | ||
237 | email, | ||
238 | displayName, | ||
239 | channel | ||
240 | }, | ||
241 | implicitToken: false, | ||
242 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
243 | }) | ||
244 | } | ||
245 | |||
246 | // --------------------------------------------------------------------------- | 217 | // --------------------------------------------------------------------------- |
247 | 218 | ||
248 | getMyInfo (options: OverrideCommandOptions = {}) { | 219 | getMyInfo (options: OverrideCommandOptions = {}) { |