Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login #15

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
version: '3'
services:
discoveryservice:
image: aista/eureka
ports:
- "8761:8761"

rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

edgeservice:
image: aista/edge-service
ports:
- "8080:8080"
depends_on:
- discoveryservice

mysqlserver:
image: mysql:5.7
volumes:
- mysql-data:/var/lib/mysql:rw
restart: always
ports:
- '3306:3306'
environment:
MYSQL_USER:
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: 'user_service'

userservice:
build: ~/Documents/ai-testing-org/authentication-service/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pull from an image

depends_on:
- discoveryservice
- mysqlserver
ports:
- '8080'
environment:
- RABBIT_HOST=rabbitmq

calculationservice:
depends_on:
- discoveryservice
- rabbitmq
build: ~/go/src/github.com/AITestingOrg/calculation-service/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pull from an image

command: ["go", "run", "main.go"]
ports:
- "8080"
environment:
- RABBIT_HOST=rabbitmq
- EUREKA_SERVER=discoveryservice

gmapsadapter:
depends_on:
- discoveryservice
- rabbitmq
build: ~/Documents/ai-testing-org/gmaps-adapter/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pull from an image

ports:
- "8080"
environment:
- RABBIT_HOST=rabbitmq
- EUREKA_SERVER=discoveryservice

notificationservice:
depends_on:
- discoveryservice
- rabbitmq
image: aista/notification-service
command: notification-service
ports:
- "32700:32700"
environment:
- RABBIT_HOST=rabbitmq
- EUREKA_SERVER=discoveryservice

volumes:
mongo:
mysql-data:
20 changes: 15 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
"@angular/platform-browser": "^4.4.7",
"@angular/platform-browser-dynamic": "^4.4.7",
"@angular/router": "^4.4.7",
"@auth0/angular-jwt": "^2.0.0",
"@ngrx/entity": "^4.1.1",
"@ngrx/store": "^4.1.1",
"@ngrx/store-devtools": "^4.1.1",
"@types/eventsource": "^1.0.2",
"@types/googlemaps": "^3.30.10",
"angular2-jwt": "^0.2.3",
"core-js": "^2.5.7",
"eventsource-polyfill": "^0.9.6",
"eventsourcemock": "^2.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {HttpClientModule} from '@angular/common/http';
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
import {reducers} from './action-reducer-map';
import {StoreDevtoolsModule} from '@ngrx/store-devtools';
import {FormsModule} from '@angular/forms';
import 'rxjs/add/operator/map';
import { AuthenticationService } from './common/states/authentication.service';

