Passwort setzen funktion
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="WebServers">
|
<component name="WebServers">
|
||||||
<option name="servers">
|
<option name="servers">
|
||||||
<webServer id="e5ee7894-d0e4-495e-ad8a-6a6bb712ef8b" name="Contabo Neu" url="http://207.180.228.85">
|
<webServer id="e5ee7894-d0e4-495e-ad8a-6a6bb712ef8b" name="Contabo Neu" url="http://207.180.228.85:8700">
|
||||||
<fileTransfer host="207.180.228.85" port="21">
|
<fileTransfer host="207.180.228.85" port="21">
|
||||||
<advancedOptions>
|
<advancedOptions>
|
||||||
<advancedOptions dataProtectionLevel="Private" passiveMode="true" shareSSLContext="true" />
|
<advancedOptions dataProtectionLevel="Private" passiveMode="true" shareSSLContext="true" />
|
||||||
|
|||||||
@@ -104,6 +104,35 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method SetPassword
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the password using the specified user (a. beging, 20.05.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user</param>
|
||||||
|
/// <returns>A task containing the operation result</returns>
|
||||||
|
public async Task<OperationResult> SetPassword(User user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entityUser = await Context.Users.FirstOrDefaultAsync(x => x.Id == user.Id);
|
||||||
|
if (entityUser == null) return new OperationResult(new Exception("User not found"));
|
||||||
|
|
||||||
|
entityUser.Password = user.Password;
|
||||||
|
|
||||||
|
var saveR = await Context.SaveChangesAsync();
|
||||||
|
|
||||||
|
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
|
||||||
|
return new OperationResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new OperationResult(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Public Method Update
|
#region Public Method Update
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -134,7 +163,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
|||||||
|
|
||||||
var saveR = await Context.SaveChangesAsync();
|
var saveR = await Context.SaveChangesAsync();
|
||||||
|
|
||||||
if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern"));
|
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
|
||||||
return new OperationResult();
|
return new OperationResult();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
69
FoodsharingSiegen.Server/Dialogs/SetPasswordModal.razor
Normal file
69
FoodsharingSiegen.Server/Dialogs/SetPasswordModal.razor
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
@using FoodsharingSiegen.Contracts.Entity
|
||||||
|
@using FoodsharingSiegen.Shared.Helper
|
||||||
|
@using Microsoft.AspNetCore.Components
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private Modal ModalReference { get; set; } = null!;
|
||||||
|
|
||||||
|
private User User { get; set; } = new();
|
||||||
|
|
||||||
|
private string Password { get; set; }
|
||||||
|
private string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<User> OnPasswortSet { get; set; }
|
||||||
|
|
||||||
|
public async Task Show(User user)
|
||||||
|
{
|
||||||
|
User = user;
|
||||||
|
await ModalReference.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValidationStatus IsValidPassword { get; set; }
|
||||||
|
private ValidationStatus IsValidConfirm { get; set; }
|
||||||
|
|
||||||
|
private bool SaveDisabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsValidPassword != ValidationStatus.Success) return true;
|
||||||
|
if (IsValidConfirm != ValidationStatus.Success) return true;
|
||||||
|
return Password != ConfirmPassword;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveClick(object arg)
|
||||||
|
{
|
||||||
|
User.Password = Password;
|
||||||
|
await OnPasswortSet.InvokeAsync(User);
|
||||||
|
await ModalReference.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
<Modal @ref="@ModalReference">
|
||||||
|
<ModalContent Centered Size="ModalSize.Small">
|
||||||
|
<ModalHeader>
|
||||||
|
<ModalTitle>Passwort von @User.Name setzen</ModalTitle>
|
||||||
|
<CloseButton/>
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>Passwort</FieldLabel>
|
||||||
|
<Validation Validator="ValidationHelper.ValidatePassword" @bind-Status="@IsValidPassword">
|
||||||
|
<TextEdit @bind-Text="Password" Role="TextRole.Password" Placeholder="Passwort"></TextEdit>
|
||||||
|
</Validation>
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>Passwort wiederholen</FieldLabel>
|
||||||
|
<Validation Validator="ValidationHelper.ValidatePassword" @bind-Status="@IsValidConfirm">
|
||||||
|
<TextEdit @bind-Text="ConfirmPassword" Role="TextRole.Password" Placeholder="Passwort"></TextEdit>
|
||||||
|
</Validation>
|
||||||
|
</Field>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button Color="Color.Secondary" Clicked="ModalReference.Hide">Abbrechen</Button>
|
||||||
|
<Button Color="Color.Primary" Clicked="SaveClick" Disabled="@SaveDisabled">Speichern</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
@page "/login"
|
@page "/login"
|
||||||
@using FoodsharingSiegen.Server.Auth
|
@using FoodsharingSiegen.Server.Auth
|
||||||
|
@using FoodsharingSiegen.Shared.Helper
|
||||||
@layout LoginLayout
|
@layout LoginLayout
|
||||||
|
|
||||||
@inject AuthService AuthService
|
@inject AuthService AuthService
|
||||||
@@ -9,11 +10,11 @@
|
|||||||
<div class="card" style="width: 100%; max-width: 380px;">
|
<div class="card" style="width: 100%; max-width: 380px;">
|
||||||
<div class="card-header">FS Siegen</div>
|
<div class="card-header">FS Siegen</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<Validation Validator="ValidateMail" @bind-Status="@IsValidMail">
|
<Validation Validator="ValidationHelper.ValidateMail" @bind-Status="@IsValidMail">
|
||||||
<TextEdit @bind-Text="Mailaddress" Role="TextRole.Email" Placeholder="E-Mail" Class="mt-0" KeyUp="TextEdit_KeyUp"></TextEdit>
|
<TextEdit @bind-Text="Mailaddress" Role="TextRole.Email" Placeholder="E-Mail" Class="mt-0" KeyUp="TextEdit_KeyUp"></TextEdit>
|
||||||
</Validation>
|
</Validation>
|
||||||
|
|
||||||
<Validation Validator="ValidatePassword" @bind-Status="@IsValidPassword">
|
<Validation Validator="ValidationHelper.ValidatePassword" @bind-Status="@IsValidPassword">
|
||||||
<TextEdit @bind-Text="Password" Role="TextRole.Password" Placeholder="Passwort" Class="my-3" KeyUp="TextEdit_KeyUp"></TextEdit>
|
<TextEdit @bind-Text="Password" Role="TextRole.Password" Placeholder="Passwort" Class="my-3" KeyUp="TextEdit_KeyUp"></TextEdit>
|
||||||
</Validation>
|
</Validation>
|
||||||
|
|
||||||
|
|||||||
@@ -74,50 +74,5 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Method ValidateMail
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the mail using the specified args (a. beging, 11.04.2022)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="args">The args</param>
|
|
||||||
private void ValidateMail(ValidatorEventArgs args)
|
|
||||||
{
|
|
||||||
var email = Convert.ToString(args.Value);
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(email))
|
|
||||||
{
|
|
||||||
args.Status = ValidationStatus.None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isMatch = Regex.IsMatch(email, "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", RegexOptions.IgnoreCase);
|
|
||||||
|
|
||||||
args.Status = isMatch ? ValidationStatus.Success : ValidationStatus.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Method ValidatePassword
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates the password using the specified args (a. beging, 11.04.2022)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="args">The args</param>
|
|
||||||
private void ValidatePassword(ValidatorEventArgs args)
|
|
||||||
{
|
|
||||||
var password = Convert.ToString(args.Value);
|
|
||||||
if (string.IsNullOrWhiteSpace(password))
|
|
||||||
{
|
|
||||||
args.Status = ValidationStatus.None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isValid = password.Length > 3;
|
|
||||||
|
|
||||||
args.Status = isValid ? ValidationStatus.Success : ValidationStatus.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
@page "/user"
|
@page "/user"
|
||||||
@page "/users"
|
@page "/users"
|
||||||
@using FoodsharingSiegen.Contracts.Entity
|
@using FoodsharingSiegen.Contracts.Entity
|
||||||
|
@using FoodsharingSiegen.Server.Dialogs
|
||||||
|
|
||||||
@inherits FoodsharingSiegen.Server.BaseClasses.FsBase
|
@inherits FoodsharingSiegen.Server.BaseClasses.FsBase
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
<h2>Benutzerverwaltung <span style="font-size: .5em; line-height: 0;">Admin</span></h2>
|
<h2>Benutzerverwaltung <span style="font-size: .5em; line-height: 0;">Admin</span></h2>
|
||||||
|
|
||||||
<div class="my-2">
|
<div class="my-2">
|
||||||
<Button Color="Color.Primary" Disabled="@(SelectedUser == null)"><i class="fa-solid fa-key"></i> setzen</Button>
|
<Button Color="Color.Primary" Disabled="@(SelectedUser == null)" Clicked="() => PasswordModal.Show(SelectedUser!)"><i class="fa-solid fa-key"></i> setzen</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DataGrid TItem="User"
|
<DataGrid TItem="User"
|
||||||
@@ -109,3 +110,5 @@
|
|||||||
</DataGridColumn>
|
</DataGridColumn>
|
||||||
</DataGridColumns>
|
</DataGridColumns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
|
|
||||||
|
<SetPasswordModal @ref="PasswordModal" OnPasswortSet="OnPasswordSet"></SetPasswordModal>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
using FoodsharingSiegen.Contracts.Entity;
|
using FoodsharingSiegen.Contracts.Entity;
|
||||||
using FoodsharingSiegen.Server.Data.Service;
|
using FoodsharingSiegen.Server.Data.Service;
|
||||||
|
using FoodsharingSiegen.Server.Dialogs;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace FoodsharingSiegen.Server.Pages
|
namespace FoodsharingSiegen.Server.Pages
|
||||||
@@ -44,6 +45,7 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
public List<Company> Companies { get; set; }
|
public List<Company> Companies { get; set; }
|
||||||
public List<UserGroup> SelectedCompanies { get; set; }
|
public List<UserGroup> SelectedCompanies { get; set; }
|
||||||
public List<string> SelectedCompanyTexts { get; set; } = new();
|
public List<string> SelectedCompanyTexts { get; set; } = new();
|
||||||
|
public SetPasswordModal PasswordModal { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -147,6 +149,11 @@ namespace FoodsharingSiegen.Server.Pages
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task OnPasswordSet(User user)
|
||||||
|
{
|
||||||
|
var result = await UserService.SetPassword(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Company
|
public class Company
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Blazorise" Version="1.0.2" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
56
FoodsharingSiegen.Shared/Helper/ValidationHelper.cs
Normal file
56
FoodsharingSiegen.Shared/Helper/ValidationHelper.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Blazorise;
|
||||||
|
|
||||||
|
namespace FoodsharingSiegen.Shared.Helper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The validation helper class (a. beging, 20.05.2022)
|
||||||
|
/// </summary>
|
||||||
|
public static class ValidationHelper
|
||||||
|
{
|
||||||
|
#region Public Method ValidateMail
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the mail using the specified args (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">The args</param>
|
||||||
|
public static void ValidateMail(ValidatorEventArgs args)
|
||||||
|
{
|
||||||
|
var email = Convert.ToString(args.Value);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(email))
|
||||||
|
{
|
||||||
|
args.Status = ValidationStatus.None;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isMatch = Regex.IsMatch(email, "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
|
args.Status = isMatch ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Method ValidatePassword
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the password using the specified args (a. beging, 11.04.2022)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">The args</param>
|
||||||
|
public static void ValidatePassword(ValidatorEventArgs args)
|
||||||
|
{
|
||||||
|
var password = Convert.ToString(args.Value);
|
||||||
|
if (string.IsNullOrWhiteSpace(password))
|
||||||
|
{
|
||||||
|
args.Status = ValidationStatus.None;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isValid = password.Length > 3;
|
||||||
|
|
||||||
|
args.Status = isValid ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user