Added little note to post / comment form, added some other stuff, which I forgot

This commit is contained in:
limited_dev 2023-01-27 22:09:16 +01:00
parent bdb2d0a0b5
commit c04b9ac6f2
8 changed files with 105 additions and 20 deletions

View file

@ -15,6 +15,12 @@ public static class UsersRepository
await using var db = new AppDBContext(); await using var db = new AppDBContext();
return await db.Users.FirstOrDefaultAsync(user => user.UserID == userId); return await db.Users.FirstOrDefaultAsync(user => user.UserID == userId);
} }
public static async Task<UserData> getUserByIPAsync(string userIp)
{
await using var db = new AppDBContext();
return await db.Users.FirstOrDefaultAsync(user => user.Ipv4Address == userIp);
}
public static async Task<int> createUserAsync(UserData userToCreate) public static async Task<int> createUserAsync(UserData userToCreate)
{ {

View file

@ -19,6 +19,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="wwwroot\dynamic\comment" />
<Folder Include="wwwroot\dynamic\op" />
<Folder Include="wwwroot\static" /> <Folder Include="wwwroot\static" />
</ItemGroup> </ItemGroup>

View file

@ -3,6 +3,7 @@
font-weight: 1000; font-weight: 1000;
/*the text have to be in a biger Pixel number I do not know how to do it */ /*the text have to be in a biger Pixel number I do not know how to do it */
} }
.rules_list{ .rules_list{
text-align:left; text-align:left;
display:block; display:block;

View file

@ -12,17 +12,19 @@
{ {
<div class="pd centered"> <div class="pd centered">
<span>Comment on @post.Title in /@post.Board/</span> <span>Comment on @post.Title in /@post.Board/</span>
<FormInfo/>
<div class="centered formContent"> <div class="centered formContent">
<div> <div>
<div class="pd centered marg"> <div class="pd centered marg">
@if (image != null) @if (image != null)
{ {
<img class="formImage" src="@($"data:image/png;base64,{Convert.ToBase64String(image)}")" alt="No Image"/> <img class="formImage" src="@($"data:image/png;base64,{Convert.ToBase64String(image)}")" alt="No Image"/>
} }
</div> </div>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/> <InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
</div> </div>
<div> <div>
<div class="pd centered marg"> <div class="pd centered marg">
@ -36,6 +38,7 @@
</div> </div>
<div class="pd centered marg"> <div class="pd centered marg">
<FormInfo/>
<RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton> <RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton>
</div> </div>
@ -103,7 +106,21 @@
Banned = false, Banned = false,
lastActionTimeStamp = DateTime.Now.Millisecond lastActionTimeStamp = DateTime.Now.Millisecond
}; };
int userID = await UsersRepository.createUserAsync(userToCreate);
int userID;
UserData foundusr = await UsersRepository.getUserByIPAsync(userToCreate.Ipv4Address);
if (foundusr == null)
{
userID = await UsersRepository.createUserAsync(userToCreate);
}
else
{
userID = foundusr.UserID;
if(foundusr.Banned)
return;
foundusr.lastActionTimeStamp = DateTime.Now.Millisecond;
await UsersRepository.updateUserAsync(foundusr);
}
bool hasImage = image != null; bool hasImage = image != null;
CommentData commentToCreate; CommentData commentToCreate;

View file

@ -0,0 +1,5 @@
<ul class="notesInfo">
<li>The max. image size is 1MB.</li>
<li>Supported file types are: jpeg, png & gif</li>
<li>Read the rules before posting</li>
</ul>

View file

@ -0,0 +1,8 @@
.notesInfo{
font-weight: 60;
display: block;
text-align: center;
font-size: 10px;
color: #c6cfd0;
/*the text sice can stay like it is, if you do not want to change it.*/
}

View file

@ -19,20 +19,35 @@
<div class="pd centered"> <div class="pd centered">
<span>Post to /@board.Tag/ - @board.Topic</span> <span>Post to /@board.Tag/ - @board.Topic</span>
<div class="pd centered marg"> <div class="centered formContent">
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/> <div>
</div> <div class="pd centered marg">
@if (image != null)
{
<img class="formImage" src="@($"data:image/png;base64,{Convert.ToBase64String(image)}")" alt="No Image"/>
}
</div>
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
</div>
<div class="pd centered marg"> <div>
<RadzenTextBox Placeholder="Title" MaxLength="20" Change=@(args => OnChange(args, "title")) Class="w-100"/> <div class="pd centered marg">
</div> <RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
</div>
<div class="pd centered marg">
<RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Change=@(args => OnChange(args, "Content")) Class="w-100"/> <div class="pd centered marg">
<RadzenTextBox Placeholder="Title" MaxLength="20" Change=@(args => OnChange(args, "title")) Class="w-100"/>
</div>
<div class="pd centered marg">
<RadzenTextArea Placeholder="Content..." @bind-Value="@postContent" Cols="30" Rows="6" Change=@(args => OnChange(args, "Content")) Class="w-100"/>
</div>
</div>
</div> </div>
<div class="pd centered marg"> <div class="pd centered marg">
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/> <FormInfo/>
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton> <RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
</div> </div>
@ -100,7 +115,21 @@
Banned = false, Banned = false,
lastActionTimeStamp = DateTime.Now.Millisecond lastActionTimeStamp = DateTime.Now.Millisecond
}; };
int userID = await UsersRepository.createUserAsync(userToCreate);
int userID;
UserData foundusr = await UsersRepository.getUserByIPAsync(userToCreate.Ipv4Address);
if (foundusr == null)
{
userID = await UsersRepository.createUserAsync(userToCreate);
}
else
{
userID = foundusr.UserID;
if(foundusr.Banned)
return;
foundusr.lastActionTimeStamp = DateTime.Now.Millisecond;
await UsersRepository.updateUserAsync(foundusr);
}
//TODO Add check if data is image //TODO Add check if data is image

View file

@ -20,4 +20,21 @@
.marg{ .marg{
margin: 2px margin: 2px
}
.formImage{
margin: 6px;
max-width: 200px;
max-height: 200px;
padding: 5px;
}
.formImage img{
max-width:150px;
width: 100%;
}
.formContent{
text-align: left;
display: flex;
} }