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