feat: added User Screen for admins
This commit is contained in:
parent
0279df06fa
commit
df1ac86636
11 changed files with 163 additions and 31 deletions
|
@ -7,7 +7,12 @@ public static class UsersRepository
|
||||||
public static async Task<List<UserData>> getUsersAsync()
|
public static async Task<List<UserData>> getUsersAsync()
|
||||||
{
|
{
|
||||||
await using var db = new AppDBContext();
|
await using var db = new AppDBContext();
|
||||||
return await db.Users.ToListAsync();
|
return await db.Users
|
||||||
|
.Include(user => user.SubmittedReports)
|
||||||
|
.Include(user => user.RecivedReports)
|
||||||
|
.Include(user => user.Comments)
|
||||||
|
.Include(user => user.Posts)
|
||||||
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<UserData> getUserByIdAsync(int userId)
|
public static async Task<UserData> getUserByIdAsync(int userId)
|
||||||
|
@ -19,7 +24,10 @@ public static class UsersRepository
|
||||||
public static async Task<UserData> getUserByEmailAsync(string email)
|
public static async Task<UserData> getUserByEmailAsync(string email)
|
||||||
{
|
{
|
||||||
await using var db = new AppDBContext();
|
await using var db = new AppDBContext();
|
||||||
return await db.Users.FirstOrDefaultAsync(user => user.Email == email);
|
return await db.Users
|
||||||
|
.Where(user => user.Email == email)
|
||||||
|
.Include(user => user.SubmittedReports)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<int> createUserAsync(UserData userToCreate)
|
public static async Task<int> createUserAsync(UserData userToCreate)
|
||||||
|
|
|
@ -1,6 +1,90 @@
|
||||||
@page "/sys/you"
|
@page "/sys/you"
|
||||||
<h3>UserPage</h3>
|
@using ImageBoardServerApp.Auth
|
||||||
|
@using ImageBoardServerApp.Data.Repository
|
||||||
|
@inject AuthenticationStateProvider authStateProvider
|
||||||
|
@inject NavigationManager navManager
|
||||||
|
|
||||||
|
<AuthorizeView>
|
||||||
|
<Authorized>
|
||||||
|
<h3>YOU</h3>
|
||||||
|
<br/>
|
||||||
|
<span>Email: @mail</span>
|
||||||
|
<br/>
|
||||||
|
<span>Email: </span>
|
||||||
|
<input type="email" id="email" @bind="newMail" />
|
||||||
|
<a @onclick="changeEmail" href="javascript:void(0)">[Change Email]</a>
|
||||||
|
<br/>
|
||||||
|
<span>Password: </span>
|
||||||
|
<input type="password" id="password" @bind="newPassword" />
|
||||||
|
<a @onclick="changePassword" href="javascript:void(0)">[Change Password]</a>
|
||||||
|
<br/>
|
||||||
|
<a @onclick="logout" href="javascript:void(0)">[Logout]</a>
|
||||||
|
</Authorized>
|
||||||
|
<NotAuthorized>
|
||||||
|
<span>You are not logged in.</span>
|
||||||
|
<a class="navbar-brand" href="/sys/login">Please login first.</a>
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
|
private string mail { get; set; } = "";
|
||||||
|
private string newMail { get; set; }
|
||||||
|
private string newPassword { get; set; }
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||||
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||||
|
if (user.User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
mail = user.User.Identity.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task logout()
|
||||||
|
{
|
||||||
|
var customAuthStateProvider = (CustomAuthenticationStateProvider) authStateProvider;
|
||||||
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
||||||
|
navManager.NavigateTo("/", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task changeEmail()
|
||||||
|
{
|
||||||
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||||
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||||
|
var usr = user.User;
|
||||||
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
||||||
|
if (foundusr == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int userID = foundusr.UserID;
|
||||||
|
if (newMail == null || newMail == "" || !newMail.Contains("@"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foundusr.Email = newMail;
|
||||||
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
await UsersRepository.updateUserAsync(foundusr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task changePassword()
|
||||||
|
{
|
||||||
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||||
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||||
|
var usr = user.User;
|
||||||
|
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
|
||||||
|
if (foundusr == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int userID = foundusr.UserID;
|
||||||
|
if (newPassword == null || newPassword == "")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foundusr.Password = BCrypt.Net.BCrypt.HashPassword(newPassword);
|
||||||
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
await UsersRepository.updateUserAsync(foundusr);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,12 @@
|
||||||
<span>We're currently hosting @amountOfPosts Threads, @amountOfComments Comments and @amountOfUsers Users.</span>
|
<span>We're currently hosting @amountOfPosts Threads, @amountOfComments Comments and @amountOfUsers Users.</span>
|
||||||
<sr/>
|
<sr/>
|
||||||
<span>@Details</span>
|
<span>@Details</span>
|
||||||
|
<AuthorizeView>
|
||||||
|
<Authorized>
|
||||||
|
<br/>
|
||||||
|
<a href="/sys/you">Edit your account</a>
|
||||||
|
</Authorized>
|
||||||
|
</AuthorizeView>
|
||||||
|
|
||||||
@code{
|
@code{
|
||||||
private string Details { get; set; }
|
private string Details { get; set; }
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<h3>Report @type#@id on /@board/</h3>
|
<h3>Report @type#@id on /@board/</h3>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<select name="rule" id="rule" @bind="@selectedItem">
|
<select name="rule" id="rule" @bind="@selectedItem">
|
||||||
<option value="none">Select</option>
|
<option value="none">Select</option>
|
||||||
|
@ -19,6 +18,7 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<span>@selectedItem</span>
|
<span>@selectedItem</span>
|
||||||
|
<br/>
|
||||||
<span>Explain further (optional)</span>
|
<span>Explain further (optional)</span>
|
||||||
<div class="pd centered marg">
|
<div class="pd centered marg">
|
||||||
<RadzenTextArea Placeholder="Specify..." @bind-Value="@explaination" Cols="30" Rows="6" Class="w-100"/>
|
<RadzenTextArea Placeholder="Specify..." @bind-Value="@explaination" Cols="30" Rows="6" Class="w-100"/>
|
||||||
|
@ -51,6 +51,8 @@
|
||||||
|
|
||||||
private async Task onReportClick()
|
private async Task onReportClick()
|
||||||
{
|
{
|
||||||
|
if (selectedItem == null || selectedItem == "none")
|
||||||
|
return;
|
||||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||||
var usr = user.User;
|
var usr = user.User;
|
||||||
|
@ -89,6 +91,13 @@
|
||||||
ReportExlaination = explaination
|
ReportExlaination = explaination
|
||||||
};
|
};
|
||||||
|
|
||||||
|
List<ReportData> submittedReports = foundusr.RecivedReports;
|
||||||
|
foreach(var r in submittedReports)
|
||||||
|
{
|
||||||
|
if (r.ReportedPostID == reportData.ReportedPostID && r.ReportedCommentID == reportData.ReportedCommentID)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var reportID = await ReportsRepository.createReportAsync(reportData);
|
var reportID = await ReportsRepository.createReportAsync(reportData);
|
||||||
js.InvokeVoidAsync("window.close");
|
js.InvokeVoidAsync("window.close");
|
||||||
}
|
}
|
|
@ -1,13 +1,24 @@
|
||||||
@page "/sys/users"
|
@page "/sys/users"
|
||||||
|
@using ImageBoardServerApp.Data.Repository
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<h3>Users</h3>
|
<h3>Users</h3>
|
||||||
|
@foreach (var u in users)
|
||||||
|
{
|
||||||
|
<UserEntry user="u"/>
|
||||||
|
<hr/>
|
||||||
|
}
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
<DeadLink/>
|
<DeadLink/>
|
||||||
</NotAuthorized>
|
</NotAuthorized>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
@code {
|
@code {
|
||||||
|
private List<UserData> users { get; set; }
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
users = await UsersRepository.getUsersAsync();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<span> /@report.ReportedComment/ </span>
|
<span> /@report.ReportedComment.Board/ </span>
|
||||||
}
|
}
|
||||||
<span>#@report.ReportID</span>
|
<span>#@report.ReportID</span>
|
||||||
<span>@report.Type</span>
|
<span>@report.Type</span>
|
||||||
|
|
16
ImageBoardServerApp/Shared/Components/UserEntry.razor
Normal file
16
ImageBoardServerApp/Shared/Components/UserEntry.razor
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
@using System.ComponentModel.DataAnnotations
|
||||||
|
<span>@user.Email | </span>
|
||||||
|
<span>@user.Posts.Count Posts | </span>
|
||||||
|
<span>@user.Comments.Count Comments | </span>
|
||||||
|
<span>@user.SubmittedReports.Count Reports submitted | </span>
|
||||||
|
<span>@user.RecivedReports.Count Reports recived | </span>
|
||||||
|
<span>@user.Role</span>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
[Required]
|
||||||
|
public UserData user { get; set; }
|
||||||
|
|
||||||
|
}
|
|
@ -65,5 +65,4 @@
|
||||||
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
||||||
navManager.NavigateTo("/", true);
|
navManager.NavigateTo("/", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,7 +13,6 @@
|
||||||
@using ImageBoardServerApp.Pages.Boards
|
@using ImageBoardServerApp.Pages.Boards
|
||||||
@using ImageBoardServerApp.Pages.Accounts
|
@using ImageBoardServerApp.Pages.Accounts
|
||||||
@using ImageBoardServerApp.Pages.Basic
|
@using ImageBoardServerApp.Pages.Basic
|
||||||
@using ImageBoardServerApp.Pages.Components
|
|
||||||
@using ImageBoardServerApp.Pages.Status
|
@using ImageBoardServerApp.Pages.Status
|
||||||
@using ImageBoardServerApp.Shared
|
@using ImageBoardServerApp.Shared
|
||||||
@using ImageBoardServerApp.Shared.Components
|
@using ImageBoardServerApp.Shared.Components
|
||||||
|
|
Loading…
Reference in a new issue