Skip to content

Commit 4a66b77

Browse files
author
Ankur Srivastava
committed
fixed linter errors
1 parent a4074c6 commit 4a66b77

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

front/src/app/authentication/authentication.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export class AuthenticationService {
5757
*/
5858
public postResource(body: String, url: string) {
5959
let token = localStorage.getItem('token');
60-
let headers = new Headers({ 'Authorization': 'Bearer ' + token });
61-
headers.append('Content-Type', 'application/json');
62-
let options = new RequestOptions({ headers: headers });
60+
let postHeader = new Headers({ Authorization: 'Bearer ' + token });
61+
postHeader.append('Content-Type', 'application/json');
62+
let options = new RequestOptions({ headers: postHeader });
6363
return this.http.post(url, body, options);
6464
}
6565

@@ -68,8 +68,8 @@ export class AuthenticationService {
6868
*/
6969
public getResource(url: string) {
7070
let token = localStorage.getItem('token');
71-
let headers = new Headers({ 'Authentication-Token': token });
72-
let options = new RequestOptions({ headers: headers });
71+
let getHeader = new Headers({ Authorization: 'Bearer ' + token });
72+
let options = new RequestOptions({ headers: getHeader });
7373
return this.http.get(url, options);
7474
}
7575

@@ -92,11 +92,10 @@ export class AuthenticationService {
9292
* based on the first time authentication from server
9393
*/
9494
private checkTokenExpired() {
95-
9695
let expiryTime = Number(localStorage.getItem('exp'));
9796
let curTime = Math.floor(new Date().getTime() / 1000);
9897
if (curTime > expiryTime) {
99-
console.log("Session expired.")
98+
console.log('Session expired.');
10099
return true;
101100
}
102101
return false;

front/src/app/home/home.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { Http, Response } from '@angular/http';
33
import { AuthenticationService } from '../authentication';
44
import { Router } from '@angular/router';
5-
import { NavbarComponent } from '../navbar';
5+
import { NavbarComponent } from '../navbar';
66
import { WebService } from '../webservices';
77

88
@Component({
@@ -11,7 +11,7 @@ import { WebService } from '../webservices';
1111
styleUrls: ['./home.component.css'],
1212
providers: [WebService, AuthenticationService]
1313
})
14-
export class HomeComponent implements OnInit {
14+
export class HomeComponent implements OnInit, OnDestroy {
1515

1616
public heroes = [];
1717
constructor(private http: Http, private router: Router, private webservice: WebService) { }

front/src/app/login/login.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Observable } from 'rxjs/Rx';
1414
// directives to be available in this component
1515
providers: [AuthenticationService]
1616
})
17-
export class LoginFormComponent {
17+
export class LoginFormComponent implements OnInit {
1818

1919
public inputLogo = 'assets/img/angularclass-logo.png';
2020
public model: UserComponent = new UserComponent(1, '', '');
@@ -31,6 +31,14 @@ export class LoginFormComponent {
3131
this.myForm = new FormGroup(group);
3232
}
3333

34+
public ngOnInit() {
35+
console.log('Inside the login page');
36+
37+
if (this._service.isAuthenticated()) {
38+
console.log('We are authenticated, why go to login page again');
39+
this.router.navigate(['/home']);
40+
}
41+
}
3442

3543
public loginUser() {
3644

front/src/app/utils/notfound/notfound.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { ActivatedRoute, Router } from '@angular/router';
1919
</div>
2020
</div>
2121
`,
22-
styles: [`.center {text-align: center; margin-left: auto; margin-right: auto; margin-bottom: auto; margin-top: auto;}`]
22+
styles: [`.center {text-align: center; margin-left: auto; \
23+
margin-right: auto; margin-bottom: auto; margin-top: auto;}`]
2324
})
2425
export class NotFoundComponent {
2526
constructor(private router: Router) { }

0 commit comments

Comments
 (0)