@namespace OpenArchival.Blazor.AdminPages.Shared @using Microsoft.AspNetCore.Components.Web @using MudBlazor @using System.Text.RegularExpressions @using System.ComponentModel.DataAnnotations @using OpenArchival.DataAccess @if (IsUpdate) { Update User } else { Create a User } @UserRoles.Admin @UserRoles.Writer Cancel Register @code { [Parameter] public UserDto Model { get; set; } = new(); [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!; [Parameter] public bool IsUpdate { get; set; } = false; private MudForm _mudForm { get; set; } = default!; private bool _isFormValid { get; set; } = false; private static IEnumerable PasswordStrength(string pw) { if (string.IsNullOrWhiteSpace(pw)) { yield return "Password is required!"; yield break; } if (pw.Length < 8) yield return "Password must be at least of length 8"; if (!Regex.IsMatch(pw, @"[A-Z]")) yield return "Password must contain at least one capital letter"; if (!Regex.IsMatch(pw, @"[a-z]")) yield return "Password must contain at least one lowercase letter"; if (!Regex.IsMatch(pw, @"[0-9]")) yield return "Password must contain at least one digit"; } private string? ValidatePermissions(bool value) { return null; } private string? PasswordMatch(string arg) { return Model.Password != arg ? "Passwords don't match" : null; } private void OnCancel(MouseEventArgs args) { MudDialog.Cancel(); } private void OnRegister(MouseEventArgs args) { MudDialog.Close(DialogResult.Ok(Model)); } }