fix: fixed auth issues
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
766e6054dc
commit
6630b4963e
11 changed files with 308 additions and 243 deletions
|
@ -14,7 +14,7 @@
|
|||
{
|
||||
<div class="pd centered">
|
||||
<span>Comment on @post.Title in /@post.Board/</span>
|
||||
|
||||
|
||||
<div class="centered formContent">
|
||||
<div>
|
||||
<div class="pd centered marg">
|
||||
|
@ -22,14 +22,14 @@
|
|||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
|
||||
<RadzenTextArea Placeholder="Comment..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@if (hasErr)
|
||||
{
|
||||
<span class="postError">@postErr</span>
|
||||
}
|
||||
{
|
||||
<span class="postError">@postErr</span>
|
||||
}
|
||||
<div class="pd centered marg">
|
||||
<FormInfo/>
|
||||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
|
@ -58,7 +58,7 @@
|
|||
string postUsername { get; set; }
|
||||
string postContent { get; set; } = "";
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
|
@ -71,17 +71,17 @@
|
|||
return;
|
||||
}
|
||||
postUsername = foundusr.LastUsedName;
|
||||
await base.OnParametersSetAsync();
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
private IBrowserFile selectedFile;
|
||||
|
||||
|
||||
private async Task SingleUpload(InputFileChangeEventArgs e)
|
||||
{
|
||||
selectedFile = e.GetMultipleFiles()[0];
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
string postErr { get; set; }
|
||||
bool hasErr { get; set; } = false;
|
||||
|
||||
|
@ -107,7 +107,7 @@
|
|||
{
|
||||
hasErr = true;
|
||||
postErr = "You are banned and may not comment.";
|
||||
//Maybe redirect to /banned?
|
||||
//Maybe redirect to /banned?
|
||||
return;
|
||||
}
|
||||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
|
@ -148,7 +148,7 @@
|
|||
await stream.CopyToAsync(fs);
|
||||
stream.Close();
|
||||
fs.Close();
|
||||
|
||||
|
||||
var imageToUpload = new ImageData
|
||||
{
|
||||
Board = post.Board,
|
||||
|
@ -184,16 +184,17 @@
|
|||
int commentId = await CommentsRepository.createCommentAsync(commentToCreate);
|
||||
if (commentId == -1)
|
||||
{
|
||||
//Open comment unsucessfull
|
||||
//Open comment unsucessfull
|
||||
navigationManager.NavigateTo("/sys/UnSuccessfulPost");
|
||||
hasErr = true;
|
||||
postErr = "There was an error and the comment could not be created. Please notify the admin.";
|
||||
Console.WriteLine("Shit sucks and did not work.");
|
||||
return;
|
||||
}
|
||||
//comment successfull
|
||||
//comment successfull
|
||||
Console.WriteLine("Post created");
|
||||
navigationManager.NavigateTo($"/{post.Board}/thread/{post.PostID}", true, true);
|
||||
opened = false;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,15 +17,15 @@
|
|||
<span>Post to /@board.Tag/ - @board.Topic</span>
|
||||
<div class="centered formContent">
|
||||
<div>
|
||||
<div class="pd centered marg">
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" @bind-Value="@postUsername" Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextBox Placeholder="Title" MaxLength="128" @bind-Value="@postTitle" Class="w-100"/>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
|
||||
<div class="pd centered marg">
|
||||
<RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Class="w-100"/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -39,7 +39,7 @@
|
|||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@
|
|||
string postTitle { get; set; } = "";
|
||||
string postContent { get; set; } = "";
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
var user = await cauthStateProvder.GetAuthenticationStateAsync();
|
||||
|
@ -77,13 +77,12 @@
|
|||
return;
|
||||
}
|
||||
postUsername = foundusr.LastUsedName;
|
||||
await base.OnParametersSetAsync();
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
|
||||
private IBrowserFile selectedFile;
|
||||
|
||||
|
||||
|
||||
|
||||
private async Task SingleUpload(InputFileChangeEventArgs e)
|
||||
{
|
||||
selectedFile = e.GetMultipleFiles()[0];
|
||||
|
@ -110,15 +109,15 @@
|
|||
{
|
||||
foundusr.TimeBanned = -1;
|
||||
}
|
||||
|
||||
|
||||
if (foundusr.TimeBanned != -1)
|
||||
{
|
||||
hasErr = true;
|
||||
postErr = "You are banned and may not post.";
|
||||
//Maybe redirect to /banned?
|
||||
//Maybe redirect to /banned?
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BoardData b = await BoardsRepository.getBoardByTagAsync(board.Tag);
|
||||
if (b.isLocked)
|
||||
{
|
||||
|
@ -126,7 +125,7 @@
|
|||
postErr = "This board is currently locked.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
if (postUsername == null || postUsername == "")
|
||||
{
|
||||
|
@ -134,17 +133,17 @@
|
|||
}
|
||||
foundusr.LastUsedName = postUsername;
|
||||
await UsersRepository.updateUserAsync(foundusr);
|
||||
|
||||
|
||||
//TODO Add check if data is image
|
||||
|
||||
|
||||
|
||||
//TODO Add check if data is image
|
||||
|
||||
if (selectedFile == null || selectedFile.Size >= 512000 * 4)
|
||||
{
|
||||
hasErr = true;
|
||||
postErr = "You did not attach a file or the selected file is bigger then the 2MiB file limit.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Stream stream = selectedFile.OpenReadStream(maxAllowedSize: 512000 * 8); // max 4MB
|
||||
var file = Path.GetRandomFileName() + "." + selectedFile.Name.Split(".")[selectedFile.Name.Split(".").Length - 1];
|
||||
var path = $"{env.WebRootPath}/img/dynamic/op/{@board.Tag}/{@file}";
|
||||
|
@ -152,7 +151,7 @@
|
|||
await stream.CopyToAsync(fs);
|
||||
stream.Close();
|
||||
fs.Close();
|
||||
|
||||
|
||||
var imageToUpload = new ImageData
|
||||
{
|
||||
Board = board.Tag,
|
||||
|
@ -163,7 +162,7 @@
|
|||
int thisGET = b.NumberOfGETs + 1;
|
||||
b.NumberOfGETs++;
|
||||
await BoardsRepository.updateBoardAsync(b);
|
||||
|
||||
|
||||
var postToPost = new PostData
|
||||
{
|
||||
UserID = userID,
|
||||
|
@ -181,17 +180,18 @@
|
|||
int postId = await PostsRepository.createPostAsync(postToPost);
|
||||
if (postId != -1)
|
||||
{
|
||||
//Open post successfull
|
||||
//Open post successfull
|
||||
NavigationManager.NavigateTo($"/{board.Tag}/thread/{postId}", true, true);
|
||||
await TheManager.bumpThreads(board);
|
||||
Console.WriteLine("Post created");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Open post unsucessfull
|
||||
//Open post unsucessfull
|
||||
hasErr = true;
|
||||
postErr = "There was an error and the post could not be created. Please notify the admin.";
|
||||
Console.WriteLine("Shit sucks and did not work.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue