2023-02-12 16:01:46 +00:00
|
|
|
@page "/sys/report/{type}/{board}/{id}"
|
2023-02-03 10:33:56 +00:00
|
|
|
@using System.ComponentModel.DataAnnotations
|
2023-02-11 22:04:02 +00:00
|
|
|
@using System.Data
|
|
|
|
@using ImageBoardServerApp.Auth
|
|
|
|
@using ImageBoardServerApp.Data.Repository
|
|
|
|
@inject AuthenticationStateProvider authStateProvider
|
|
|
|
@inject IJSRuntime js
|
2023-06-08 21:34:20 +00:00
|
|
|
|
|
|
|
<PageTitle>Report @type#@id on /@board/ - BulletBoards</PageTitle>
|
2023-02-11 22:04:02 +00:00
|
|
|
<AuthorizeView>
|
2023-02-12 18:06:33 +00:00
|
|
|
<Authorized>
|
|
|
|
<h3>Report @type#@id on /@board/</h3>
|
|
|
|
<div>
|
|
|
|
<select name="rule" id="rule" @bind="@selectedItem">
|
|
|
|
<option value="none">Select</option>
|
|
|
|
@foreach (var r in RulesConv.dict.Keys)
|
|
|
|
{
|
|
|
|
<option value="@r">@RulesConv.dict[r]</option>
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<span>@selectedItem</span>
|
|
|
|
<br/>
|
|
|
|
<span>Explain further (optional)</span>
|
|
|
|
<div class="pd centered marg">
|
2023-06-12 18:46:44 +00:00
|
|
|
<RadzenTextArea Placeholder="Specify..." @bind-Value="@explaination" Cols="30" Rows="6" Class="w-100"/>
|
2023-02-12 18:06:33 +00:00
|
|
|
</div>
|
|
|
|
<RadzenButton class="pd" Click="@onReportClick" Text="Report"></RadzenButton>
|
|
|
|
</Authorized>
|
|
|
|
<NotAuthorized>
|
|
|
|
<span>Please login to report</span>
|
|
|
|
</NotAuthorized>
|
|
|
|
</AuthorizeView>
|
2023-02-03 10:33:56 +00:00
|
|
|
|
|
|
|
@code {
|
2023-02-11 22:04:02 +00:00
|
|
|
private IEnumerable<Rule> rules;
|
|
|
|
private string selectedItem;
|
|
|
|
private string explaination;
|
|
|
|
|
|
|
|
|
2023-02-03 10:33:56 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public string type { get; set; }
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-02-03 10:33:56 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public string board { get; set; }
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-02-03 10:33:56 +00:00
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public string id { get; set; }
|
2023-02-11 22:04:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
private async Task onReportClick()
|
|
|
|
{
|
2023-02-12 18:06:33 +00:00
|
|
|
if (selectedItem == null || selectedItem == "none")
|
|
|
|
return;
|
2023-02-11 22:04:02 +00:00
|
|
|
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
|
|
|
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
|
|
|
var usr = user.User;
|
2023-06-12 18:46:44 +00:00
|
|
|
UserData foundusr = await UsersRepository.getUserByEmailRawAsync(usr.Identity.Name);
|
2023-02-11 22:04:02 +00:00
|
|
|
if (foundusr == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-02-11 22:04:02 +00:00
|
|
|
if (foundusr.TimeBanned != -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foundusr.lastActionTimeStamp = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds();
|
|
|
|
await UsersRepository.updateUserAsync(foundusr);
|
|
|
|
int targetID = 0;
|
|
|
|
if (type == "op")
|
|
|
|
{
|
|
|
|
var post = await PostsRepository.getPostByIdAsync(Int32.Parse(id));
|
|
|
|
targetID = post.User.UserID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var comment = await CommentsRepository.getCommentByIdAsync(Int32.Parse(id));
|
|
|
|
targetID = comment.User.UserID;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReportData reportData = new ReportData()
|
|
|
|
{
|
|
|
|
Type = type,
|
|
|
|
ReportedCommentID = type == "op" ? null : Int32.Parse(id),
|
|
|
|
ReportedPostID = type == "op" ? Int32.Parse(id) : null,
|
|
|
|
UserReporterID = foundusr.UserID,
|
|
|
|
UserReportedID = targetID,
|
|
|
|
ReportReason = RulesConv.dict[RulesConv.dict2[selectedItem]],
|
|
|
|
ReportExlaination = explaination
|
|
|
|
};
|
|
|
|
|
2023-02-12 18:06:33 +00:00
|
|
|
List<ReportData> submittedReports = foundusr.RecivedReports;
|
2023-06-12 18:46:44 +00:00
|
|
|
foreach (var r in submittedReports)
|
2023-02-12 18:06:33 +00:00
|
|
|
{
|
|
|
|
if (r.ReportedPostID == reportData.ReportedPostID && r.ReportedCommentID == reportData.ReportedCommentID)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-09 07:45:14 +00:00
|
|
|
await ReportsRepository.createReportAsync(reportData);
|
2023-02-11 22:04:02 +00:00
|
|
|
js.InvokeVoidAsync("window.close");
|
|
|
|
}
|
2023-06-12 18:46:44 +00:00
|
|
|
|
2023-02-03 10:33:56 +00:00
|
|
|
}
|