aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/users
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-04 11:45:47 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-04 11:45:47 +0100
commite2a2d6c86c7ca39074fdff3b545947d1d58dc008 (patch)
treea3420493460f67472acceae2a5746612a30943f0 /client/src/app/shared/users
parenta7449e74f9105839fa03f0b2e23b435f37a1fc2f (diff)
downloadPeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.tar.gz
PeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.tar.zst
PeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.zip
Client: check token valitidy at startup
Diffstat (limited to 'client/src/app/shared/users')
-rw-r--r--client/src/app/shared/users/index.ts1
-rw-r--r--client/src/app/shared/users/user.service.ts36
2 files changed, 37 insertions, 0 deletions
diff --git a/client/src/app/shared/users/index.ts b/client/src/app/shared/users/index.ts
index 5a670ce8f..ff009e89b 100644
--- a/client/src/app/shared/users/index.ts
+++ b/client/src/app/shared/users/index.ts
@@ -1 +1,2 @@
1export * from './user.model'; 1export * from './user.model';
2export * from './user.service';
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts
new file mode 100644
index 000000000..4cf100f0d
--- /dev/null
+++ b/client/src/app/shared/users/user.service.ts
@@ -0,0 +1,36 @@
1import { Injectable } from '@angular/core';
2import 'rxjs/add/operator/catch';
3import 'rxjs/add/operator/map';
4
5import { AuthService } from '../../core';
6import { AuthHttp } from '../auth';
7import { RestExtractor } from '../rest';
8
9@Injectable()
10export class UserService {
11 private static BASE_USERS_URL = '/api/v1/users/';
12
13 constructor(
14 private authHttp: AuthHttp,
15 private authService: AuthService,
16 private restExtractor: RestExtractor
17 ) {}
18
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
26 changePassword(newPassword: string) {
27 const url = UserService.BASE_USERS_URL + this.authService.getUser().id;
28 const body = {
29 password: newPassword
30 };
31
32 return this.authHttp.put(url, body)
33 .map(this.restExtractor.extractDataBool)
34 .catch((res) => this.restExtractor.handleError(res));
35 }
36}