2023-01-25 22:45:36 +00:00
|
|
|
@using System.ComponentModel.DataAnnotations
|
2023-02-02 17:50:50 +00:00
|
|
|
@using ImageBoardServerApp.Auth
|
2023-01-25 22:45:36 +00:00
|
|
|
@using ImageBoardServerApp.Data.Repository
|
2023-06-13 17:08:43 +00:00
|
|
|
@using ImageBoardServerApp.Util
|
2023-01-26 12:04:55 +00:00
|
|
|
@inject NavigationManager navigationManager
|
2023-02-01 13:18:36 +00:00
|
|
|
@inject IWebHostEnvironment env
|
2023-02-02 17:50:50 +00:00
|
|
|
@inject AuthenticationStateProvider authStateProvider
|
2023-01-25 22:45:36 +00:00
|
|
|
|
2023-06-07 12:46:39 +00:00
|
|
|
<div class="toggler">
|
2023-01-25 22:45:36 +00:00
|
|
|
<span>[</span>
|
2023-06-07 12:46:39 +00:00
|
|
|
<button onclick="@ToggleOpened">@toggleText</button>
|
2023-01-25 22:45:36 +00:00
|
|
|
<span>]</span>
|
|
|
|
</div>
|
|
|
|
@if (opened)
|
|
|
|
{
|
|
|
|
<div class="pd centered">
|
2023-01-26 08:07:25 +00:00
|
|
|
<span>Comment on @post.Title in /@post.Board/</span>
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-27 20:15:50 +00:00
|
|
|
<div class="centered formContent">
|
|
|
|
<div>
|
|
|
|
<div class="pd centered marg">
|
2023-02-02 17:50:50 +00:00
|
|
|
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" @bind-Value="@postUsername" Class="w-100"/>
|
2023-01-27 20:15:50 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="pd centered marg">
|
2023-06-12 16:51:25 +00:00
|
|
|
<RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
|
2023-01-27 20:15:50 +00:00
|
|
|
</div>
|
2023-06-13 06:51:53 +00:00
|
|
|
<AuthorizeView Roles="Admin,Mod">
|
|
|
|
<Authorized>
|
|
|
|
<RadzenCheckBox @bind-Value=@postAnon Name="postAsAnon"/>
|
|
|
|
<RadzenLabel Text="Do not show role." Component="postAsAnon"/>
|
|
|
|
</Authorized>
|
|
|
|
</AuthorizeView>
|
2023-01-27 20:15:50 +00:00
|
|
|
</div>
|
2023-01-25 22:45:36 +00:00
|
|
|
</div>
|
2023-02-02 21:27:31 +00:00
|
|
|
@if (hasErr)
|
2023-06-12 16:51:25 +00:00
|
|
|
{
|
|
|
|
<span class="postError">@postErr</span>
|
|
|
|
}
|
2023-01-25 22:45:36 +00:00
|
|
|
<div class="pd centered marg">
|
2023-01-27 21:09:16 +00:00
|
|
|
<FormInfo/>
|
2023-02-01 13:18:36 +00:00
|
|
|
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
|
|
|
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
|
2023-01-25 22:45:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
|
|
|
private bool opened = false;
|
|
|
|
|
|
|
|
private string toggleText = "Open Comment Formula";
|
|
|
|
|
|
|
|
private void ToggleOpened()
|
|
|
|
{
|
|
|
|
opened = !opened;
|
|
|
|
toggleText = opened ? "Close Comment Formula" : "Open Comment Formula";
|
|
|
|
}
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Required]
|
|
|
|
public PostData post { get; set; }
|
|
|
|
|
2023-05-31 12:50:05 +00:00
|
|
|
string postUsername { get; set; }
|
2023-02-02 17:50:50 +00:00
|
|
|
string postContent { get; set; } = "";
|
2023-06-13 06:51:53 +00:00
|
|
|
bool postAnon { get; set; } = false;
|
2023-01-25 22:45:36 +00:00
|
|
|
|
2023-06-12 16:51:25 +00:00
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
2023-05-31 12:50:05 +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-05-31 12:50:05 +00:00
|
|
|
if (foundusr == null)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "You are not logged in.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
postUsername = foundusr.LastUsedName;
|
2023-06-13 14:24:38 +00:00
|
|
|
if (!foundusr.ConfirmedEmail)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "You cannot post without an verified email.";
|
|
|
|
return;
|
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
2023-05-31 12:50:05 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 13:18:36 +00:00
|
|
|
private IBrowserFile selectedFile;
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-26 08:07:25 +00:00
|
|
|
private async Task SingleUpload(InputFileChangeEventArgs e)
|
|
|
|
{
|
2023-02-01 13:18:36 +00:00
|
|
|
selectedFile = e.GetMultipleFiles()[0];
|
|
|
|
this.StateHasChanged();
|
2023-01-26 08:07:25 +00:00
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-02-02 21:27:31 +00:00
|
|
|
string postErr { get; set; }
|
|
|
|
bool hasErr { get; set; } = false;
|
2023-01-26 08:07:25 +00:00
|
|
|
|
2023-01-25 22:45:36 +00:00
|
|
|
private async Task onPostClick()
|
|
|
|
{
|
2023-02-02 17:50:50 +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-02 21:27:31 +00:00
|
|
|
if (foundusr == null)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "You are not logged in.";
|
|
|
|
return;
|
|
|
|
}
|
2023-06-13 17:08:43 +00:00
|
|
|
if (!foundusr.ConfirmedEmail)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "You cannot post without an verified email.";
|
|
|
|
return;
|
|
|
|
}
|
2023-02-02 17:50:50 +00:00
|
|
|
int userID = foundusr.UserID;
|
2023-06-13 21:34:16 +00:00
|
|
|
if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned > 0)
|
2023-02-13 20:39:39 +00:00
|
|
|
{
|
|
|
|
foundusr.TimeBanned = -1;
|
|
|
|
}
|
|
|
|
|
2023-02-02 21:27:31 +00:00
|
|
|
if (foundusr.TimeBanned != -1)
|
|
|
|
{
|
2023-06-13 17:08:43 +00:00
|
|
|
var dt = TheManager.ConvertToDateTime(foundusr.TimeBanned);
|
2023-02-02 21:27:31 +00:00
|
|
|
hasErr = true;
|
2023-06-13 21:34:16 +00:00
|
|
|
postErr = "You are banned for \"" + foundusr.BanReason + "\" and may not comment until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second;
|
2023-02-02 17:50:50 +00:00
|
|
|
return;
|
2023-02-02 21:27:31 +00:00
|
|
|
}
|
2023-02-12 16:01:46 +00:00
|
|
|
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
2023-05-31 12:50:05 +00:00
|
|
|
if (postUsername == null || postUsername == "")
|
|
|
|
{
|
|
|
|
postUsername = "Anonymous";
|
|
|
|
}
|
|
|
|
foundusr.LastUsedName = postUsername;
|
2023-02-02 17:50:50 +00:00
|
|
|
await UsersRepository.updateUserAsync(foundusr);
|
2023-01-26 08:07:25 +00:00
|
|
|
|
2023-02-24 23:08:36 +00:00
|
|
|
PostData updatedPost = await PostsRepository.getPostByIdAsync(post.PostID);
|
|
|
|
if (updatedPost.IsLocked)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "This Post is locked.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-04 22:09:26 +00:00
|
|
|
BoardData b = await BoardsRepository.getBoardByTagAsync(post.Board);
|
|
|
|
if (b.isLocked)
|
|
|
|
{
|
|
|
|
hasErr = true;
|
|
|
|
postErr = "This board is currently locked.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-01 13:18:36 +00:00
|
|
|
bool hasImage = selectedFile != null;
|
2023-03-11 01:50:07 +00:00
|
|
|
int thisGET = b.NumberOfGETs + 1;
|
2023-06-13 05:47:49 +00:00
|
|
|
++b.NumberOfGETs;
|
2023-03-11 01:50:07 +00:00
|
|
|
await BoardsRepository.updateBoardAsync(b);
|
2023-01-26 08:07:25 +00:00
|
|
|
CommentData commentToCreate;
|
|
|
|
if (hasImage)
|
2023-01-25 22:45:36 +00:00
|
|
|
{
|
2023-06-13 05:47:49 +00:00
|
|
|
Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 2 * 10); // max 10MB
|
2023-02-01 13:18:36 +00:00
|
|
|
var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1];
|
2023-02-07 20:47:28 +00:00
|
|
|
var path = $"{env.WebRootPath}/img/dynamic/comment/{@post.Board}/{@file}";
|
2023-02-01 13:18:36 +00:00
|
|
|
FileStream fs = File.Create(path);
|
|
|
|
await stream.CopyToAsync(fs);
|
|
|
|
stream.Close();
|
|
|
|
fs.Close();
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-26 08:07:25 +00:00
|
|
|
var imageToUpload = new ImageData
|
|
|
|
{
|
|
|
|
Board = post.Board,
|
2023-02-07 20:47:28 +00:00
|
|
|
ImageLocation = $"/img/dynamic/comment/{@post.Board}/{@file}"
|
2023-01-26 08:07:25 +00:00
|
|
|
};
|
|
|
|
int imageID = await ImagesRepository.createImageAsync(imageToUpload);
|
|
|
|
commentToCreate = new CommentData()
|
|
|
|
{
|
|
|
|
PostID = post.PostID,
|
|
|
|
UserID = userID,
|
|
|
|
ImageID = imageID,
|
|
|
|
Content = postContent,
|
|
|
|
Username = postUsername,
|
|
|
|
Board = post.Board,
|
2023-03-11 01:50:07 +00:00
|
|
|
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
|
2023-06-13 06:51:53 +00:00
|
|
|
GET = thisGET,
|
|
|
|
shouldAnon = postAnon
|
2023-01-26 08:07:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commentToCreate = new CommentData()
|
|
|
|
{
|
|
|
|
PostID = post.PostID,
|
|
|
|
UserID = userID,
|
|
|
|
Content = postContent,
|
|
|
|
Username = postUsername,
|
|
|
|
Board = post.Board,
|
2023-03-11 01:50:07 +00:00
|
|
|
CreatedAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
|
2023-06-13 06:51:53 +00:00
|
|
|
GET = thisGET,
|
|
|
|
shouldAnon = postAnon
|
2023-01-26 08:07:25 +00:00
|
|
|
};
|
|
|
|
}
|
2023-01-26 12:04:55 +00:00
|
|
|
|
2023-01-25 22:45:36 +00:00
|
|
|
int commentId = await CommentsRepository.createCommentAsync(commentToCreate);
|
|
|
|
if (commentId == -1)
|
|
|
|
{
|
2023-06-12 16:51:25 +00:00
|
|
|
//Open comment unsucessfull
|
2023-02-12 16:01:46 +00:00
|
|
|
navigationManager.NavigateTo("/sys/UnSuccessfulPost");
|
2023-02-02 21:27:31 +00:00
|
|
|
hasErr = true;
|
|
|
|
postErr = "There was an error and the comment could not be created. Please notify the admin.";
|
2023-01-25 22:45:36 +00:00
|
|
|
Console.WriteLine("Shit sucks and did not work.");
|
|
|
|
return;
|
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
//comment successfull
|
2023-01-25 22:45:36 +00:00
|
|
|
Console.WriteLine("Post created");
|
2023-01-26 12:04:55 +00:00
|
|
|
navigationManager.NavigateTo($"/{post.Board}/thread/{post.PostID}", true, true);
|
|
|
|
opened = false;
|
2023-01-25 22:45:36 +00:00
|
|
|
}
|
2023-06-12 16:51:25 +00:00
|
|
|
|
2023-01-25 22:45:36 +00:00
|
|
|
}
|