-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
129 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/DevilDaggersInfo.Web.Client/Pages/Admin/Spawnsets/EditPage.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
src/DevilDaggersInfo.Web.Client/Pages/Admin/Users/AssignPlayerPage.razor
This file was deleted.
Oops, something went wrong.
164 changes: 164 additions & 0 deletions
164
src/DevilDaggersInfo.Web.Client/Pages/Admin/Users/EditPage.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
@page "/admin/users/edit/{Id:int}" | ||
@using DevilDaggersInfo.Web.ApiSpec.Admin.Players | ||
@using DevilDaggersInfo.Web.ApiSpec.Admin.Users | ||
@using DevilDaggersInfo.Web.Client.Components | ||
@using DevilDaggersInfo.Web.Client.Components.Admin | ||
@using DevilDaggersInfo.Web.Client.Components.Input | ||
@using DevilDaggersInfo.Web.Client.StateObjects.Admin.Users | ||
@using DevilDaggersInfo.Web.Core.Claims | ||
@using System.Security.Cryptography | ||
@inherits BaseAdminPage | ||
|
||
<AdminAuthorizer Base="this" RequiredRole="@Roles.Players"> | ||
<Heading Title="Admin - Edit User" /> | ||
|
||
<Heading Title="Assign Player" Level="2" /> | ||
|
||
<EditForm Model="@AssignPlayerState" OnValidSubmit="@AssignPlayerAsync"> | ||
<DataAnnotationsValidator /> | ||
<ValidationSummary /> | ||
|
||
<InputWrapper Label="Player"><SearchDropdown TKey="int" Values="@_playerNames" Converter="s => int.Parse(s)" @bind-Value="@AssignPlayerState.PlayerId" /></InputWrapper> | ||
|
||
<button class="btn btn-gray p-1" type="submit">Assign player</button> | ||
</EditForm> | ||
|
||
<Heading Title="Reset Password" Level="2" /> | ||
|
||
<button class="btn btn-gray p-1" @onclick="() => ResetPasswordState.NewPassword = GeneratePassword()">Generate random</button> | ||
|
||
<EditForm Model="@ResetPasswordState" OnValidSubmit="@ResetPasswordAsync"> | ||
<DataAnnotationsValidator /> | ||
<ValidationSummary /> | ||
|
||
<div class="grid gap-2 grid-cols-2 max-w-md"> | ||
<span>Password</span> | ||
<input class="bg-black border-gray-3 border-2" @bind="@ResetPasswordState.NewPassword" /> | ||
</div> | ||
|
||
<button class="btn btn-gray p-1" type="submit">Reset password</button> | ||
</EditForm> | ||
|
||
<Heading Title="Roles" Level="2" /> | ||
|
||
@if (_getUser == null) | ||
{ | ||
<Loading /> | ||
} | ||
else | ||
{ | ||
List<(string RoleName, bool IsEnabled)> data = | ||
[ | ||
(Roles.Admin, _getUser.IsAdmin), | ||
(Roles.CustomLeaderboards, _getUser.IsCustomLeaderboardsMaintainer), | ||
(Roles.Mods, _getUser.IsModsMaintainer), | ||
(Roles.Players, _getUser.IsPlayersMaintainer), | ||
(Roles.Spawnsets, _getUser.IsSpawnsetsMaintainer), | ||
]; | ||
foreach ((string roleName, bool isEnabled) in data) | ||
{ | ||
<div> | ||
<button @onclick="@(() => ToggleRoleAsync(roleName))" class="btn @(GetRoleButtonColor(isEnabled)) p-1">@(GetRoleButtonText(isEnabled)) @(roleName)</button> | ||
</div> | ||
} | ||
} | ||
</AdminAuthorizer> | ||
|
||
@code | ||
{ | ||
private Dictionary<int, string>? _playerNames; | ||
private GetUser? _getUser; | ||
|
||
[Parameter] | ||
[EditorRequired] | ||
public int Id { get; set; } | ||
|
||
[Parameter] | ||
public AssignPlayerState AssignPlayerState { get; set; } = new(); | ||
|
||
[Parameter] | ||
public ResetPasswordState ResetPasswordState { get; set; } = new(); | ||
|
||
private static string GetRoleButtonText(bool isEnabled) | ||
{ | ||
return isEnabled ? "Disable" : "Enable"; | ||
} | ||
|
||
private static string GetRoleButtonColor(bool isEnabled) | ||
{ | ||
return isEnabled ? "btn-red" : "btn-green"; | ||
} | ||
|
||
private static string GeneratePassword() | ||
{ | ||
// ReSharper disable StringLiteralTypo | ||
return RandomNumberGenerator.GetString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 20); | ||
// ReSharper restore StringLiteralTypo | ||
} | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
|
||
try | ||
{ | ||
List<GetPlayerName> getPlayerNames = await Http.GetPlayerNames(); | ||
_playerNames = getPlayerNames.ToDictionary(m => m.Id, m => m.PlayerName); | ||
|
||
_getUser = await Http.GetUserById(Id); | ||
AssignPlayerState.PlayerId = _getUser.PlayerId ?? 0; | ||
} | ||
catch (AccessTokenNotAvailableException exception) | ||
{ | ||
exception.Redirect(); | ||
} | ||
} | ||
|
||
private async Task AssignPlayerAsync() | ||
{ | ||
try | ||
{ | ||
HttpResponseMessage hrm = await Http.AssignPlayer(Id, AssignPlayerState.ToModel()); | ||
|
||
if (hrm.StatusCode == HttpStatusCode.OK) | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
catch (AccessTokenNotAvailableException exception) | ||
{ | ||
exception.Redirect(); | ||
} | ||
} | ||
|
||
private async Task ResetPasswordAsync() | ||
{ | ||
try | ||
{ | ||
HttpResponseMessage hrm = await Http.ResetPasswordForUserById(Id, ResetPasswordState.ToModel()); | ||
|
||
if (hrm.StatusCode == HttpStatusCode.OK) | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
catch (AccessTokenNotAvailableException exception) | ||
{ | ||
exception.Redirect(); | ||
} | ||
} | ||
|
||
private async Task ToggleRoleAsync(string roleName) | ||
{ | ||
try | ||
{ | ||
HttpResponseMessage hrm = await Http.ToggleRole(Id, new() | ||
{ | ||
RoleName = roleName, | ||
}); | ||
|
||
if (hrm.StatusCode == HttpStatusCode.OK) | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
catch (AccessTokenNotAvailableException exception) | ||
{ | ||
exception.Redirect(); | ||
} | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
src/DevilDaggersInfo.Web.Client/Pages/Admin/Users/ResetPasswordPage.razor
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters