-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Login #15
Changes from 5 commits
de60acc
628dafd
aaf90b9
663803a
2954524
0f9eaf3
2c23928
1b5fa1c
0144cb0
f0b4a36
8a44726
9192c7d
7717204
eef0d1b
56af590
fb9bd29
ecbaa68
6f0f0d6
7a2aec9
872d329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ | ||
depends_on: | ||
- discoveryservice | ||
- mysqlserver | ||
ports: | ||
- '8080' | ||
environment: | ||
- RABBIT_HOST=rabbitmq | ||
|
||
calculationservice: | ||
depends_on: | ||
- discoveryservice | ||
- rabbitmq | ||
build: ~/go/src/github.com/AITestingOrg/calculation-service/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 = ''; | ||
} |
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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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