mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-05-04 00:34:05 +02:00
79 lines
2.3 KiB
Plaintext
79 lines
2.3 KiB
Plaintext
@using Phantom.Common.Data.Web.Users
|
|
@using Phantom.Common.Data.Web.Users.CreateUserResults
|
|
@using Phantom.Web.Services.Users
|
|
@using System.ComponentModel.DataAnnotations
|
|
@inherits Phantom.Web.Components.PhantomComponent
|
|
@inject IJSRuntime Js;
|
|
@inject UserManager UserManager;
|
|
|
|
<Form Model="form" OnSubmit="AddUser">
|
|
<Modal Id="@ModalId" TitleText="Add User">
|
|
<Body>
|
|
|
|
<div class="row">
|
|
<div class="mb-3">
|
|
<FormTextInput Id="account-username" Label="Username" @bind-Value="form.Username" autocomplete="off" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="mb-3">
|
|
<FormTextInput Id="account-password" Label="Password" Type="FormTextInputType.Password" autocomplete="new-password" @bind-Value="form.Password" />
|
|
</div>
|
|
</div>
|
|
|
|
</Body>
|
|
<Footer>
|
|
<FormSubmitError />
|
|
<FormButtonSubmit Label="Add User" class="btn btn-primary" />
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
</Footer>
|
|
</Modal>
|
|
</Form>
|
|
|
|
@code {
|
|
|
|
[Parameter, EditorRequired]
|
|
public string ModalId { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public EventCallback<UserInfo> UserAdded { get; set; }
|
|
|
|
private readonly AddUserFormModel form = new();
|
|
|
|
private sealed class AddUserFormModel : FormModel {
|
|
[Required]
|
|
public string Username { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Password { get; set; } = string.Empty;
|
|
}
|
|
|
|
private async Task AddUser(EditContext context) {
|
|
await form.SubmitModel.StartSubmitting();
|
|
|
|
var loggedInUserGuid = await GetUserGuid();
|
|
if (loggedInUserGuid == null || !await CheckPermission(Permission.EditUsers)) {
|
|
form.SubmitModel.StopSubmitting("You do not have permission to add users.");
|
|
return;
|
|
}
|
|
|
|
switch (await UserManager.Create(loggedInUserGuid.Value, form.Username, form.Password, CancellationToken)) {
|
|
case Success success:
|
|
await UserAdded.InvokeAsync(success.User);
|
|
await Js.InvokeVoidAsync("closeModal", ModalId);
|
|
form.SubmitModel.StopSubmitting();
|
|
break;
|
|
|
|
case CreationFailed fail:
|
|
form.SubmitModel.StopSubmitting(fail.Error.ToSentences("\n"));
|
|
break;
|
|
|
|
default:
|
|
form.SubmitModel.StopSubmitting("Unknown error.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|