Commit 6f84345b authored by Javi Corvi's avatar Javi Corvi
Browse files

access only when logged

parent 4e9f148c
Pipeline #26596 failed with stage
in 0 seconds
<a *ngIf="!getIsLogged()" (click)="login()">Login</a>
<router-outlet *ngIf="getIsLogged()"></router-outlet>
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import {OAuthService, NullValidationHandler} from "angular-oauth2-oidc";
import { environment } from './../environments/environment';
import { map, filter } from 'rxjs/operators';
import {OAuthService} from "angular-oauth2-oidc";
import {environment } from './../environments/environment';
import {authConfig} from "./auth.config";
@Injectable({
providedIn: 'root'
......@@ -22,17 +22,7 @@ export class LoginService {
}
authenticationService(username: String, password: String) {
const url = `${this.apiUrl}/basicauth`;
return this.http.get(url,
{ headers: { authorization: this.createBasicAuthToken(username, password) } }).pipe(map((res) => {
this.username = username;
this.password = password;
this.registerSuccessfulLogin(username, password);
}));
}
createBasicAuthToken(username: String, password: String) {
......@@ -72,11 +62,14 @@ export class LoginService {
// }
public configure() {
this.oauthService.configure(authConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin();
this.oauthService.loadDiscoveryDocumentAndLogin();
this.oauthService.events
.pipe(filter((e) => e.type === 'token_received'))
.subscribe((_) => this.oauthService.loadUserProfile());
}
login() {
//this.oauthService.initLoginFlow();
this.oauthService.initImplicitFlow();
this.oauthService.initLoginFlow();
}
public getIsLogged(): boolean {
......
......@@ -27,14 +27,14 @@ export class LoginComponent implements OnInit {
}
handleLogin() {
this.authenticationService.authenticationService(this.username, this.password).subscribe((result)=> {
this.invalidLogin = false;
this.loginSuccess = true;
this.successMessage = 'Login Successful.';
this.router.navigate(['/documents']);
}, () => {
this.invalidLogin = true;
this.loginSuccess = false;
});
// this.authenticationService.authenticationService(this.username, this.password).subscribe((result)=> {
// this.invalidLogin = false;
// this.loginSuccess = true;
// this.successMessage = 'Login Successful.';
// this.router.navigate(['/documents']);
// }, () => {
// this.invalidLogin = true;
// this.loginSuccess = false;
// });
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment