]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.service.ts
Client: Handle NSFW video
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.service.ts
CommitLineData
629d8d6f 1import { Injectable } from '@angular/core';
c16ce1de
C
2import 'rxjs/add/operator/catch';
3import 'rxjs/add/operator/map';
629d8d6f 4
e2a2d6c8
C
5import { AuthService } from '../../core';
6import { AuthHttp } from '../auth';
7import { RestExtractor } from '../rest';
629d8d6f
C
8
9@Injectable()
e2a2d6c8 10export class UserService {
d38b8281 11 static BASE_USERS_URL = '/api/v1/users/';
629d8d6f 12
de59c48f
C
13 constructor(
14 private authHttp: AuthHttp,
15 private authService: AuthService,
16 private restExtractor: RestExtractor
17 ) {}
629d8d6f 18
e2a2d6c8
C
19 checkTokenValidity() {
20 const url = UserService.BASE_USERS_URL + 'me';
21
22 // AuthHttp will redirect us to the login page if the oken is not valid anymore
23 this.authHttp.get(url).subscribe(() => { ; });
24 }
25
629d8d6f 26 changePassword(newPassword: string) {
e2a2d6c8 27 const url = UserService.BASE_USERS_URL + this.authService.getUser().id;
629d8d6f
C
28 const body = {
29 password: newPassword
30 };
31
de59c48f
C
32 return this.authHttp.put(url, body)
33 .map(this.restExtractor.extractDataBool)
34 .catch((res) => this.restExtractor.handleError(res));
629d8d6f
C
35 }
36}