Skip to content

Commit

Permalink
Merge pull request #27 from FlyersWeb/noSecretStored
Browse files Browse the repository at this point in the history
Secret is not stored anymore
  • Loading branch information
FlyersWeb authored Dec 13, 2019
2 parents b4af081 + ecded5a commit ebf816b
Show file tree
Hide file tree
Showing 19 changed files with 266 additions and 274 deletions.
21 changes: 9 additions & 12 deletions front-end/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { HelloComponent } from './hello/hello.component';

import { NgModule } from '@angular/core'
import { Routes, RouterModule } from '@angular/router'
import { LoginComponent } from './login/login.component'
import { HelloComponent } from './hello/hello.component'

const routes: Routes = [
{ path: '', component: LoginComponent},
{ path: 'hello', component: HelloComponent}
];
{ path: '', component: LoginComponent },
{ path: 'hello', component: HelloComponent }
]

@NgModule({
imports: [RouterModule.forRoot(
routes
)],
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
export class AppRoutingModule {}
29 changes: 12 additions & 17 deletions front-end/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { TestBed, async } from '@angular/core/testing'
import { RouterTestingModule } from '@angular/router/testing'
import { AppComponent } from './app.component'

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
}));
imports: [RouterTestingModule],
declarations: [AppComponent]
}).compileComponents()
}))

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});

});
const fixture = TestBed.createComponent(AppComponent)
const app = fixture.debugElement.componentInstance
expect(app).toBeTruthy()
})
})
4 changes: 2 additions & 2 deletions front-end/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component } from '@angular/core';
import { Component } from '@angular/core'

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Angular Symfony';
title = 'Angular Symfony'
}
32 changes: 13 additions & 19 deletions front-end/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'

import { AppRoutingModule } from './app-routing.module';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { HelloComponent } from './hello/hello.component';
import { httpInterceptorProviders } from './http-interceptor';
import { AppRoutingModule } from './app-routing.module'
import { ReactiveFormsModule } from '@angular/forms'
import { HttpClientModule } from '@angular/common/http'
import { AppComponent } from './app.component'
import { LoginComponent } from './login/login.component'
import { HelloComponent } from './hello/hello.component'
import { httpInterceptorProviders } from './http-interceptor'

@NgModule({
declarations: [
AppComponent,
LoginComponent,
HelloComponent
],
declarations: [AppComponent, LoginComponent, HelloComponent],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
HttpClientModule,
],
providers: [
httpInterceptorProviders
HttpClientModule
],
providers: [httpInterceptorProviders],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {}
38 changes: 17 additions & 21 deletions front-end/src/app/hello/hello.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { RouterTestingModule } from '@angular/router/testing'

import { HelloComponent } from './hello.component';
import { HelloComponent } from './hello.component'

describe('HelloComponent', () => {
let component: HelloComponent;
let fixture: ComponentFixture<HelloComponent>;
let component: HelloComponent
let fixture: ComponentFixture<HelloComponent>

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
RouterTestingModule,
],
declarations: [ HelloComponent ]
})
.compileComponents();
}));
imports: [HttpClientTestingModule, RouterTestingModule],
declarations: [HelloComponent]
}).compileComponents()
}))

beforeEach(() => {
fixture = TestBed.createComponent(HelloComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(HelloComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})
43 changes: 21 additions & 22 deletions front-end/src/app/hello/hello.component.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Component, OnInit } from '@angular/core'
import { Observable } from 'rxjs'

import { WSSEService } from '../wsse.service';
import { HttpErrorResponse } from '@angular/common/http';
import { Router } from '@angular/router';
import { TokenService } from '../token.service';
import { WSSEService } from '../wsse.service'
import { HttpErrorResponse } from '@angular/common/http'
import { Router } from '@angular/router'
import { TokenService } from '../token.service'

@Component({
selector: 'app-hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.css']
})
export class HelloComponent implements OnInit {
$hello: Observable<{ hello?: string }>
helloMessage: string

$hello: Observable<{ hello?: string }>;
helloMessage: string;

constructor(
constructor (
private wsseService: WSSEService,
private tokenService: TokenService,
private router: Router,
) { }
private router: Router
) {}

ngOnInit() {
ngOnInit () {
// Example API call showing an Hello World
this.$hello = this.wsseService.getHello();
this.$hello = this.wsseService.getHello()

this.$hello.subscribe(
// Show API response
({ hello }) => {
console.log(`Received from server ${hello}`);
this.helloMessage = hello;
console.log(`Received from server ${hello}`)
this.helloMessage = hello
},
// Log error message and redirect to login
(error: HttpErrorResponse) => {
console.error(error);
console.error(error)
if (error.status === 401) {
return this.router.navigate(['']);
return this.router.navigate([''])
}
});
}
)
}

onGoBack() {
return this.router.navigate(['']);
onGoBack () {
return this.router.navigate([''])
}

}
8 changes: 4 additions & 4 deletions front-end/src/app/http-interceptor/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http'

import { WSSEInterceptor } from './wsse-interceptor';
import { WSSEInterceptor } from './wsse-interceptor'

/** Http interceptor providers in outside-in order */
export const httpInterceptorProviders = [
{ provide: HTTP_INTERCEPTORS, useClass: WSSEInterceptor, multi: true },
];
{ provide: HTTP_INTERCEPTORS, useClass: WSSEInterceptor, multi: true }
]
23 changes: 11 additions & 12 deletions front-end/src/app/http-interceptor/wsse-interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { TokenService } from '../token.service';
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http';
import { TokenService } from '../token.service'
import { Injectable } from '@angular/core'
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http'

@Injectable()
export class WSSEInterceptor implements HttpInterceptor {
constructor (private tokenService: TokenService) {}

constructor(private tokenService: TokenService) {}

intercept(req: HttpRequest<any>, next: HttpHandler) {
let authToken = this.tokenService.getAuthorizationToken();
intercept (req: HttpRequest<any>, next: HttpHandler) {
let authToken = this.tokenService.getAuthorizationToken()

if (authToken) {
// Clone the request and replace the original headers with
// cloned headers, updated with the authorization.
// cloned headers, updated with the authorization.
const authReq = req.clone({
headers: req.headers.set('X-WSSE', authToken)
});
})
// send cloned request with header to the next handler.
return next.handle(authReq);
return next.handle(authReq)
} else {
// otherwise send request without token
return next.handle(req);
return next.handle(req)
}
}
}
}
35 changes: 17 additions & 18 deletions front-end/src/app/login/login.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'

import { LoginComponent } from './login.component';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { LoginComponent } from './login.component'
import { ReactiveFormsModule } from '@angular/forms'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { RouterTestingModule } from '@angular/router/testing'

describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let component: LoginComponent
let fixture: ComponentFixture<LoginComponent>

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand All @@ -16,18 +16,17 @@ describe('LoginComponent', () => {
HttpClientTestingModule,
RouterTestingModule
],
declarations: [ LoginComponent ]
})
.compileComponents();
}));
declarations: [LoginComponent]
}).compileComponents()
}))

beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(LoginComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})
Loading

0 comments on commit ebf816b

Please sign in to comment.