Per-Arne Andersen
5 years ago
16 changed files with 249 additions and 14 deletions
@ -0,0 +1,43 @@ |
|||
<mat-card> |
|||
<mat-card-title> |
|||
API Keys |
|||
</mat-card-title> |
|||
|
|||
<mat-card-content> |
|||
You can use API-Keys to perform authenticated actions. These are less secure than using OAuth2, but at the gain for increased convenience. |
|||
<br><b>Note:</b> A newly created API Key will only show <b>once</b>. This means that you have to take note of the key and safe it somewhere safe. |
|||
|
|||
<table mat-table [dataSource]="dataSource" style="width: 100%"> |
|||
|
|||
<!-- Id Column --> |
|||
<ng-container matColumnDef="id"> |
|||
<th mat-header-cell *matHeaderCellDef> ID. </th> |
|||
<td mat-cell *matCellDef="let element"> {{element.id}} </td> |
|||
</ng-container> |
|||
|
|||
<!-- Key Column --> |
|||
<ng-container matColumnDef="key"> |
|||
<th mat-header-cell *matHeaderCellDef> API-Key </th> |
|||
<td mat-cell *matCellDef="let element"> {{(element.key) ? element.key : "[HIDDEN]"}} </td> |
|||
</ng-container> |
|||
|
|||
<!-- Created_At Column --> |
|||
<ng-container matColumnDef="created_at"> |
|||
<th mat-header-cell *matHeaderCellDef> Creation Date </th> |
|||
<td mat-cell *matCellDef="let element"> {{element.created_date | date:'medium'}} </td> |
|||
</ng-container> |
|||
|
|||
<!-- Delete Column --> |
|||
<ng-container matColumnDef="delete"> |
|||
<th mat-header-cell *matHeaderCellDef> Delete </th> |
|||
<td mat-cell *matCellDef="let element"> <button mat-flat-button color="warn" (click)="deleteAPIKey(element)">Delete</button></td> |
|||
</ng-container> |
|||
|
|||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr> |
|||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> |
|||
|
|||
</table> |
|||
|
|||
<button mat-flat-button color="primary" (click)="createAPIKey()">New Key</button> |
|||
</mat-card-content> |
|||
</mat-card> |
@ -0,0 +1,25 @@ |
|||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { ApiKeyComponent } from './api-key.component'; |
|||
|
|||
describe('ApiKeyComponent', () => { |
|||
let component: ApiKeyComponent; |
|||
let fixture: ComponentFixture<ApiKeyComponent>; |
|||
|
|||
beforeEach(async(() => { |
|||
TestBed.configureTestingModule({ |
|||
declarations: [ ApiKeyComponent ] |
|||
}) |
|||
.compileComponents(); |
|||
})); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(ApiKeyComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
@ -0,0 +1,45 @@ |
|||
import {Component, OnInit} from '@angular/core'; |
|||
import {ServerService} from "../../../../services/server.service"; |
|||
|
|||
@Component({ |
|||
selector: 'app-api-key', |
|||
templateUrl: './api-key.component.html', |
|||
styleUrls: ['./api-key.component.scss'] |
|||
}) |
|||
export class ApiKeyComponent implements OnInit { |
|||
|
|||
displayedColumns: string[] = ['id', 'key', 'created_at', 'delete']; |
|||
dataSource = []; |
|||
|
|||
constructor(private serverService: ServerService |
|||
) { } |
|||
|
|||
ngOnInit(): void { |
|||
|
|||
|
|||
this.serverService.getAPIKeys().subscribe((apiKeys: Array<any>) => { |
|||
this.dataSource = [...apiKeys] |
|||
|
|||
console.log(this.dataSource) |
|||
}) |
|||
} |
|||
|
|||
deleteAPIKey(elem){ |
|||
let idx = this.dataSource.indexOf(elem); |
|||
this.serverService.deleteAPIKey(elem.id).subscribe(x => { |
|||
this.dataSource.splice(idx, 1); |
|||
this.dataSource = [...this.dataSource] |
|||
}) |
|||
} |
|||
|
|||
createAPIKey(){ |
|||
|
|||
this.serverService.addAPIKey().subscribe(key => { |
|||
this.dataSource.push(key) |
|||
this.dataSource = [...this.dataSource] |
|||
|
|||
}) |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,3 @@ |
|||
.user-edit-component{ |
|||
padding: 20px; |
|||
} |
Loading…
Reference in new issue