From a93f3bb00583421be15c17842d64d358efecc31a Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Sat, 16 Jul 2016 13:41:28 -0400 Subject: [PATCH] More reorganization and initial login/logout functionality --- src/app/login/login.component.ts | 2 +- src/app/main.ts | 6 +++--- src/app/shared/auth/auth.service.ts | 9 ++++++--- src/app/{app.constants.ts => shared/constants.ts} | 1 + src/app/shared/index.ts | 1 + src/app/shared/notifications/notifications.component.ts | 2 +- src/app/shared/notifications/notifications.service.ts | 1 - src/app/shared/top-nav/top-nav.component.ts | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) rename src/app/{app.constants.ts => shared/constants.ts} (70%) diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 45536b7..b20a72c 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,8 +1,8 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; -import { Constants } from '../app.constants'; import { + Constants, AuthService, ApiResponse, Notification, diff --git a/src/app/main.ts b/src/app/main.ts index 61917d8..49bff6c 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -1,14 +1,14 @@ import { bootstrap } from '@angular/platform-browser-dynamic'; import { HTTP_PROVIDERS } from '@angular/http'; import { disableDeprecatedForms, provideForms } from '@angular/forms'; -//import { enableProdMode } from '@angular/core'; +import { enableProdMode } from '@angular/core'; import { AppComponent } from './app.component'; import { APP_ROUTER_PROVIDERS } from './app.routes'; -import { Constants } from './app.constants'; import { NotificationsService } from './shared/index'; +import { Constants } from './shared/constants'; -//enableProdMode(); +// enableProdMode(); bootstrap(AppComponent, [ diff --git a/src/app/shared/auth/auth.service.ts b/src/app/shared/auth/auth.service.ts index 8e0471f..db3327b 100644 --- a/src/app/shared/auth/auth.service.ts +++ b/src/app/shared/auth/auth.service.ts @@ -6,13 +6,16 @@ import 'rxjs/add/observable/of'; import 'rxjs/add/operator/catch'; import { User, ApiResponse } from '../index'; +import { Constants } from '../constants'; @Injectable() export class AuthService { activeUser: User; isLoggedIn: boolean = false; + jwtKey: string; - constructor(private http: Http) { + constructor(private http: Http, constants: Constants) { + this.jwtKey = constants.TOKEN; } login(username: string, password: string, @@ -31,7 +34,7 @@ export class AuthService { this.isLoggedIn = true; this.activeUser = response.data[1]; - localStorage.setItem('jwt', response.data[0]) + localStorage.setItem(this.jwtKey, response.data[0]) } return response; @@ -43,7 +46,7 @@ export class AuthService { this.activeUser = null; this.isLoggedIn = false; - localStorage.removeItem('jwt'); + localStorage.removeItem(this.jwtKey); } return Observable.of(response); diff --git a/src/app/app.constants.ts b/src/app/shared/constants.ts similarity index 70% rename from src/app/app.constants.ts rename to src/app/shared/constants.ts index e6a1ee4..b657bcb 100644 --- a/src/app/app.constants.ts +++ b/src/app/shared/constants.ts @@ -3,5 +3,6 @@ import { Injectable } from '@angular/core'; @Injectable() export class Constants { public get VERSION(): string { return '1.0.0'; } + public get TOKEN(): string { return 'taskboard.jwt'; } } diff --git a/src/app/shared/index.ts b/src/app/shared/index.ts index 3008872..149f079 100644 --- a/src/app/shared/index.ts +++ b/src/app/shared/index.ts @@ -2,4 +2,5 @@ export * from './top-nav/top-nav.component'; export * from './auth/index'; export * from './models/index'; export * from './notifications/index'; +export * from './constants'; diff --git a/src/app/shared/notifications/notifications.component.ts b/src/app/shared/notifications/notifications.component.ts index b9eba8d..9b02a85 100644 --- a/src/app/shared/notifications/notifications.component.ts +++ b/src/app/shared/notifications/notifications.component.ts @@ -22,7 +22,7 @@ export class Notifications { private hide(note: Notification): void { let index = this.notes.indexOf(note); - note.type = note.type + " clicked"; + note.type += " clicked"; if (index >= 0) { setTimeout(() => { diff --git a/src/app/shared/notifications/notifications.service.ts b/src/app/shared/notifications/notifications.service.ts index 3f90745..b2299a3 100644 --- a/src/app/shared/notifications/notifications.service.ts +++ b/src/app/shared/notifications/notifications.service.ts @@ -10,7 +10,6 @@ export class NotificationsService { public noteAdded = this.notifications.asObservable(); public add(notification: Notification): void { - console.log(notification); this.notifications.next(notification); } } diff --git a/src/app/shared/top-nav/top-nav.component.ts b/src/app/shared/top-nav/top-nav.component.ts index 1d2a9f4..0721b4c 100644 --- a/src/app/shared/top-nav/top-nav.component.ts +++ b/src/app/shared/top-nav/top-nav.component.ts @@ -1,7 +1,7 @@ import { Component, Input } from '@angular/core'; import { ROUTER_DIRECTIVES, Router } from '@angular/router'; -import { Constants } from '../../app.constants'; +import { Constants } from '../constants'; import { AuthService } from '../auth/index'; @Component({