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" /> <input type="password" id="password" @bind="Password" />
</div> </div>
<a @onclick="login" href="javascript:void(0)">[Login]</a> <a @onclick="login" href="javascript:void(0)">[Login]</a>
<button @onclick="login" >Login</button>
</form> </form>
</div> </div>

View file

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

View file

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

View file

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