Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions GUI/WPF/ViewModels/Controls/IdentifiantViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace Upsilon.Apps.Passkey.GUI.WPF.ViewModels.Controls
{
public class IdentifierViewModel : INotifyPropertyChanged
public partial class IdentifierViewModel : INotifyPropertyChanged
{
private readonly IAccount _account;

public static readonly Dictionary<string, string> IdentifiersTypes = new()
public static readonly Dictionary<string, string> IdentifiersTypes = new()
{
{ "[Username]", "👤" },
{ "[Email]", "📧" },
Expand All @@ -34,7 +34,7 @@ public string Identifier
value = _getIdentifierType(value);
}

foreach (var idType in IdentifiersTypes)
foreach (KeyValuePair<string, string> idType in IdentifiersTypes)
{
field = value.Replace(idType.Key, idType.Value);
}
Expand Down Expand Up @@ -63,20 +63,15 @@ public void Refresh()
OnPropertyChanged(nameof(IdentifierBackground));
}

[GeneratedRegex(@"^\+\d{1,3}[\d\s\-\.]{6,20}$")]
private static partial Regex _phoneRegex();
[GeneratedRegex(@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")]
private static partial Regex _mailRegex();
private static string _getIdentifierType(string identifier)
{
Regex phoneRegex = new(@"^\+\d{1,3}[\d\s\-\.]{6,20}$");
Regex emailRegex = new(@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$");

if (phoneRegex.IsMatch(identifier))
{
return "🖁" + identifier;
}
if (emailRegex.IsMatch(identifier))
{
return "📧" + identifier;
}
return "👤" + identifier;
return _phoneRegex().IsMatch(identifier) ? "🖁" + identifier
: _mailRegex().IsMatch(identifier) ? "📧" + identifier
: "👤" + identifier;
}
}
}
4 changes: 2 additions & 2 deletions GUI/WPF/ViewModels/Controls/ServiceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public ServiceViewModel(IService service, string identifierFilter = "", string t

public AccountViewModel AddAccount()
{
AccountViewModel? accountViewModel = Accounts.FirstOrDefault(x => x.Identifiers.Any(y => y.Identifier == "NewAccount"));
AccountViewModel? accountViewModel = Accounts.FirstOrDefault(x => x.Identifiers.Any(y => y.Identifier.StartsWith("👤New Account #")));

if (accountViewModel is null)
{
accountViewModel = new(Service.AddAccount(["NewAccount"]));
accountViewModel = new(Service.AddAccount(["👤New Account #" + DateTime.Now.Ticks]));
accountViewModel.PropertyChanged += _accountViewModel_PropertyChanged;
Accounts.Insert(0, accountViewModel);

Expand Down
4 changes: 2 additions & 2 deletions GUI/WPF/ViewModels/UserServicesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public UserServicesViewModel(string defaultTitle)

public ServiceViewModel AddService()
{
ServiceViewModel? serviceViewModel = Services.FirstOrDefault(x => x.ServiceName == "New Service");
ServiceViewModel? serviceViewModel = Services.FirstOrDefault(x => x.ServiceName.StartsWith("New Service #"));

if (serviceViewModel is null)
{
serviceViewModel = new(MainViewModel.User.AddService("New Service"));
serviceViewModel = new(MainViewModel.User.AddService("New Service #" + DateTime.Now.Ticks));
Services.Insert(0, serviceViewModel);
}

Expand Down
Binary file not shown.
13 changes: 7 additions & 6 deletions UnitTests/Models/DatabaseUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace Upsilon.Apps.Passkey.UnitTests.Models
[TestClass]
public sealed class DatabaseUnitTests
{
[TestMethod, Ignore]
[Ignore]
[TestMethod]
public void Case00_GenerateNewDatabase()
{
UnitTestsHelper.ClearTestEnvironment("_");

IDatabase database = UnitTestsHelper.CreateTestDatabase(["a", "b", "c"], "_");
IDatabase database = UnitTestsHelper.CreateTestDatabase(["a", "b"], "_");
IUser user = database.User;
user.LogoutTimeout = 10;
user.CleaningClipboardTimeout = 15;
Expand All @@ -39,18 +40,18 @@ public void Case00_GenerateNewDatabase()
{
case 1:
account = service.AddAccount(label: $"Account{j}",
identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => x + "@test.te"));
identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => $"👤{x}@test.te"));
break;
case 2:
account = service.AddAccount(identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => x + "@test.te"),
account = service.AddAccount(identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => $"👤{x}@test.te"),
password: password);
break;
case 3:
account = service.AddAccount(identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => x + "@test.te"));
account = service.AddAccount(identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => $"👤{x}@test.te"));
break;
default:
account = service.AddAccount(label: $"Account{j}",
identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => x + "@test.te"),
identifiers: UnitTestsHelper.GetRandomStringArray(random / 2).Select(x => $"👤{x}@test.te"),
password: password);
break;
}
Expand Down
Loading