Added loginhistory component

This commit is contained in:
Max W. 2024-06-03 23:52:12 +02:00
parent 1e464f6fb8
commit 1462e141ad
4 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,26 @@
<form method="dialog">
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"></button>
</form>
<h2 class="mb-3">Operations</h2>
<button class="btn btn-error" (click)="deleteLogins()">Delete all stored logins for the current user</button>
<h2 class="mt-5 mb-3">Login history</h2>
<div class="overflow-x-auto">
<table class="table w-full">
<thead>
<tr>
<!-- <th>ID</th>-->
<!-- <th>User ID</th>-->
<th>Login Time</th>
<th>Login IP</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let entry of loginHistory">
<!-- <td>{{ entry.id }}</td>-->
<!-- <td>{{ entry.userId }}</td>-->
<td>{{ entry.loginTime | date: 'dd. MMMM yyyy, HH:mm:ss' }}</td>
<td>{{ entry.loginIp }}</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginhistoryComponent } from './loginhistory.component';
describe('LoginhistoryComponent', () => {
let component: LoginhistoryComponent;
let fixture: ComponentFixture<LoginhistoryComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginhistoryComponent]
})
.compileComponents();
fixture = TestBed.createComponent(LoginhistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,59 @@
import {Component, Input} from '@angular/core';
import {DevelopmentStore} from "../../../store/DevelopmentStore";
import {AuthStore} from "../../../store/authStore";
import axios from "axios";
import {firstValueFrom} from "rxjs";
import {DatePipe, NgForOf} from "@angular/common";
@Component({
selector: 'app-loginhistory',
standalone: true,
imports: [
NgForOf,
DatePipe
],
templateUrl: './loginhistory.component.html',
styleUrl: './loginhistory.component.scss'
})
export class LoginhistoryComponent {
@Input() username: string = "";
loginHistory: any[] = [];
constructor(private developmentStore: DevelopmentStore, private authStore: AuthStore) {
this.fetchUserLoginHistory();
}
async fetchUserLoginHistory() {
try {
const response = await axios({
method: 'get',
url: this.developmentStore.getBaseUrl() + 'api/v1/secure/loginhistory',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + await firstValueFrom(this.authStore.token$)
}
});
this.loginHistory = response.data;
console.log(this.loginHistory)
} catch (error) {
console.error(error);
}
}
async deleteLogins() {
try {
const response = await axios({
method: 'delete',
url: this.developmentStore.getBaseUrl() + 'api/v1/secure/loginhistory',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + await firstValueFrom(this.authStore.token$)
}
});
console.log(response.data);
this.fetchUserLoginHistory();
} catch (error) {
console.error(error);
}
}
}