From 5feffbb06850dd08728cd0941e6821a0df48e6e9 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Sat, 4 Mar 2023 08:09:01 +0100 Subject: [PATCH] system user management + fix comment spelling --- .../Pages/AdvisorActivityCreatePage.razor | 4 +- Wonky.Client/Pages/SystemUserCreatePage.razor | 139 ++++++++++++++++++ .../Pages/SystemUserCreatePage.razor.cs | 98 ++++++++++++ 3 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 Wonky.Client/Pages/SystemUserCreatePage.razor create mode 100644 Wonky.Client/Pages/SystemUserCreatePage.razor.cs diff --git a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor index 3416dcee..01063b76 100644 --- a/Wonky.Client/Pages/AdvisorActivityCreatePage.razor +++ b/Wonky.Client/Pages/AdvisorActivityCreatePage.razor @@ -237,7 +237,7 @@ else @* - ***************** Price catalot overlay button ***************************** + ***************** Price catalog overlay button ***************************** *@ + +
+ +
+
+ Tilbage +
+ + + + +

NULSTIL ADGANGSKODE

+
+

Password politik

+

Mindst 10 tegn bestående af store og små bogstaver samt tal. Du kan teste pasword og danne stærke password på pw.nix.dk

+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ } + + + + +@if (Working) +{ + +} diff --git a/Wonky.Client/Pages/SystemUserCreatePage.razor.cs b/Wonky.Client/Pages/SystemUserCreatePage.razor.cs new file mode 100644 index 00000000..72958e5f --- /dev/null +++ b/Wonky.Client/Pages/SystemUserCreatePage.razor.cs @@ -0,0 +1,98 @@ + +// Copyright (C) 2022 FCS Frede's Computer Services. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] +// + +using System.Text.Json; +using Blazored.Toast.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Wonky.Client.Helpers; +using Wonky.Client.HttpInterceptors; +using Wonky.Client.HttpRepository; +using Wonky.Entity.DTO; + +#pragma warning disable CS8618 + +namespace Wonky.Client.Pages; + +public partial class SystemUserCreatePage : IDisposable +{ + [Inject] public HttpInterceptorService Interceptor { get; set; } + [Inject] public ISystemUserRepository UserRepo { get; set; } + [Inject] public ILogger Logger { get; set; } + [Inject] public IToastService Toaster { get; set; } + private UserManagerEditView UserInfo { get; set; } = new(); + private EditContext UserEditContext { get; set; } + private ResetPasswordDto Passwords { get; set; } = new(); + private EditContext PasswdContext { get; set; } + private bool PwInvalid { get; set; } = true; + private bool Working { get; set; } = true; + private bool ReadOnly { get; set; } = true; + + private readonly JsonSerializerOptions _options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }; + + protected override async Task OnParametersSetAsync() + { + Interceptor.RegisterEvent(); + Interceptor.RegisterBeforeSendEvent(); + + UserEditContext = new EditContext(UserInfo); + PasswdContext = new EditContext(Passwords); + + PasswdContext.OnFieldChanged += PwHandleFieldChanged!; + PasswdContext.OnValidationStateChanged += PwValidationChanged; + Working = false; + } + + private async Task CreateUser() + { + ReadOnly = true; + Working = true; + Toaster.ShowInfo("Sender data til server ..."); + await UserRepo.CreateUser(UserInfo); + Working = false; + Toaster.ShowInfo("Bruger er oprettet ..."); + } + + private void PwHandleFieldChanged(object sender, FieldChangedEventArgs e) + { + PwInvalid = !PasswdContext.Validate(); + StateHasChanged(); + } + private void PwValidationChanged(object? sender, ValidationStateChangedEventArgs e) + { + PwInvalid = true; + if (!Utils.IsValidPasswd(Passwords.NewPassword)) + return; + + PasswdContext.OnFieldChanged -= PwHandleFieldChanged!; + PasswdContext.OnValidationStateChanged -= PwValidationChanged; + + PasswdContext = new EditContext(Passwords); + + PasswdContext.OnFieldChanged += PwHandleFieldChanged!; + PasswdContext.OnValidationStateChanged += PwValidationChanged; + } + + public void Dispose() + { + Interceptor.DisposeEvent(); + PasswdContext.OnFieldChanged -= PwHandleFieldChanged!; + PasswdContext.OnValidationStateChanged -= PwValidationChanged; + } +} \ No newline at end of file