feat: added Error msgs to post screen, removed second login button.

This commit is contained in:
limited_dev 2023-02-02 22:27:31 +01:00
parent 9fa145866a
commit 0e725b065a
4 changed files with 37 additions and 11 deletions

View file

@ -18,7 +18,6 @@
<input type="password" id="password" @bind="Password" />
</div>
<a @onclick="login" href="javascript:void(0)">[Login]</a>
<button @onclick="login" >Login</button>
</form>
</div>

View file

@ -27,7 +27,10 @@
</div>
</div>
</div>
@if (hasErr)
{
<span class="postError">@postErr</span>
}
<div class="pd centered marg">
<FormInfo/>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
@ -63,6 +66,9 @@
selectedFile = e.GetMultipleFiles()[0];
this.StateHasChanged();
}
string postErr { get; set; }
bool hasErr { get; set; } = false;
private async Task onPostClick()
{
@ -70,9 +76,20 @@
var user = await cauthStateProvder.GetAuthenticationStateAsync();
var usr = user.User;
UserData foundusr = await UsersRepository.getUserByEmailAsync(usr.Identity.Name);
int userID = foundusr.UserID;
if(foundusr.TimeBanned != -1)
if (foundusr == null)
{
hasErr = true;
postErr = "You are not logged in.";
return;
}
int userID = foundusr.UserID;
if (foundusr.TimeBanned != -1)
{
hasErr = true;
postErr = "You are banned and may not comment.";
//Maybe redirect to /banned?
return;
}
foundusr.lastActionTimeStamp = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds();
await UsersRepository.updateUserAsync(foundusr);
@ -125,6 +142,8 @@
{
//Open comment unsucessfull
navigationManager.NavigateTo("/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;
}

View file

@ -37,4 +37,8 @@
.formContent{
text-align: left;
display: flex;
}
.postError{
color: #ff191c;
}

View file

@ -37,14 +37,13 @@
</div>
</div>
</div>
<div class="pd centered marg">
<FormInfo/>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
@if (hasErr)
@if (hasErr)
{
<span class="postError">@postErr</span>
}
<div class="pd centered marg">
<FormInfo/>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
</div>
@ -101,7 +100,9 @@
int userID = foundusr.UserID;
if (foundusr.TimeBanned != -1)
{
hasErr = true;
postErr = "You are banned and may not post.";
//Maybe redirect to /banned?
return;
}
foundusr.lastActionTimeStamp = DateTimeOffset.UnixEpoch.ToUnixTimeMilliseconds();
@ -112,6 +113,8 @@
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;
}
@ -150,7 +153,8 @@
else
{
//Open post unsucessfull
NavigationManager.NavigateTo("/UnSuccessfulPost");
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.");
}
}