1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-16 03:31:43 +02:00
Files
.config
.run
.workdir
Agent
Common
Controller
Phantom.Controller
Phantom.Controller.Database
Phantom.Controller.Database.Postgres
Phantom.Controller.Minecraft
Phantom.Controller.Rpc
Phantom.Controller.Services
Agents
Audit
Events
Instances
Rpc
Users
AddRoleError.cs
AddUserError.cs
DeleteUserResult.cs
PasswordRequirementViolation.cs
RoleManager.cs
SetUserPasswordError.cs
UserManager.cs
UserPasswords.cs
UserRoleManager.cs
Phantom.Controller.Services.csproj
ServiceConfiguration.cs
Docker
Utils
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json

30 lines
1.0 KiB
C#

using System.Collections.Immutable;
namespace Phantom.Server.Services.Users;
public abstract record AddUserError {
private AddUserError() {}
public sealed record NameIsEmpty : AddUserError;
public sealed record NameIsTooLong(int MaximumLength) : AddUserError;
public sealed record NameAlreadyExists : AddUserError;
public sealed record PasswordIsInvalid(ImmutableArray<PasswordRequirementViolation> Violations) : AddUserError;
public sealed record UnknownError : AddUserError;
}
public static class AddUserErrorExtensions {
public static string ToSentences(this AddUserError error, string delimiter) {
return error switch {
AddUserError.NameIsEmpty => "Name cannot be empty.",
AddUserError.NameIsTooLong e => "Name cannot be longer than " + e.MaximumLength + " character(s).",
AddUserError.NameAlreadyExists => "Name is already occupied.",
AddUserError.PasswordIsInvalid e => string.Join(delimiter, e.Violations.Select(static v => v.ToSentence())),
_ => "Unknown error."
};
}
}