const routes: Routes = [
{path: '', redirectTo: 'login', pathMatch: 'full'},
Expand All @@ -35,6 +37,7 @@ const routes: Routes = [
BrowserModule,
BrowserAnimationsModule,
FeCommonModule,
FormsModule,
RouterModule.forRoot(routes),
AgmCoreModule.forRoot({
apiKey: 'AIzaSyDPs_IyBxZNsYKEh8JplMe8a91URajuqic',
Expand All @@ -49,7 +52,7 @@ const routes: Routes = [
HttpClientModule
],
providers: [
GoogleMapsAPIWrapper, GMapsDirectionsService, NotificationService, EventSourceService
GoogleMapsAPIWrapper, GMapsDirectionsService, NotificationService, EventSourceService, AuthenticationService
],
bootstrap: [AppComponent]
})
Expand Down
10 changes: 5 additions & 5 deletions src/app/common/components/smart/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<mat-icon>directions_car</mat-icon>
<h1>UltiCar</h1>
<div class="mat-card-inputs">
<app-text-box input type="text" placeholder="Username" icon="person" [(textboxValue)]="usernameValue"></app-text-box>
<app-text-box input matInput type="text" placeholder="Password" [encryption]="true" [(textboxValue)]="passwordValue"></app-text-box><br/>
<app-check-box label="Remember my credentials" color="primary" [(checkboxValue)]="rememberUserValue"></app-check-box>
<app-text-box input type="text" placeholder="Username" icon="person" ngDefaultControl [(ngModel)]="loginData.username"></app-text-box>
<app-text-box input matInput type="text" placeholder="Password" [encryption]="true" ngDefaultControl [(ngModel)]="loginData.password"></app-text-box><br/>
<app-check-box label="Remember my credentials" color="primary" ngDefaultControl [(ngModel)]="loginData.rememberUser"></app-check-box>
</div>
<div class="mat-card-sign-in">
<app-raised-button label="Sign in" color="primary" [disabled]="false" (clickEvent)="signIn($event)"></app-raised-button>
<app-raised-button label="Sign in" color="primary" [disabled]="false" (clickEvent)="login()"></app-raised-button>
</div>
<div class="mat-card-register">
<app-basic-button type="submit" label="Create an Account" color="primary" (clickEvent)="register($event)"></app-basic-button>
<app-basic-button type="submit" label="Create an Account" color="primary" (clickEvent)="register()"></app-basic-button>
</div>
</mat-card>
</div>
34 changes: 10 additions & 24 deletions src/app/common/components/smart/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
import { Component, OnInit, Input } from '@angular/core';
import { Routes, RouterModule, Router } from '@angular/router';
import { Component, Input } from '@angular/core';
import { AuthenticationService } from '../../../../common/states/authentication.service';

@Component({
selector: 'app-login',
providers: [AuthenticationService],
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
export class LoginComponent {

constructor(private router: Router) { }
loginData = {username: '', password: '', rememberUser: false};

@Input() private disabled: string;
constructor(private _service: AuthenticationService) {}

ngOnInit() {
login() {
this._service.obtainAccessToken(this.loginData);
this._service.checkCredentials();
}

signIn(event) {
this.router.navigateByUrl('/dashboard');
}

register(event) {
console.log('Registered: ' + event);
}

rememberUser(event, checkboxValue) {
if (checkboxValue) {
console.log('Will remember.');
} else {
console.log('Will not remember.');
}
}
register() {}

rememberUserValue = true;
usernameValue = '';
passwordValue = '';
}
69 changes: 69 additions & 0 deletions src/app/common/states/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
import { JwtHelper } from 'angular2-jwt';

@Injectable()
export class AuthenticationService {

edgeServiceUrl = `http://localhost:8080/api/userservice/auth/oauth/token`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name reflects just the edge service, however the full path routes to the user service. Can you update the field name to denote this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good suggestion


constructor(private _router: Router, private _http: HttpClient) {}

obtainAccessToken(loginData) {
console.log('obtaining access token');
const headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + btoa('front-end:front-end')
});

console.log(loginData);

const params = new HttpParams()
.set('grant_type', 'password')
.set('scope', 'webclient')
.set('username', loginData.username)
.set('password', loginData.password);

const requestOptions = {
headers,
withCredentials: true,
};

console.log(params.toString());

this._http.post(
this.edgeServiceUrl,
params.toString(),
requestOptions,
).subscribe(
data => {
const token = (data as any).access_token;
localStorage.setItem('accessToken', token);
localStorage.setItem('userId', this.getUserId(token));
},
err => {
alert('Invalid credientals');
console.warn(`Failed to communicated with the user service. Err: ${JSON.stringify(err)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are two unrelated error messages, how can you know if the credentials are invalid if you failed to communicate with the user service?

});
}

checkCredentials() {
const token = localStorage.getItem('accessToken');
if (token != null) {
this._router.navigate(['/dashboard']);
}
}

getUserId(access_token) {
const helper = new JwtHelper();
const decodedToken = helper.decodeToken(access_token);
return (decodedToken as any).uuid;
}

logout() {
localStorage.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are only using the 'accessToken' item, but you are wiping everything from local storage, can logout just delete what it needs to?

this._router.navigate(['/login']);
}

}
13 changes: 4 additions & 9 deletions src/app/common/states/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class NotificationService {

onInit(): void {
const currNotificationService = this;
this.bindToNotificationEventSource(this.eventSourceService.forUrl(`http://localhost:32700/events?stream=${this.userId()}`,
const userId = localStorage.getItem('userId');
this.bindToNotificationEventSource(this.eventSourceService.forUrl(`http://localhost:32700/events?stream=${userId}`,
eventSource => this.bindToNotificationEventSource.call(currNotificationService, eventSource)));
this.listenForRouteUpdates();
}
Expand Down Expand Up @@ -71,15 +72,9 @@ export class NotificationService {
}

listenForRouteUpdates() {
this._subscription = this.newObservableForKey(NotificationService.ESTIMATED_PRICE).subscribe(next =>
{
//console.log(next);
this.passengerStore.dispatch(new UpdatePlannedRoute(next as Route))
this._subscription = this.newObservableForKey(NotificationService.ESTIMATED_PRICE).subscribe(next => {
this.passengerStore.dispatch(new UpdatePlannedRoute(next as Route));
});
}

private userId() {
return '560c62f4-8612-11e8-adc0-fa7ae01bbebc';
}
}

Loading