]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.service.ts
Fix account link in the menu
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.service.ts
CommitLineData
d592e0a9 1import { HttpClient } from '@angular/common/http'
63c4db6d 2import { Injectable } from '@angular/core'
df98563e
C
3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map'
8094a898 5import { UserCreate, UserUpdateMe } from '../../../../../shared'
63c4db6d
C
6import { environment } from '../../../environments/environment'
7import { RestExtractor } from '../rest'
629d8d6f
C
8
9@Injectable()
e2a2d6c8 10export class UserService {
63c4db6d 11 static BASE_USERS_URL = environment.apiUrl + '/api/v1/users/'
629d8d6f 12
df98563e 13 constructor (
d592e0a9 14 private authHttp: HttpClient,
de59c48f
C
15 private restExtractor: RestExtractor
16 ) {}
629d8d6f 17
df98563e 18 changePassword (newPassword: string) {
8094a898
C
19 const url = UserService.BASE_USERS_URL + 'me'
20 const body: UserUpdateMe = {
629d8d6f 21 password: newPassword
df98563e 22 }
629d8d6f 23
de59c48f
C
24 return this.authHttp.put(url, body)
25 .map(this.restExtractor.extractDataBool)
d592e0a9 26 .catch(res => this.restExtractor.handleError(res))
629d8d6f 27 }
af5e743b 28
8094a898
C
29 updateMyDetails (details: UserUpdateMe) {
30 const url = UserService.BASE_USERS_URL + 'me'
af5e743b
C
31
32 return this.authHttp.put(url, details)
33 .map(this.restExtractor.extractDataBool)
d592e0a9 34 .catch(res => this.restExtractor.handleError(res))
af5e743b 35 }
a184c71b 36
c5911fd3
C
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
4771e000 44 signup (userCreate: UserCreate) {
d592e0a9 45 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
a184c71b 46 .map(this.restExtractor.extractDataBool)
d592e0a9 47 .catch(res => this.restExtractor.handleError(res))
a184c71b 48 }
c5911fd3 49
ce5496d6
C
50 getMyVideoQuotaUsed () {
51 const url = UserService.BASE_USERS_URL + '/me/video-quota-used'
c5911fd3
C
52
53 return this.authHttp.get(url)
c5911fd3
C
54 .catch(res => this.restExtractor.handleError(res))
55 }
ecb4e35f
C
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 }
629d8d6f 76}