From 1462e141ad91ce252852c6f8a6525db1e9cba99d Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 3 Jun 2024 23:52:12 +0200 Subject: [PATCH] Added loginhistory component --- .../loginhistory/loginhistory.component.html | 26 ++++++++ .../loginhistory/loginhistory.component.scss | 0 .../loginhistory.component.spec.ts | 23 ++++++++ .../loginhistory/loginhistory.component.ts | 59 +++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 frontend/src/app/adminui/loginhistory/loginhistory.component.html create mode 100644 frontend/src/app/adminui/loginhistory/loginhistory.component.scss create mode 100644 frontend/src/app/adminui/loginhistory/loginhistory.component.spec.ts create mode 100644 frontend/src/app/adminui/loginhistory/loginhistory.component.ts diff --git a/frontend/src/app/adminui/loginhistory/loginhistory.component.html b/frontend/src/app/adminui/loginhistory/loginhistory.component.html new file mode 100644 index 0000000..9b0b263 --- /dev/null +++ b/frontend/src/app/adminui/loginhistory/loginhistory.component.html @@ -0,0 +1,26 @@ +
+ +
+

Operations

+ +

Login history

+
+ + + + + + + + + + + + + + + + + +
Login TimeLogin IP
{{ entry.loginTime | date: 'dd. MMMM yyyy, HH:mm:ss' }}{{ entry.loginIp }}
+
diff --git a/frontend/src/app/adminui/loginhistory/loginhistory.component.scss b/frontend/src/app/adminui/loginhistory/loginhistory.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/adminui/loginhistory/loginhistory.component.spec.ts b/frontend/src/app/adminui/loginhistory/loginhistory.component.spec.ts new file mode 100644 index 0000000..4bd4b13 --- /dev/null +++ b/frontend/src/app/adminui/loginhistory/loginhistory.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginhistoryComponent } from './loginhistory.component'; + +describe('LoginhistoryComponent', () => { + let component: LoginhistoryComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LoginhistoryComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LoginhistoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/adminui/loginhistory/loginhistory.component.ts b/frontend/src/app/adminui/loginhistory/loginhistory.component.ts new file mode 100644 index 0000000..7bf22ba --- /dev/null +++ b/frontend/src/app/adminui/loginhistory/loginhistory.component.ts @@ -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); + } + } +}