diff options
Diffstat (limited to 'src/api/UserApi.ts')
-rw-r--r-- | src/api/UserApi.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/api/UserApi.ts b/src/api/UserApi.ts new file mode 100644 index 000000000..31c8acead --- /dev/null +++ b/src/api/UserApi.ts | |||
@@ -0,0 +1,58 @@ | |||
1 | import { BinaryLike } from 'crypto'; | ||
2 | import { hash } from '../helpers/password-helpers'; | ||
3 | |||
4 | export default class UserApi { | ||
5 | server: any; | ||
6 | |||
7 | local: any; | ||
8 | |||
9 | constructor(server: any, local: any) { | ||
10 | this.server = server; | ||
11 | this.local = local; | ||
12 | } | ||
13 | |||
14 | login(email: string, password: BinaryLike) { | ||
15 | return this.server.login(email, hash(password)); | ||
16 | } | ||
17 | |||
18 | logout() { | ||
19 | return this; | ||
20 | } | ||
21 | |||
22 | signup(data: { password: BinaryLike }) { | ||
23 | Object.assign(data, { | ||
24 | password: hash(data.password), | ||
25 | }); | ||
26 | return this.server.signup(data); | ||
27 | } | ||
28 | |||
29 | password(email: string) { | ||
30 | return this.server.retrievePassword(email); | ||
31 | } | ||
32 | |||
33 | invite(data: any) { | ||
34 | return this.server.inviteUser(data); | ||
35 | } | ||
36 | |||
37 | getInfo() { | ||
38 | return this.server.userInfo(); | ||
39 | } | ||
40 | |||
41 | updateInfo(data: { oldPassword: string; newPassword: string }) { | ||
42 | const userData = data; | ||
43 | if (userData.oldPassword && userData.newPassword) { | ||
44 | userData.oldPassword = hash(userData.oldPassword); | ||
45 | userData.newPassword = hash(userData.newPassword); | ||
46 | } | ||
47 | |||
48 | return this.server.updateUserInfo(userData); | ||
49 | } | ||
50 | |||
51 | getLegacyServices() { | ||
52 | return this.server.getLegacyServices(); | ||
53 | } | ||
54 | |||
55 | delete() { | ||
56 | return this.server.deleteAccount(); | ||
57 | } | ||
58 | } | ||