feat: added Error msgs to post screen, removed second login button.
This commit is contained in:
parent
9fa145866a
commit
0e725b065a
4 changed files with 37 additions and 11 deletions
|
@ -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>
|
||||
|
|
|
@ -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/*"/>
|
||||
|
@ -64,15 +67,29 @@
|
|||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
string postErr { get; set; }
|
||||
bool hasErr { get; set; } = false;
|
||||
|
||||
private async Task onPostClick()
|
||||
{
|
||||
var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -38,3 +38,7 @@
|
|||
text-align: left;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.postError{
|
||||
color: #ff191c;
|
||||
}
|
|
@ -37,14 +37,13 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pd centered marg">
|
||||
<FormInfo/>
|
||||
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
|
||||
@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.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue