More reorganization and initial login/logout functionality
This commit is contained in:
parent
68d693307d
commit
a93f3bb005
@ -1,8 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Constants } from '../app.constants';
|
||||
import {
|
||||
Constants,
|
||||
AuthService,
|
||||
ApiResponse,
|
||||
Notification,
|
||||
|
@ -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,
|
||||
[
|
||||
|
@ -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);
|
||||
|
@ -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'; }
|
||||
}
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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(() => {
|
||||
|
@ -10,7 +10,6 @@ export class NotificationsService {
|
||||
public noteAdded = this.notifications.asObservable();
|
||||
|
||||
public add(notification: Notification): void {
|
||||
console.log(notification);
|
||||
this.notifications.next(notification);
|
||||
}
|
||||
}
|
||||
|
@ -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({
|
||||
|
Reference in New Issue
Block a user