]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.service.ts
Add user update for admins
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.service.ts
CommitLineData
df98563e
C
1import { Injectable } from '@angular/core'
2import { Http } from '@angular/http'
3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map'
629d8d6f 5
df98563e
C
6import { AuthService } from '../../core'
7import { AuthHttp } from '../auth'
8import { RestExtractor } from '../rest'
8094a898 9import { UserCreate, UserUpdateMe } from '../../../../../shared'
629d8d6f
C
10
11@Injectable()
e2a2d6c8 12export class UserService {
df98563e 13 static BASE_USERS_URL = API_URL + '/api/v1/users/'
629d8d6f 14
df98563e 15 constructor (
a184c71b 16 private http: Http,
de59c48f
C
17 private authHttp: AuthHttp,
18 private authService: AuthService,
19 private restExtractor: RestExtractor
20 ) {}
629d8d6f 21
df98563e
C
22 checkTokenValidity () {
23 const url = UserService.BASE_USERS_URL + 'me'
e2a2d6c8 24
8094a898 25 // AuthHttp will redirect us to the login page if the token is not valid anymore
df98563e 26 this.authHttp.get(url).subscribe()
e2a2d6c8
C
27 }
28
df98563e 29 changePassword (newPassword: string) {
8094a898
C
30 const url = UserService.BASE_USERS_URL + 'me'
31 const body: UserUpdateMe = {
629d8d6f 32 password: newPassword
df98563e 33 }
629d8d6f 34
de59c48f
C
35 return this.authHttp.put(url, body)
36 .map(this.restExtractor.extractDataBool)
df98563e 37 .catch((res) => this.restExtractor.handleError(res))
629d8d6f 38 }
af5e743b 39
8094a898
C
40 updateMyDetails (details: UserUpdateMe) {
41 const url = UserService.BASE_USERS_URL + 'me'
af5e743b
C
42
43 return this.authHttp.put(url, details)
44 .map(this.restExtractor.extractDataBool)
df98563e 45 .catch((res) => this.restExtractor.handleError(res))
af5e743b 46 }
a184c71b 47
4771e000
C
48 signup (userCreate: UserCreate) {
49 return this.http.post(UserService.BASE_USERS_URL + 'register', userCreate)
a184c71b 50 .map(this.restExtractor.extractDataBool)
df98563e 51 .catch(this.restExtractor.handleError)
a184c71b 52 }
629d8d6f 53}