From b1794c53ac97d77a16c10ed915336f08cff1e5e3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 22 Mar 2016 15:51:54 +0100 Subject: Login in Angular : first draft --- client/angular/app/app.component.ts | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'client/angular/app/app.component.ts') diff --git a/client/angular/app/app.component.ts b/client/angular/app/app.component.ts index cb961a3c8..1648b8870 100644 --- a/client/angular/app/app.component.ts +++ b/client/angular/app/app.component.ts @@ -7,8 +7,16 @@ import { VideosListComponent } from '../videos/components/list/videos-list.compo import { VideosWatchComponent } from '../videos/components/watch/videos-watch.component'; import { VideosService } from '../videos/services/videos.service'; import { FriendsService } from '../friends/services/friends.service'; +import { UserLoginComponent } from '../users/components/login/login.component'; +import { AuthService } from '../users/services/auth.service'; +import { AuthStatus } from '../users/models/authStatus'; @RouteConfig([ + { + path: '/users/login', + name: 'UserLogin', + component: UserLoginComponent + }, { path: '/videos/list', name: 'VideosList', @@ -32,11 +40,30 @@ import { FriendsService } from '../friends/services/friends.service'; templateUrl: 'app/angular/app/app.component.html', styleUrls: [ 'app/angular/app/app.component.css' ], directives: [ ROUTER_DIRECTIVES ], - providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, ElementRef, VideosService, FriendsService ] + providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, + ElementRef, VideosService, FriendsService, + AuthService + ] }) export class AppComponent { - constructor(private _friendsService: FriendsService, private _router: Router) {} + isLoggedIn: boolean; + + constructor(private _friendsService: FriendsService, + private _authService: AuthService, + private _router: Router + ) { + if (localStorage.getItem('access_token')) this.isLoggedIn = true; + else this.isLoggedIn = false; + + this._authService.loginChanged$.subscribe( + status => { + if (status === AuthStatus.LoggedIn) { + this.isLoggedIn = true; + } + } + ); + } doSearch(search: string) { if (search !== '') { @@ -46,6 +73,10 @@ export class AppComponent { } } + logout() { + // this._authService.logout(); + } + makeFriends() { this._friendsService.makeFriends().subscribe( status => { -- cgit v1.2.3