]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.component.ts
Client: implement password change
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
CommitLineData
230809ef 1import { Component } from '@angular/core';
bddab65a 2import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
dc8bc31b 3
4a6995be 4import { FriendService } from './friends';
41a2aee3 5import {
41a2aee3 6 AuthService,
a840d396 7 AuthStatus,
0629423c
C
8 SearchComponent,
9 SearchService
4a6995be 10} from './shared';
0629423c 11import { VideoService } from './videos';
dc8bc31b
C
12
13@Component({
14 selector: 'my-app',
4a6995be
C
15 template: require('./app.component.html'),
16 styles: [ require('./app.component.scss') ],
471bc22f 17 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
bd5c83a8 18 providers: [ FriendService, VideoService, SearchService ]
dc8bc31b
C
19})
20
21export class AppComponent {
ccf6ed16 22 choices = [];
4fd8aa32 23 isLoggedIn: boolean;
a99593ed 24
4fd8aa32
C
25 constructor(
26 private authService: AuthService,
27 private friendService: FriendService,
bddab65a 28 private route: ActivatedRoute,
4fd8aa32 29 private router: Router
b1794c53 30 ) {
ccf6ed16 31 this.isLoggedIn = this.authService.isLoggedIn();
b1794c53 32
ccf6ed16 33 this.authService.loginChangedSource.subscribe(
b1794c53
C
34 status => {
35 if (status === AuthStatus.LoggedIn) {
36 this.isLoggedIn = true;
bd5c83a8
C
37 console.log('Logged in.');
38 } else if (status === AuthStatus.LoggedOut) {
39 this.isLoggedIn = false;
40 console.log('Logged out.');
41 } else {
42 console.error('Unknown auth status: ' + status);
b1794c53
C
43 }
44 }
45 );
46 }
98b01bac 47
b1794c53 48 logout() {
bd5c83a8 49 this.authService.logout();
b1794c53
C
50 }
51
dc8bc31b 52 makeFriends() {
ccf6ed16 53 this.friendService.makeFriends().subscribe(
dc8bc31b
C
54 status => {
55 if (status === 409) {
56 alert('Already made friends!');
98b01bac 57 } else {
dc8bc31b
C
58 alert('Made friends!');
59 }
60 },
61 error => alert(error)
44124980 62 );
dc8bc31b
C
63 }
64
65 quitFriends() {
ccf6ed16 66 this.friendService.quitFriends().subscribe(
dc8bc31b 67 status => {
4fd8aa32 68 alert('Quit friends!');
dc8bc31b
C
69 },
70 error => alert(error)
44124980 71 );
dc8bc31b
C
72 }
73}