]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/users/user.service.ts
publish comment on crtl-enter (#290)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.service.ts
1 import { HttpClient } from '@angular/common/http'
2 import { Injectable } from '@angular/core'
3 import 'rxjs/add/operator/catch'
4 import 'rxjs/add/operator/map'
5 import { UserCreate, UserUpdateMe } from '../../../../../shared'
6 import { environment } from '../../../environments/environment'
7 import { RestExtractor } from '../rest'
8
9 @Injectable()
10 export class UserService {
11 static BASE_USERS_URL = environment.apiUrl + '/api/v1/users/'
12
13 constructor (
14 private authHttp: HttpClient,
15 private restExtractor: RestExtractor
16 ) {}
17
18 changePassword (newPassword: string) {
19 const url = UserService.BASE_USERS_URL + 'me'
20 const body: UserUpdateMe = {
21 password: newPassword
22 }
23
24 return this.authHttp.put(url, body)
25 .map(this.restExtractor.extractDataBool)
26 .catch(res => this.restExtractor.handleError(res))
27 }
28
29 updateMyDetails (details: UserUpdateMe) {
30 const url = UserService.BASE_USERS_URL + 'me'
31
32 return this.authHttp.put(url, details)
33 .map(this.restExtractor.extractDataBool)
34 .catch(res => this.restExtractor.handleError(res))
35 }
36
37 changeAvatar (avatarForm: FormData) {
38 const url = UserService.BASE_USERS_URL + 'me/avatar/pick'
39
40 return this.authHttp.post(url, avatarForm)
41 .catch(this.restExtractor.handleError)
42 }
43
44 signup (userCreate: UserCreate) {
45 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
46 .map(this.restExtractor.extractDataBool)
47 .catch(res => this.restExtractor.handleError(res))
48 }
49
50 getMyVideoQuotaUsed () {
51 const url = UserService.BASE_USERS_URL + '/me/video-quota-used'
52
53 return this.authHttp.get(url)
54 .catch(res => this.restExtractor.handleError(res))
55 }
56
57 askResetPassword (email: string) {
58 const url = UserService.BASE_USERS_URL + '/ask-reset-password'
59
60 return this.authHttp.post(url, { email })
61 .map(this.restExtractor.extractDataBool)
62 .catch(res => this.restExtractor.handleError(res))
63 }
64
65 resetPassword (userId: number, verificationString: string, password: string) {
66 const url = `${UserService.BASE_USERS_URL}/${userId}/reset-password`
67 const body = {
68 verificationString,
69 password
70 }
71
72 return this.authHttp.post(url, body)
73 .map(this.restExtractor.extractDataBool)
74 .catch(res => this.restExtractor.handleError(res))
75 }
76 }