Allow users to be approved

dhcp-server
Pat Hartl 2023-08-11 13:30:29 -05:00
parent 89837b55db
commit 9d99d9b77f
5 changed files with 1386 additions and 1 deletions

View File

@ -45,6 +45,12 @@ namespace LANCommander.Data.Models
[JsonIgnore]
public virtual ICollection<GameSave>? GameSaves { get; set; }
[JsonIgnore]
public bool Approved { get; set; }
[JsonIgnore]
public DateTime ApprovedOn { get; set; }
public string GetGameSaveUploadPath()
{
return Path.Combine("Saves", Id.ToString());

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LANCommander.Migrations
{
public partial class AddUserApproval : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "Approved",
table: "AspNetUsers",
type: "INTEGER",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<DateTime>(
name: "ApprovedOn",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
migrationBuilder.Sql("update AspNetUsers set Approved = 1, ApprovedOn = datetime('now')");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Approved",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "ApprovedOn",
table: "AspNetUsers");
}
}
}

View File

@ -6,5 +6,6 @@
public string UserName { get; set; }
public IEnumerable<string> Roles { get; set; }
public long SavesSize { get; set; }
public bool Approved { get; set; }
}
}

View File

@ -19,6 +19,13 @@
</PropertyColumn>
<ActionColumn>
<Space Style="display: flex; justify-content: end">
@if (!context.Approved)
{
<SpaceItem>
<Button OnClick="() => ApproveUser(context)" Type="@ButtonType.Primary">Approve</Button>
</SpaceItem>
}
<SpaceItem>
@if (!context.Roles.Any(r => r == "Administrator"))
{
@ -83,7 +90,8 @@
Id = user.Id,
UserName = user.UserName,
Roles = await UserManager.GetRolesAsync(user),
SavesSize = saveSize
SavesSize = saveSize,
Approved = user.Approved
});
}
@ -91,6 +99,23 @@
StateHasChanged();
}
private async Task ApproveUser(UserViewModel user)
{
var dbUser = await UserManager.FindByIdAsync(user.Id.ToString());
if (dbUser != null)
{
dbUser.Approved = true;
dbUser.ApprovedOn = DateTime.Now;
await UserManager.UpdateAsync(dbUser);
user.Approved = true;
await MessageService.Success($"Approved {user.UserName}!");
}
}
private async Task PromoteUser(UserViewModel user)
{
await UserManager.AddToRoleAsync(UserManager.Users.First(u => u.UserName == user.UserName), "Administrator");