Commit 0dd7504c authored by Lukas Burgey's avatar Lukas Burgey

Support selection of idps

parent ddd0851a
<span *ngIf="userService.loggedIn ? false : true">
<button mat-raised-button color="accent" (click)="userService.login()">Login</button>
<form *ngIf="idps"
(ngSubmit)="userService.login(selectedIdP)" #loginForm="ngForm">
<mat-form-field>
<mat-select name="idp" required [(ngModel)]="selectedIdP">
<mat-option *ngFor="let idp of idps" [value]="idp.id">
{{ idp.name }}
</mat-option>
</mat-select>
</mat-form-field>
<button mat-raised-button [disabled]="!loginForm.form.valid" color="accent" type="submit">Login</button>
</form>
</span>
<span *ngIf="userService.loggedIn">
<button mat-button mat-icon-button (click)="dialog.openSshKeys()">
......
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DialogService } from '../dialog.service';
import { UserService } from '../user.service';
......@@ -10,9 +11,19 @@ import { UserService } from '../user.service';
})
export class LoginComponent {
private profileDialog;
public idps: any[];
public selectedIdP: number;
constructor(
public userService: UserService,
public dialog: DialogService,
) { }
public http: HttpClient,
) {
this.userService.getAuthInfo().subscribe(
data => {
this.idps = data['idps'];
this.selectedIdP = data['default'];
}
);
}
}
......@@ -52,6 +52,16 @@ interface StateAPIUser {
user: User;
}
interface IdP {
id: string;
name: string;
}
interface AuthInfo {
idps: IdP[];
default: number;
}
@Injectable()
export class UserService {
......@@ -61,6 +71,7 @@ export class UserService {
public sshKeyData: MatTableDataSource<any>;
public userInfoData: MatTableDataSource<any>;
public services: Service[];
public authInfo: AuthInfo;
constructor(
......@@ -91,17 +102,8 @@ export class UserService {
);
}
public login() {
this.backendOperational().subscribe(
(operational: boolean) => {
console.log(operational);
if (operational) {
window.location.href = 'https://hdf-portal.data.kit.edu/backend/auth';
} else {
this.snackBar.open('The backend is currently not operational');
}
}
);
public login(idpId: number) {
window.location.href = 'https://hdf-portal.data.kit.edu/backend/auth/v1/request/?idp=' + idpId;
}
public updateData(data: any) {
......@@ -138,7 +140,18 @@ export class UserService {
this.logState();
}
public update() {
public getAuthInfo() {
return this.http.get('/backend/auth/v1/info/').map(
(data) => {
return data;
},
(err) => {
return {};
}
);
}
public updateState() {
this.http
.get('/backend/api/state/')
.subscribe(
......@@ -152,8 +165,12 @@ export class UserService {
);
}
public update() {
this.updateState();
}
public logout() {
this.http.post('/backend/auth_logout/', {}).subscribe(
this.http.post('/backend/auth/v1/logout/', {}).subscribe(
data => {
this.updateData(data);
}
......
Markdown is supported
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