Added loginhistory component
This commit is contained in:
parent
1e464f6fb8
commit
1462e141ad
@ -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>
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user