From 17a5634c42079d2f370855fd6aa8ec677fccd595 Mon Sep 17 00:00:00 2001 From: Daniel Balk <67603460+Daniel-Balk@users.noreply.github.com> Date: Mon, 3 Apr 2023 01:44:58 +0200 Subject: [PATCH] untested totp / password change --- Moonlight/App/Models/Misc/AuditLogType.cs | 1 + Moonlight/App/Services/TotpService.cs | 11 +- .../Navigations/ProfileNavigation.razor | 11 +- Moonlight/Shared/Views/Profile/Security.razor | 288 ++++++++++++++++++ .../Shared/Views/Profile/Subscriptions.razor | 2 +- Moonlight/resources/lang/de_de.lang | 16 +- 6 files changed, 322 insertions(+), 7 deletions(-) create mode 100644 Moonlight/Shared/Views/Profile/Security.razor diff --git a/Moonlight/App/Models/Misc/AuditLogType.cs b/Moonlight/App/Models/Misc/AuditLogType.cs index 13fafa1..a2ccf6d 100644 --- a/Moonlight/App/Models/Misc/AuditLogType.cs +++ b/Moonlight/App/Models/Misc/AuditLogType.cs @@ -23,4 +23,5 @@ public enum AuditLogType CleanupEnabled, CleanupDisabled, CleanupTriggered, + PasswordChange, } \ No newline at end of file diff --git a/Moonlight/App/Services/TotpService.cs b/Moonlight/App/Services/TotpService.cs index be76546..0e359fe 100644 --- a/Moonlight/App/Services/TotpService.cs +++ b/Moonlight/App/Services/TotpService.cs @@ -46,8 +46,7 @@ public class TotpService public async Task Enable() { var user = (await IdentityService.Get())!; - - user.TotpEnabled = true; + user.TotpSecret = GenerateSecret(); UserRepository.Update(user); @@ -55,6 +54,14 @@ public class TotpService await AuditLogService.Log(AuditLogType.EnableTotp, user.Email); } + public async Task EnforceTotpLogin() + { + var user = (await IdentityService.Get())!; + + user.TotpEnabled = true; + UserRepository.Update(user); + } + public async Task Disable() { var user = (await IdentityService.Get())!; diff --git a/Moonlight/Shared/Components/Navigations/ProfileNavigation.razor b/Moonlight/Shared/Components/Navigations/ProfileNavigation.razor index 67b3816..ab04ef6 100644 --- a/Moonlight/Shared/Components/Navigations/ProfileNavigation.razor +++ b/Moonlight/Shared/Components/Navigations/ProfileNavigation.razor @@ -27,12 +27,17 @@
diff --git a/Moonlight/Shared/Views/Profile/Security.razor b/Moonlight/Shared/Views/Profile/Security.razor new file mode 100644 index 0000000..8b29c58 --- /dev/null +++ b/Moonlight/Shared/Views/Profile/Security.razor @@ -0,0 +1,288 @@ +@page "/profile/security" + +@using Moonlight.Shared.Components.Navigations +@using QRCoder +@using Moonlight.App.Services.LogServices +@using Moonlight.App.Services.Sessions +@using Moonlight.App.Services +@using Moonlight.App.Services.Interop +@using System.Text.RegularExpressions +@using Moonlight.App.Database.Entities +@using Moonlight.App.Models.Misc + +@inject SmartTranslateService SmartTranslateService +@inject AuditLogService AuditLogService +@inject TotpService TotpService +@inject NavigationManager NavigationManager +@inject IdentityService IdentityService +@inject UserService UserService +@inject AlertService AlertService +@inject ToastService ToastService + +