PeerTube/client/src/app/shared/users/user.service.ts

37 lines
1.0 KiB
TypeScript
Raw Normal View History

2016-08-05 18:04:08 +02:00
import { Injectable } from '@angular/core';
2017-01-13 12:16:00 +01:00
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
2016-08-05 18:04:08 +02:00
import { AuthService } from '../../core';
import { AuthHttp } from '../auth';
import { RestExtractor } from '../rest';
2016-08-05 18:04:08 +02:00
@Injectable()
export class UserService {
2017-03-08 21:35:43 +01:00
static BASE_USERS_URL = '/api/v1/users/';
2016-08-05 18:04:08 +02:00
constructor(
private authHttp: AuthHttp,
private authService: AuthService,
private restExtractor: RestExtractor
) {}
2016-08-05 18:04:08 +02:00
checkTokenValidity() {
const url = UserService.BASE_USERS_URL + 'me';
// AuthHttp will redirect us to the login page if the oken is not valid anymore
this.authHttp.get(url).subscribe(() => { ; });
}
2016-08-05 18:04:08 +02:00
changePassword(newPassword: string) {
const url = UserService.BASE_USERS_URL + this.authService.getUser().id;
2016-08-05 18:04:08 +02:00
const body = {
password: newPassword
};
return this.authHttp.put(url, body)
.map(this.restExtractor.extractDataBool)
.catch((res) => this.restExtractor.handleError(res));
2016-08-05 18:04:08 +02:00
}
}