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();
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)
{

View file

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

View file

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

View file

@ -12,17 +12,19 @@
{
<div class="pd centered">
<span>Comment on @post.Title in /@post.Board/</span>
<FormInfo/>
<div class="centered formContent">
<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">
@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>
<div class="pd centered marg">
@ -36,6 +38,7 @@
</div>
<div class="pd centered marg">
<FormInfo/>
<RadzenButton class="pd" Click="@onPostClick" Text="Comment!"></RadzenButton>
</div>
@ -103,7 +106,21 @@
Banned = false,
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;
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">
<span>Post to /@board.Tag/ - @board.Topic</span>
<div class="pd centered marg">
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
</div>
<div class="centered formContent">
<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">
<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 class="pd centered marg">
<RadzenTextBox Placeholder="Username (Anonymous)" MaxLength="15" Change=@(args => OnChange(args, "username")) Class="w-100"/>
</div>
<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 class="pd centered marg">
<InputFile OnChange="@SingleUpload" type="file" accept="image/*"/>
<FormInfo/>
<RadzenButton class="pd" Click="@onPostClick" Text="Post!"></RadzenButton>
</div>
@ -100,7 +115,21 @@
Banned = false,
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

View file

@ -20,4 +20,21 @@
.marg{
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;
}