CP TsLint small changes

This commit is contained in:
ThomasFransolet 2019-07-14 02:45:44 +02:00
parent fc1c96552d
commit b88b3da9e0
5 changed files with 28 additions and 31 deletions

View File

@ -10,7 +10,7 @@ export class JwtInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add authorization header with jwt token if available // add authorization header with jwt token if available
let currentUser = this._authService.currentUserValue; const currentUser = this._authService.currentUserValue;
if (currentUser && currentUser.token) { if (currentUser && currentUser.token) {
request = request.clone({ request = request.clone({
setHeaders: { setHeaders: {
@ -21,4 +21,4 @@ export class JwtInterceptor implements HttpInterceptor {
return next.handle(request); return next.handle(request);
} }
} }

View File

@ -19,7 +19,7 @@ export class AuthenticationService {
constructor( constructor(
protected http: HttpClient, protected http: HttpClient,
private _tokenService: TokenService private _tokenService: TokenService
) { ) {
this.currentUserSubject = new BehaviorSubject<UserInfo>(JSON.parse(localStorage.getItem('currentUser'))); this.currentUserSubject = new BehaviorSubject<UserInfo>(JSON.parse(localStorage.getItem('currentUser')));
this.currentUser = this.currentUserSubject.asObservable(); this.currentUser = this.currentUserSubject.asObservable();
} }
@ -38,7 +38,7 @@ export class AuthenticationService {
// store user details and jwt token in local storage to keep user logged in between page refreshes // store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user)); localStorage.setItem('currentUser', JSON.stringify(user));
this.currentUserSubject.next(user); this.currentUserSubject.next(user);
console.log('This is USER = ',user) console.log('This is USER = ', user );
return user; return user;
})); }));
} }

View File

@ -2,12 +2,12 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'; import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './control-panel/home/home.component'; import { HomeComponent } from './control-panel/home/home.component';
import { ConfigComponent } from './control-panel/profile/config/config.component'; import { ConfigComponent } from './control-panel/profile/config/config.component';
import { AuthGuard } from './_helpers/auth.guard'; import { AuthGuard } from './_helpers/auth.guard';
import { NotFoundComponent } from './control-panel/not-found/not-found.component'; import { NotFoundComponent } from './control-panel/not-found/not-found.component';
import { ProfileComponent } from './control-panel/profile/profile/profile.component'; import { ProfileComponent } from './control-panel/profile/profile/profile.component';
import { EditProfileComponent } from './control-panel/profile/edit-profile/edit-profile.component'; import { EditProfileComponent } from './control-panel/profile/edit-profile/edit-profile.component';
const routes: Routes = const routes: Routes =
[ [
{ path : '', redirectTo: 'home', pathMatch: 'full'}, { path : '', redirectTo: 'home', pathMatch: 'full'},
{ path : 'home', component: HomeComponent }, { path : 'home', component: HomeComponent },
@ -24,15 +24,14 @@ const routes: Routes =
] ]
}, },
{ path: '**', component: NotFoundComponent} { path: '**', component: NotFoundComponent}
]; ];
@NgModule({ @NgModule({
imports: imports:
[ [
RouterModule.forRoot(routes) RouterModule.forRoot(routes)
], ],
exports: exports:
[ [
RouterModule RouterModule
] ]

View File

@ -12,15 +12,15 @@ import { first } from 'rxjs/operators';
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrls: ['./app.component.css'] styleUrls: ['./app.component.css']
}) })
export class AppComponent implements OnInit{ export class AppComponent implements OnInit {
title = 'MyControlPanel'; title = 'MyControlPanel';
items : MenuItem[]; items: MenuItem[];
public Connected : boolean = false; public Connected = false;
public DisplayLoginModal: boolean = false; public DisplayLoginModal = false;
public DisplaySignInModal: boolean = false; public DisplaySignInModal = false;
public DisplayPersonalField: boolean = false; public DisplayPersonalField = false;
// Login // Login
public Username: string = null; public Username: string = null;
@ -33,17 +33,17 @@ export class AppComponent implements OnInit{
private _translateService: TranslateService, private _translateService: TranslateService,
private _authService: AuthenticationService, private _authService: AuthenticationService,
private _router: Router private _router: Router
){} ) {}
ngOnInit(){ ngOnInit() {
this.items = [ this.items = [
{label: 'Update', icon: 'pi pi-refresh'}, {label: 'Update', icon: 'pi pi-refresh'},
{label: 'Delete', icon: 'pi pi-times'} {label: 'Delete', icon: 'pi pi-times'}
]; ];
// To Include in a fonction of a dropdown language chose // To Include in a fonction of a dropdown language chose
this._translateService.setDefaultLang('fr'); this._translateService.setDefaultLang('fr');
let currentUser = this._authService.currentUserValue; const currentUser = this._authService.currentUserValue;
console.log(currentUser); console.log(currentUser);
if (currentUser && currentUser.token) { if (currentUser && currentUser.token) {
@ -57,9 +57,8 @@ export class AppComponent implements OnInit{
} }
public LogIn() public LogIn() {
{
/*this._appService.GetToken(this.Username, this.Password) /*this._appService.GetToken(this.Username, this.Password)
.subscribe(res => { .subscribe(res => {
console.log(res.Token); console.log(res.Token);
@ -101,8 +100,7 @@ export class AppComponent implements OnInit{
this._authService.IsLoggedIn = false; this._authService.IsLoggedIn = false;
this._router.navigate(['/home']); this._router.navigate(['/home']);
} }
public SignUp() public SignUp() {
{
this.DisplaySignInModal = true; this.DisplaySignInModal = true;
} }
} }

View File

@ -5,7 +5,7 @@ import { NgModule, Provider, APP_INITIALIZER } from '@angular/core';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { HomeComponent } from './control-panel/home/home.component'; import { HomeComponent } from './control-panel/home/home.component';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http'; import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AlertModule } from 'ngx-bootstrap/alert'; import { AlertModule } from 'ngx-bootstrap/alert';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker'; import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
@ -22,8 +22,8 @@ import { AppService } from './_services/app.service';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { CalendarModule } from 'primeng/calendar'; import { CalendarModule } from 'primeng/calendar';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader'; import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { AuthenticationService } from './_services/authentication.service'; import { AuthenticationService } from './_services/authentication.service';
import { ConfigComponent } from './control-panel/profile/config/config.component'; import { ConfigComponent } from './control-panel/profile/config/config.component';
import { NotFoundComponent } from './control-panel/not-found/not-found.component'; import { NotFoundComponent } from './control-panel/not-found/not-found.component';
@ -37,15 +37,15 @@ import { ErrorInterceptor } from './_helpers/error.interceptor';
export function initApiConfiguration(config: ApiConfiguration): Function { export function initApiConfiguration(config: ApiConfiguration): Function {
return () => { return () => {
config.rootUrl='https://localhost:5001'; // None = same rooturl config.rootUrl = 'https://localhost:5001'; // None = same rooturl
}; };
} }
export const INIT_API_CONFIGURATION: Provider = { export const INIT_API_CONFIGURATION: Provider = {
provide:APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory:initApiConfiguration, useFactory: initApiConfiguration,
deps: [ApiConfiguration], deps: [ApiConfiguration],
multi:true multi: true
}; };
// AoT requires an exported function for factories // AoT requires an exported function for factories