diff --git a/src/app/app.component.ts b/src/app/app.component.ts index af422f4..088bb0a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,6 +5,7 @@ import { LoanEditComponent } from './loan-edit/loan-edit.component'; import { mainMenuItems } from './main-menu-items'; import { AuthService } from './service/auth.service'; import { MenuService } from './service/menu.service'; +import {apiv1LoginResponse} from './models/api-v1-login-response'; @Component({ selector: 'app-root', @@ -14,47 +15,49 @@ import { MenuService } from './service/menu.service'; }) export class AppComponent implements OnInit , OnDestroy { title = 'SFM broker'; - public login :boolean = false; + public login = false; public items: any[] = mainMenuItems; kendokaAvatar = "./assets/img/avatar.png" - @ViewChild('loanEditComponent', {static: true}) loanEdit: LoanEditComponent; + @ViewChild('loanEditComponent', {static: true}) loanEdit: LoanEditComponent; - private loginSub: Subscription; - - constructor(private menuService: MenuService, private authService: AuthService){ - } + private loginSub: Subscription; - //check menuItem has fontawesome - public menuItemHasFontawesome (item: any) : boolean { - return item.hasOwnProperty('fa'); - } + constructor(private menuService: MenuService, private authService: AuthService){ + } - //menuItem clicked - public onSelect({ item }): void { - if (!item.items) { - this.menuService.itemClicked.emit(item); - //console.log("emit on select : " + item.text); - if ( item.popup == "loanEdit"){ - this.loanEdit.somedata = "" + Math.random() + "changed"; + // check menuItem has fontawesome + public menuItemHasFontawesome (item: any) : boolean { + return item.hasOwnProperty('fa'); + } + + // menuItem clicked + public onSelect({ item }): void { + if (!item.items) { + this.menuService.itemClicked.emit(item); + //console.log("emit on select : " + item.text); + if ( item.popup == "loanEdit"){ + this.loanEdit.somedata = "" + Math.random() + "changed"; this.loanEdit.open('dialog'); } - if (item.text == "Logout"){ + if (item.text == 'Logout'){ this.authService.logout(); - this.login = false; - //this.authService.loginSuccess.emit("loggedout"); + this.login = false; + // this.authService.loginSuccess.emit("loggedout"); } } - } + } + // tslint:disable-next-line:typedef ngOnInit (){ this.loginSub = this.authService.loginSuccess.subscribe( - (success: boolean) => { - this.login = success; + (rsp: apiv1LoginResponse) => { + this.login = rsp.login; } - ) + ); } + // tslint:disable-next-line:typedef ngOnDestroy (){ this.loginSub.unsubscribe(); } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 89b90d6..48793f5 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,6 +5,7 @@ import { CommonModule } from '@angular/common'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { HttpClientModule} from '@angular/common/http'; //Kendo import { MenuModule, ContextMenuModule } from '@progress/kendo-angular-menu'; import { IconsModule } from '@progress/kendo-angular-icons'; @@ -45,13 +46,6 @@ import { TransTailsComponent } from './trans-details/trans-tails/trans-tails.com - - - - - - - @NgModule({ declarations: [ AppComponent, @@ -72,7 +66,8 @@ import { TransTailsComponent } from './trans-details/trans-tails/trans-tails.com BrowserModule, FormsModule, CommonModule, - ReactiveFormsModule, + HttpClientModule, + ReactiveFormsModule, AppRoutingModule, MenuModule, ContextMenuModule, diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index f4fc652..ca6cc9f 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -4,7 +4,7 @@ import { Router } from '@angular/router'; import { NotificationService } from '@progress/kendo-angular-notification'; import { Subscription } from 'rxjs'; import { AuthService } from '../service/auth.service'; - +import {apiv1LoginResponse} from '../models/api-v1-login-response'; @Component({ selector: 'app-auth', @@ -12,19 +12,22 @@ import { AuthService } from '../service/auth.service'; styleUrls: ['./auth.component.scss'] }) export class AuthComponent implements OnInit, OnDestroy{ - loading : boolean ; // a state that user is currently loading loggin - loginSub: Subscription; + loading: boolean ; // a state that user is currently loading loggin + loginSub: Subscription; public userForm: FormGroup = new FormGroup({ - password: new FormControl('password', [Validators.minLength(3), Validators.maxLength(20)]), - email: new FormControl('email@email.com', Validators.email) + password: new FormControl('pass', [Validators.minLength(3), Validators.maxLength(20)]), + email: new FormControl('admin@supercredit.com.au', Validators.email) }); - constructor(private authService: AuthService, private rounter: Router, private notificationService: NotificationService) { } + constructor(private authService: AuthService, private router: Router, private notificationService: NotificationService) { } ngOnInit(): void { this.loginSub = this.authService.loginSuccess.subscribe( - (ok:boolean) =>{this.onLogin(ok)} + responseData => { + console.log(responseData); + this.onLogin(responseData); + } ); } @@ -32,20 +35,22 @@ export class AuthComponent implements OnInit, OnDestroy{ this.loginSub.unsubscribe(); } + // tslint:disable-next-line:typedef submitForm() { console.log(this.userForm); - this.loading = true; + this.loading = true; this.authService.login(this.userForm.value.email, this.userForm.value.password); - } - public onLogin(ok:boolean) { - this.loading = false - console.log (" found login success " + ok ); - if (ok) - this.rounter.navigate(["/dashboard"]); - else + public onLogin(rsp: apiv1LoginResponse) { + this.loading = false; + console.log ('found login ' , rsp ); + if (rsp.login) { + this.router.navigate(['/dashboard']); + } + else { this.show(); + } } public show(): void { diff --git a/src/app/models/api-v1-login-response.ts b/src/app/models/api-v1-login-response.ts new file mode 100644 index 0000000..48832ee --- /dev/null +++ b/src/app/models/api-v1-login-response.ts @@ -0,0 +1,8 @@ + + +// tslint:disable-next-line:class-name +export class apiv1LoginResponse { + id?: string; + login: boolean; + +} diff --git a/src/app/service/auth.service.ts b/src/app/service/auth.service.ts index 24430a4..6ff8806 100644 --- a/src/app/service/auth.service.ts +++ b/src/app/service/auth.service.ts @@ -1,38 +1,59 @@ import { EventEmitter, Injectable } from '@angular/core'; import { NotificationService } from '@progress/kendo-angular-notification'; +import {HttpClient} from '@angular/common/http'; +import {apiv1LoginResponse} from '../models/api-v1-login-response'; @Injectable() export class AuthService { - private loggedIn: boolean = false; - loginSuccess = new EventEmitter (); - + private loggedIn = false; + loginSuccess = new EventEmitter (); + constructor( private http: HttpClient) { + } + // tslint:disable-next-line:typedef isAuthenticated() { return this.loggedIn; } + // tslint:disable-next-line:typedef login(email: string, password: string) { - - const promise = new Promise( - (resolve, reject) => { - setTimeout(() => { - resolve(this.loggedIn); - console.log("email = " + email + " password = " + password); - var result = (( email == "email@email.com" ) && (password == "password")); - this.loggedIn = result; - this.loginSuccess.emit(result); - }, 800); + + this.http.post('http://svr2021:8080/api/v1/login', {u: email, p: password}).subscribe( + responseData => { + this.loggedIn = responseData.login; + this.loginSuccess.emit(responseData); + }, + error => { + const fail = { + login: false + }; + console.log(error); + this.loginSuccess.emit(fail); } + ); - return promise; + + // const promise = new Promise( + // (resolve, reject) => { + // setTimeout(() => { + // resolve(this.loggedIn); + // console.log('email = ' + email + ' password = ' + password); + // const result = (( email === 'email@email.com' ) && (password === 'password')); + // this.loggedIn = result; + // this.loginSuccess.emit(result); + // }, 800); + // } + // ); + // return promise; } + // tslint:disable-next-line:typedef logout() { this.loggedIn = false; } -} \ No newline at end of file +} diff --git a/src/app/trans-details/trans-details.component.html b/src/app/trans-details/trans-details.component.html index 9268690..8fd4ad8 100644 --- a/src/app/trans-details/trans-details.component.html +++ b/src/app/trans-details/trans-details.component.html @@ -1,9 +1,9 @@

-

Address: {{item.address}}

+ +
\ No newline at end of file diff --git a/src/app/trans-details/trans-tails/trans-tails.component.html b/src/app/trans-details/trans-tails/trans-tails.component.html index 4405a63..4b1a86a 100644 --- a/src/app/trans-details/trans-tails/trans-tails.component.html +++ b/src/app/trans-details/trans-tails/trans-tails.component.html @@ -7,10 +7,10 @@ scrollable="none" [navigable]="true" kendoGridFocusable> - + - + - + \ No newline at end of file