JAVA-67: renamed spring-security-angular to spring-security-web-angular
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<h1>Hi {{userName}}!</h1>
|
||||
<p><a [routerLink]="['/login']" (click) ="logout()">Logout</a></p>
|
||||
</div>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError, map, tap} from 'rxjs/operators';
|
||||
@Component({
|
||||
selector: 'home',
|
||||
templateUrl: './home.component.html'
|
||||
})
|
||||
|
||||
export class HomeComponent implements OnInit {
|
||||
|
||||
userName: string;
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
ngOnInit() {
|
||||
let url = 'http://localhost:8082/user';
|
||||
|
||||
let headers: HttpHeaders = new HttpHeaders({
|
||||
'Authorization': 'Basic ' + sessionStorage.getItem('token')
|
||||
});
|
||||
|
||||
let options = { headers: headers };
|
||||
this.http.post<Observable<Object>>(url, {}, options).
|
||||
subscribe(principal => {
|
||||
this.userName = principal['name'];
|
||||
},
|
||||
error => {
|
||||
if(error.status == 401)
|
||||
alert('Unauthorized');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
logout() {
|
||||
sessionStorage.setItem('token', '');
|
||||
}
|
||||
private handleError(error: HttpErrorResponse) {
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
console.error('An error occurred:', error.error.message);
|
||||
} else {
|
||||
console.error(
|
||||
`Backend returned code ${error.status}, ` +
|
||||
`body was: ${error.error}`);
|
||||
}
|
||||
return throwError(
|
||||
'Something bad happened; please try again later.');
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user