feat: ban message now shows the ban reason and time when unbanned

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-13 19:08:43 +02:00
parent bc1d632e4c
commit 3abc1ba7ab
4 changed files with 26 additions and 5 deletions

View file

@ -1,6 +1,7 @@
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
@using ImageBoardServerApp.Auth @using ImageBoardServerApp.Auth
@using ImageBoardServerApp.Data.Repository @using ImageBoardServerApp.Data.Repository
@using ImageBoardServerApp.Util
@inject NavigationManager navigationManager @inject NavigationManager navigationManager
@inject IWebHostEnvironment env @inject IWebHostEnvironment env
@inject AuthenticationStateProvider authStateProvider @inject AuthenticationStateProvider authStateProvider
@ -110,6 +111,12 @@
postErr = "You are not logged in."; postErr = "You are not logged in.";
return; return;
} }
if (!foundusr.ConfirmedEmail)
{
hasErr = true;
postErr = "You cannot post without an verified email.";
return;
}
int userID = foundusr.UserID; int userID = foundusr.UserID;
if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0) if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0)
{ {
@ -118,9 +125,9 @@
if (foundusr.TimeBanned != -1) if (foundusr.TimeBanned != -1)
{ {
var dt = TheManager.ConvertToDateTime(foundusr.TimeBanned);
hasErr = true; hasErr = true;
postErr = "You are banned and may not comment."; postErr = "You are banned for " + foundusr.BanReason + " and may not comment until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second;
//Maybe redirect to /banned?
return; return;
} }
foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();

View file

@ -117,6 +117,12 @@
postErr = "You are not logged in."; postErr = "You are not logged in.";
return; return;
} }
if (!foundusr.ConfirmedEmail)
{
hasErr = true;
postErr = "You cannot post without an verified email.";
return;
}
int userID = foundusr.UserID; int userID = foundusr.UserID;
if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0) if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0)
{ {
@ -125,9 +131,9 @@
if (foundusr.TimeBanned != -1) if (foundusr.TimeBanned != -1)
{ {
var dt = TheManager.ConvertToDateTime(foundusr.TimeBanned);
hasErr = true; hasErr = true;
postErr = "You are banned and may not post."; postErr = "You are banned for " + foundusr.BanReason + " and may not post until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second;
//Maybe redirect to /banned?
return; return;
} }

View file

@ -12,8 +12,9 @@
<option value="Admin">Admin</option> <option value="Admin">Admin</option>
</select> </select>
<a onclick="@updateRole()" href="javascript:void(0)">Update Role</a> <a onclick="@updateRole()" href="javascript:void(0)">Update Role</a>
<br/> <span>&emsp;</span>
<a onclick="@unban()" href="javascript:void(0)">Unban (if banned)</a> <a onclick="@unban()" href="javascript:void(0)">Unban (if banned)</a>
<br/>
<span> </span> <span> </span>
<span>@user.Role</span> <span>@user.Role</span>
<br/> <br/>

View file

@ -106,4 +106,11 @@ public class TheManager
return BitConverter.ToString(bytes).Replace("-", "").ToLower(); return BitConverter.ToString(bytes).Replace("-", "").ToLower();
} }
public static DateTime ConvertToDateTime(long timestamp)
{
DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime date = unixEpoch.AddSeconds(timestamp);
return date;
}
} }