system user management + fix comment spelling
This commit is contained in:
parent
9ffc89dc30
commit
5feffbb068
3 changed files with 239 additions and 2 deletions
|
@ -237,7 +237,7 @@ else
|
|||
<td></td>
|
||||
<td class="align-middle text-end">
|
||||
@*
|
||||
***************** Price catalot overlay button *****************************
|
||||
***************** Price catalog overlay button *****************************
|
||||
*@
|
||||
<button class="btn btn-primary" type="button" @onclick="ShowPriceListOverlay">
|
||||
<i class="bi-plus"></i> Ny linje
|
||||
|
@ -276,7 +276,7 @@ else
|
|||
<div class="input-group">
|
||||
<input type="number" class="form-control" @bind-value="@Price"/>
|
||||
@*
|
||||
***************** Price history overlay button *****************************
|
||||
***************** Product Price history overlay button *********************
|
||||
*@
|
||||
<button class="btn btn-warning" type="button" @onclick="ShowPriceHistoryOverlay">
|
||||
<i class="bi-list-ul"></i>
|
||||
|
|
139
Wonky.Client/Pages/SystemUserCreatePage.razor
Normal file
139
Wonky.Client/Pages/SystemUserCreatePage.razor
Normal file
|
@ -0,0 +1,139 @@
|
|||
@*
|
||||
// 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 Microsoft.AspNetCore.Authorization
|
||||
@using Wonky.Client.Components
|
||||
@attribute [Authorize(Roles = "Admin")]
|
||||
@page "/system/users/create"
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h3>Bruger info</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (!string.IsNullOrWhiteSpace(UserInfo.UserId))
|
||||
{
|
||||
<EditForm EditContext="UserEditContext" OnValidSubmit="CreateUser">
|
||||
<DataAnnotationsValidator/>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr class="align-middle">
|
||||
<th scope="col">
|
||||
Fornavn
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="firstName" class="form-control" @bind-Value="UserInfo.FirstName" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.FirstName)"></ValidationMessage>
|
||||
</td>
|
||||
<th scope="col">
|
||||
Efternavn
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="lastName" class="form-control" @bind-Value="UserInfo.LastName" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.LastName)"></ValidationMessage>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="align-middle">
|
||||
<th scope="col">
|
||||
Email
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="email" class="form-control" @bind-Value="UserInfo.Email" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.Email)"></ValidationMessage>
|
||||
</td>
|
||||
<th scope="col">
|
||||
Mobilnummer
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="phoneNumber" class="form-control" @bind-Value="UserInfo.PhoneNumber" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.PhoneNumber)"></ValidationMessage>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="align-middle">
|
||||
<th scope="col">
|
||||
Sælgernr.
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="salesRep" class="form-control" @bind-Value="UserInfo.SalesRep" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.SalesRep)"></ValidationMessage>
|
||||
</td>
|
||||
<th scope="col">
|
||||
Landekode
|
||||
</th>
|
||||
<td>
|
||||
<InputText id="countryCode" class="form-control" @bind-Value="UserInfo.CountryCode" readonly="@ReadOnly" />
|
||||
<ValidationMessage For="@(() => UserInfo.CountryCode)"></ValidationMessage>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="align-middle">
|
||||
<th scope="col">
|
||||
Spærret
|
||||
</th>
|
||||
<td colspan="3">
|
||||
<InputCheckbox id="lockoutEnabled" class="form-check" @bind-Value="UserInfo.LockoutEnabled"/>
|
||||
<ValidationMessage For="@(() => UserInfo.LockoutEnabled)"></ValidationMessage>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button type="button" class="btn btn-danger" @onclick="() => ReadOnly = !ReadOnly">Rediger</button>
|
||||
</div>
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Gem</button>
|
||||
</div>
|
||||
<div class="col">
|
||||
<a class="btn btn-primary" href="/system/users">Tilbage</a>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
<EditForm EditContext="PasswdContext" class="mt-5" >
|
||||
<DataAnnotationsValidator />
|
||||
<h3>NULSTIL ADGANGSKODE</h3>
|
||||
<div class="alert-info">
|
||||
<h4>Password politik</h4>
|
||||
<p>Mindst 10 tegn bestående af store og små bogstaver samt tal. Du kan teste pasword og danne stærke password på <a href="https://pw.nix.dk">pw.nix.dk</a></p>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label for="newPasswd" class="col-md-2 col-form-label">Ny</label>
|
||||
<div class="col-md-10">
|
||||
<InputText id="newPasswd" class="form-control" @bind-Value="@Passwords.NewPassword"/>
|
||||
<ValidationMessage For="@(() => Passwords.NewPassword)"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label for="verifyPasswd" class="col-md-2 col-form-label">Bekræft</label>
|
||||
<div class="col-md-10">
|
||||
<InputText id="verifyPasswd" class="form-control" @bind-Value="@Passwords.ConfirmPassword"/>
|
||||
<ValidationMessage For="@(() => Passwords.ConfirmPassword)"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if (Working)
|
||||
{
|
||||
<WorkingThreeDots/>
|
||||
}
|
98
Wonky.Client/Pages/SystemUserCreatePage.razor.cs
Normal file
98
Wonky.Client/Pages/SystemUserCreatePage.razor.cs
Normal file
|
@ -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<SystemUserCreatePage> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue