diff --git a/api/src/modules/auth/auth.module.ts b/api/src/modules/auth/auth.module.ts index 3cbdca8..38b17f9 100644 --- a/api/src/modules/auth/auth.module.ts +++ b/api/src/modules/auth/auth.module.ts @@ -5,6 +5,7 @@ import { DatabaseModule } from 'src/shared/database/database.module'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { HttpModule } from '@nestjs/axios'; import { JwtModule, JwtService } from '@nestjs/jwt'; +import { LogModule } from '../log/log.module'; @Module({ controllers: [AuthController], @@ -21,6 +22,7 @@ import { JwtModule, JwtService } from '@nestjs/jwt'; signOptions: { expiresIn: config.get('JWT_EXPIRES_IN') }, }), }), + LogModule ], exports: [JwtModule, AuthService], }) diff --git a/api/src/modules/auth/auth.service.ts b/api/src/modules/auth/auth.service.ts index 95e563f..702b4f3 100644 --- a/api/src/modules/auth/auth.service.ts +++ b/api/src/modules/auth/auth.service.ts @@ -7,6 +7,7 @@ import { ConfigService } from '@nestjs/config'; import { JwtService } from '@nestjs/jwt'; import { IExternalAccessPayload, IPayload } from 'src/model/interface'; import { User } from 'src/model/entitites'; +import { LogService, LogType } from '../log/log.service'; @Injectable() export class AuthService { @@ -15,9 +16,12 @@ export class AuthService { private readonly http: HttpService, private configService: ConfigService, private jwt: JwtService, + private log: LogService ) {} + register(register: CreateUserDto) { - return this.userRepo.createUser(register); + const user = this.userRepo.createUser(register); + this.log.log(LogType.Auth, user); } async registerOrLoginWithAuthCode(auth: AuthCodeDto): Promise { @@ -31,6 +35,7 @@ export class AuthService { return resolve(null); } this.generateTokens(user); + this.log.log(LogType.Auth, user); resolve(user); }, error: () => { @@ -116,6 +121,7 @@ export class AuthService { } getUserById(id: string): Promise { + this.log.log(LogType.Auth, null); return this.userRepo.findById(id); } diff --git a/api/src/modules/log/log.service.ts b/api/src/modules/log/log.service.ts index d7b8eaa..d532239 100644 --- a/api/src/modules/log/log.service.ts +++ b/api/src/modules/log/log.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; +import { User } from 'src/model/entitites'; import { EmailLogRepository } from 'src/model/repositories/log'; @Injectable() @@ -11,6 +12,8 @@ export class LogService { log(type: LogType, data: any) { if (type == LogType.Mail) { return this.logEmail(data); + } else if (type == LogType.Auth) { + return this.logAuthEvent(data); } } @@ -18,10 +21,15 @@ export class LogService { const log = this.emailLogRepo.create(data); const logEntry = await this.emailLogRepo.save(log); } + + private async logAuthEvent(data: User) { + console.error("auth logging not implemented") + } } export enum LogType { - Mail + Mail, + Auth } export enum EmailEvent { diff --git a/api/src/modules/mail/mail.service.ts b/api/src/modules/mail/mail.service.ts index a68dfdc..b9d3417 100644 --- a/api/src/modules/mail/mail.service.ts +++ b/api/src/modules/mail/mail.service.ts @@ -2,6 +2,8 @@ import { MailerService } from "@nestjs-modules/mailer"; import { Injectable } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { EmailEvent, LogService, LogType } from "../log/log.service"; +import { KeySystem } from "src/model/entitites/system.entity"; +import { User } from "src/model/entitites"; @Injectable() export class MailService { @@ -12,56 +14,60 @@ export class MailService { ) { } - async sendAccessGrantedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) { + async sendAccessGrantedMail({to, system}: {to: User, system: KeySystem}) { this.mailserService.sendMail({ template: './access', - to: to, + to: to.username, from: this.configService.get('MAILER_FROM'), subject: 'Zugriff gewährt', context: { - firstName, - systemName + firstName: to.firstName, + systemName: system.name } }).then(v => { this.logService.log(LogType.Mail, { to, success: true, message: v.response, - type: EmailEvent.GrantSystemAccess + type: EmailEvent.GrantSystemAccess, + system }) }).catch(e => { this.logService.log(LogType.Mail, { to, success: false, message: e.response, - type: EmailEvent.GrantSystemAccess + type: EmailEvent.GrantSystemAccess, + system }) }) } - sendAccessRemovedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) { + sendAccessRemovedMail({to, system}: {to: User, system: KeySystem}) { this.mailserService.sendMail({ template: './access-removed', - to: to, + to: to.username, from: this.configService.get('MAILER_FROM'), subject: 'Zugriff entzogen', context: { - firstName, - systemName + firstName: to.firstName, + systemName: system.name } }).then(v => { this.logService.log(LogType.Mail, { to, success: true, message: v.response, - type: EmailEvent.RemoveSystemAccess + type: EmailEvent.RemoveSystemAccess, + system }) }).catch(e => { this.logService.log(LogType.Mail, { to, success: false, message: e.response, - type: EmailEvent.RemoveSystemAccess + type: EmailEvent.RemoveSystemAccess, + system }) }) } diff --git a/api/src/modules/system/system.service.ts b/api/src/modules/system/system.service.ts index 7614122..23a9a7d 100644 --- a/api/src/modules/system/system.service.ts +++ b/api/src/modules/system/system.service.ts @@ -87,7 +87,7 @@ export class SystemService { relations: ['settings'] }); if (user.settings.sendSystemAccessMails) { - this.mailService.sendAccessRemovedMail({to: manageObject.email, firstName: manageObject.email, systemName: sys.name}) + this.mailService.sendAccessRemovedMail({to: user, system: sys}) } return sys.managers; } @@ -107,7 +107,7 @@ export class SystemService { sys.managers.push(user); await this.systemRepo.save(sys); if (user.settings.sendSystemAccessMails) { - this.mailService.sendAccessGrantedMail({to: user.username, firstName: user.firstName, systemName: sys.name}) + this.mailService.sendAccessGrantedMail({to: user, system: sys}) } return sys.managers; diff --git a/client/src/app/core/layout/layout.component.html b/client/src/app/core/layout/layout.component.html index 57f2889..e0b488d 100644 --- a/client/src/app/core/layout/layout.component.html +++ b/client/src/app/core/layout/layout.component.html @@ -12,14 +12,14 @@ - - - - + + + + @if (isAdmin) { - + } - + @@ -27,7 +27,7 @@ diff --git a/client/src/app/modules/auth/login/login.component.html b/client/src/app/modules/auth/login/login.component.html index 8ad5d48..1d28120 100644 --- a/client/src/app/modules/auth/login/login.component.html +++ b/client/src/app/modules/auth/login/login.component.html @@ -3,6 +3,6 @@ Du bist nicht eingeloggt. Logge dich ein um zu Beginnen.

- +
\ No newline at end of file diff --git a/client/src/app/modules/cylinder/components/create-cylinder/create-cylinder.component.html b/client/src/app/modules/cylinder/components/create-cylinder/create-cylinder.component.html index bf3ff14..e033519 100644 --- a/client/src/app/modules/cylinder/components/create-cylinder/create-cylinder.component.html +++ b/client/src/app/modules/cylinder/components/create-cylinder/create-cylinder.component.html @@ -25,8 +25,8 @@ - - + diff --git a/client/src/app/modules/cylinder/components/delete-cylinder/delete-cylinder.component.html b/client/src/app/modules/cylinder/components/delete-cylinder/delete-cylinder.component.html index c1e6974..674f46f 100644 --- a/client/src/app/modules/cylinder/components/delete-cylinder/delete-cylinder.component.html +++ b/client/src/app/modules/cylinder/components/delete-cylinder/delete-cylinder.component.html @@ -1,7 +1,7 @@

Zylinder {{cylinder.name}} löschen?

- warning + warning

{{cylinder.name}} wirklich entfernen? Alle Schlüssel die nur diesen Zylinder haben werden ebenfalls entfernt. @@ -13,8 +13,8 @@

- - + diff --git a/client/src/app/modules/cylinder/cylinder.component.html b/client/src/app/modules/cylinder/cylinder.component.html index cb03be8..e4e1820 100644 --- a/client/src/app/modules/cylinder/cylinder.component.html +++ b/client/src/app/modules/cylinder/cylinder.component.html @@ -4,6 +4,6 @@ [gridOptions]="gridOptions!" />
- +
\ No newline at end of file diff --git a/client/src/app/modules/dashboard/dashboard.component.html b/client/src/app/modules/dashboard/dashboard.component.html index 71b6458..0028544 100644 --- a/client/src/app/modules/dashboard/dashboard.component.html +++ b/client/src/app/modules/dashboard/dashboard.component.html @@ -17,7 +17,7 @@

Aktive Schlüssel

- + @@ -31,7 +31,7 @@

Registrierte Zylinder

- + @@ -45,7 +45,7 @@

Aktive Schließanlagen

- + @@ -59,7 +59,7 @@

Derzeit ausgegebene Schlüssel

- + diff --git a/client/src/app/modules/keys/components/archive/archive.component.html b/client/src/app/modules/keys/components/archive/archive.component.html index c27ca19..a42e2d7 100644 --- a/client/src/app/modules/keys/components/archive/archive.component.html +++ b/client/src/app/modules/keys/components/archive/archive.component.html @@ -8,5 +8,5 @@ - + \ No newline at end of file diff --git a/client/src/app/modules/keys/components/delete-key/delete-key.component.html b/client/src/app/modules/keys/components/delete-key/delete-key.component.html index 878fad5..17ae829 100644 --- a/client/src/app/modules/keys/components/delete-key/delete-key.component.html +++ b/client/src/app/modules/keys/components/delete-key/delete-key.component.html @@ -1,7 +1,7 @@

Schlüssel {{key.name}} löschen?

- warning + warning

{{key.name}} wirklich entfernen?

@@ -12,8 +12,8 @@
- - + diff --git a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.html b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.html index 2ce6c44..22f68e6 100644 --- a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.html +++ b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.html @@ -43,8 +43,11 @@ - - + + @@ -59,7 +62,7 @@ - + diff --git a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts index 5f5464c..a70fcc9 100644 --- a/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts +++ b/client/src/app/modules/keys/components/handover-dialog/handover-dialog.component.ts @@ -24,10 +24,11 @@ import {MatTabsModule} from '@angular/material/tabs'; import { GridApi, GridOptions, GridReadyEvent } from 'ag-grid-community'; import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale'; import { AgGridAngular } from 'ag-grid-angular'; +import { MatIconModule } from '@angular/material/icon'; @Component({ selector: 'app-handover-dialog', - imports: [FormsModule, MatTabsModule, AgGridAngular, ReactiveFormsModule, MatDatepickerModule, MatFormFieldModule, MatInputModule, MatButtonModule, MatDialogModule, MatAutocompleteModule, MatProgressSpinnerModule, MatRadioModule, AsyncPipe], + imports: [FormsModule, MatTabsModule, AgGridAngular, ReactiveFormsModule, MatDatepickerModule, MatFormFieldModule, MatInputModule, MatButtonModule, MatDialogModule, MatAutocompleteModule, MatProgressSpinnerModule, MatRadioModule, AsyncPipe, MatIconModule], providers: [ provideNativeDateAdapter(), { provide: LOCALE_ID, useValue: 'de-DE' }, diff --git a/client/src/app/modules/keys/components/lost-key/lost-key.component.html b/client/src/app/modules/keys/components/lost-key/lost-key.component.html index 0fe69da..0641aa2 100644 --- a/client/src/app/modules/keys/components/lost-key/lost-key.component.html +++ b/client/src/app/modules/keys/components/lost-key/lost-key.component.html @@ -6,7 +6,7 @@
@if(key.keyLost != null) { - report + report

{{key.name}} wirklich als gefunden markieren?

@@ -14,7 +14,7 @@ Die Information, dass er am {{ key.keyLost| date:'shortDate' }} verloren wurde, wird gelöscht!

} @else { - warning + warning

{{key.name}} wirklich als verloren markieren?

@@ -25,15 +25,15 @@
- + @if(key.keyLost != null) { - } @else { - diff --git a/client/src/app/modules/keys/components/lost-keys/lost-keys.component.html b/client/src/app/modules/keys/components/lost-keys/lost-keys.component.html index 8d7ca97..7e314d7 100644 --- a/client/src/app/modules/keys/components/lost-keys/lost-keys.component.html +++ b/client/src/app/modules/keys/components/lost-keys/lost-keys.component.html @@ -7,5 +7,5 @@ /> - + \ No newline at end of file diff --git a/client/src/app/modules/keys/create/create.component.html b/client/src/app/modules/keys/create/create.component.html index 532d667..30975e1 100644 --- a/client/src/app/modules/keys/create/create.component.html +++ b/client/src/app/modules/keys/create/create.component.html @@ -41,8 +41,8 @@ - - + diff --git a/client/src/app/modules/keys/create/select-key-cylinder/select-key-cylinder.component.html b/client/src/app/modules/keys/create/select-key-cylinder/select-key-cylinder.component.html index 01d486e..7234b04 100644 --- a/client/src/app/modules/keys/create/select-key-cylinder/select-key-cylinder.component.html +++ b/client/src/app/modules/keys/create/select-key-cylinder/select-key-cylinder.component.html @@ -10,6 +10,6 @@ - - + + \ No newline at end of file diff --git a/client/src/app/modules/keys/keys.component.html b/client/src/app/modules/keys/keys.component.html index e01d744..9e87b24 100644 --- a/client/src/app/modules/keys/keys.component.html +++ b/client/src/app/modules/keys/keys.component.html @@ -5,7 +5,7 @@ />
- +
diff --git a/client/src/app/modules/settings/settings.component.html b/client/src/app/modules/settings/settings.component.html index 8f64559..2e31364 100644 --- a/client/src/app/modules/settings/settings.component.html +++ b/client/src/app/modules/settings/settings.component.html @@ -3,12 +3,16 @@ }