diff --git a/src/app/authentication/authentication.component.html b/src/app/authentication/authentication.component.html index 026dcc6..c934879 100644 --- a/src/app/authentication/authentication.component.html +++ b/src/app/authentication/authentication.component.html @@ -2,7 +2,7 @@

Log In

-
+
@@ -18,7 +18,7 @@ Submit -

+


The Kinsley Group is a leading energy solutions supplier with a 50 plus year legacy of sales, rental and diff --git a/src/app/authentication/authentication.component.ts b/src/app/authentication/authentication.component.ts index aacb6fa..9ffc978 100644 --- a/src/app/authentication/authentication.component.ts +++ b/src/app/authentication/authentication.component.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { LoginService } from '../services/login.service'; import { Router } from '@angular/router'; +import { ErrorHandler } from '@angular/core'; @Injectable() @@ -16,7 +17,7 @@ export class AuthenticationComponent implements OnInit { @ViewChild('email_input') email_input: ElementRef; @ViewChild('password_input') password_input: ElementRef; - constructor(private data: LoginService, private router: Router) { + constructor(private data: LoginService, private router: Router, private handleError: ErrorHandler) { } logOn () { @@ -26,8 +27,10 @@ export class AuthenticationComponent implements OnInit { 'user_password': this.password_input.nativeElement.value }; - this.data.authorizeUser(loginjson).subscribe((data) => { - if (data) { + const errMessage = document.getElementById('peep'); + errMessage.innerHTML = ''; + try { + this.data.authorizeUser(loginjson).subscribe((data) => { const token = data['token']; const message = data['message']; if (message === 'Authorized') { @@ -36,20 +39,14 @@ export class AuthenticationComponent implements OnInit { localStorage.setItem('auth_token', token); this.router.navigateByUrl('/generator-search'); } - } else { - document.getElementById('peep').innerHTML = 'Username or Password is Invalid'; + }); + } catch (err) { + // document.getElementById("loginForm").reset(); + errMessage.innerHTML = err.message; } - - }); } - /* - this.data.getUser(token).subscribe((me) => { - console.log(me); - }); - */ - ngOnInit() { } } diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts index b61af7e..e9efd3e 100644 --- a/src/app/services/login.service.ts +++ b/src/app/services/login.service.ts @@ -1,6 +1,9 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/observable/throw'; +import 'rxjs/add/operator/catch'; +import { ReplaySubject } from 'rxjs'; @Injectable({ providedIn: 'root' @@ -9,8 +12,15 @@ export class LoginService { constructor(private http: HttpClient) { } - authorizeUser(loginInfo) { + authorizeUser(loginInfo): Observable { return this.http.post('http://sd5-backend.engr.uconn.edu/auth', loginInfo); + // .catch((err) => { + // const errObj = { + // message: 'Username or Password is Invalid', + // token: 'none' + // }; + // return Observable.throw(errObj); + // }) } getUser(token) {