Allow users to be approved
This commit is contained in:
parent
89837b55db
commit
9d99d9b77f
5 changed files with 1386 additions and 1 deletions
|
@ -45,6 +45,12 @@ namespace LANCommander.Data.Models
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public virtual ICollection<GameSave>? GameSaves { get; set; }
|
public virtual ICollection<GameSave>? GameSaves { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool Approved { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime ApprovedOn { get; set; }
|
||||||
|
|
||||||
public string GetGameSaveUploadPath()
|
public string GetGameSaveUploadPath()
|
||||||
{
|
{
|
||||||
return Path.Combine("Saves", Id.ToString());
|
return Path.Combine("Saves", Id.ToString());
|
||||||
|
|
1314
LANCommander/Migrations/20230402013359_AddUserApproval.Designer.cs
generated
Normal file
1314
LANCommander/Migrations/20230402013359_AddUserApproval.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
39
LANCommander/Migrations/20230402013359_AddUserApproval.cs
Normal file
39
LANCommander/Migrations/20230402013359_AddUserApproval.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,5 +6,6 @@
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
public IEnumerable<string> Roles { get; set; }
|
public IEnumerable<string> Roles { get; set; }
|
||||||
public long SavesSize { get; set; }
|
public long SavesSize { get; set; }
|
||||||
|
public bool Approved { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,13 @@
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
<ActionColumn>
|
<ActionColumn>
|
||||||
<Space Style="display: flex; justify-content: end">
|
<Space Style="display: flex; justify-content: end">
|
||||||
|
@if (!context.Approved)
|
||||||
|
{
|
||||||
|
<SpaceItem>
|
||||||
|
<Button OnClick="() => ApproveUser(context)" Type="@ButtonType.Primary">Approve</Button>
|
||||||
|
</SpaceItem>
|
||||||
|
}
|
||||||
|
|
||||||
<SpaceItem>
|
<SpaceItem>
|
||||||
@if (!context.Roles.Any(r => r == "Administrator"))
|
@if (!context.Roles.Any(r => r == "Administrator"))
|
||||||
{
|
{
|
||||||
|
@ -83,7 +90,8 @@
|
||||||
Id = user.Id,
|
Id = user.Id,
|
||||||
UserName = user.UserName,
|
UserName = user.UserName,
|
||||||
Roles = await UserManager.GetRolesAsync(user),
|
Roles = await UserManager.GetRolesAsync(user),
|
||||||
SavesSize = saveSize
|
SavesSize = saveSize,
|
||||||
|
Approved = user.Approved
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +99,23 @@
|
||||||
StateHasChanged();
|
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)
|
private async Task PromoteUser(UserViewModel user)
|
||||||
{
|
{
|
||||||
await UserManager.AddToRoleAsync(UserManager.Users.First(u => u.UserName == user.UserName), "Administrator");
|
await UserManager.AddToRoleAsync(UserManager.Users.First(u => u.UserName == user.UserName), "Administrator");
|
||||||
|
|
Loading…
Add table
Reference in a new issue