prog commit

This commit is contained in:
Albuswolvrick 2023-01-19 13:00:30 +01:00
parent 4aec0f7cf0
commit e65022fa3b
6 changed files with 124 additions and 2 deletions

View file

@ -7,8 +7,10 @@
<PageTitle>Not found</PageTitle> <PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)"> <LayoutView Layout="@typeof(MainLayout)">
<h3>404</h3> <h3>404</h3>
<div class="Error404">
<img src="static/1.jpeg" alt="noimageFound"/> <img src="static/1.jpeg" alt="noimageFound"/>
<p role="alert">Sorry, there's nothing at this address.</p> <p role="alert">Sorry, nothing found. Please go back to the main page. Or watch the tree and find the hidden Cat..</p>
</div>
</LayoutView> </LayoutView>
</NotFound> </NotFound>
</Router> </Router>

View file

@ -0,0 +1,5 @@
.Error404{
text-align: center;
align-items:center;
font-style: italic;
}

View file

@ -15,4 +15,7 @@ public class AccountData
[Required] [Required]
public string Password { get; set; } public string Password { get; set; }
[Required]
public int PermissionInteger { get; set; }
} }

View file

@ -0,0 +1,53 @@
using Microsoft.EntityFrameworkCore;
namespace ImageBoardServerApp.Data.Repository;
public static class AccountsRepository
{
public static async Task<List<AccountData>> getAccountsAsync()
{
await using var db = new AppDBContext();
return await db.Accounts.ToListAsync();
}
public static async Task<List<AccountData>> getAccountsByMailAsync(string email)
{
await using var db = new AppDBContext();
return await db.Accounts
.Where(acc => acc.Email.Equals(email))
.ToListAsync();
}
public static async Task<AccountData> getAccountByIdAsync(int accountId)
{
await using var db = new AppDBContext();
return await db.Accounts.FirstOrDefaultAsync(post => post.AccountID == accountId);
}
public static async Task<int> createAccountAsync(AccountData accountToCreate)
{
await using var db = new AppDBContext();
await db.Accounts.AddAsync(accountToCreate);
if (await db.SaveChangesAsync() >= 1)
{
Console.WriteLine($"Created post with ID: {accountToCreate.AccountID}");
return accountToCreate.AccountID;
}
return -1;
}
public static async Task<bool> updateAccountAsync(AccountData accountToUpdate)
{
await using var db = new AppDBContext();
db.Accounts.Update(accountToUpdate);
return await db.SaveChangesAsync() >= 1;
}
public static async Task<bool> deleteAccountAsync(int postId)
{
await using var db = new AppDBContext();
AccountData accountToDelete = await getAccountByIdAsync(postId);
db.Remove(accountToDelete);
return await db.SaveChangesAsync() >= 1;
}
}

View file

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.13"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.13">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View file

@ -0,0 +1,58 @@
@page "/Login"
@using ImageBoardServerApp.Data.Repository
<h3>Login</h3>
<div>
<form>
<div>
<label for="email">Email:</label>
<input type="email" id="email" @bind="Email" />
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" @bind="Password" />
</div>
<button type="submit" @onclick="SubmitForm">Submit</button>
</form>
@if (tried)
{
@if (verified)
{
<span>Verifed!</span>
}
else
{
<span>False login</span>
}
}
else
{
<span>Plz login</span>
}
</div>
@code {
private string Email { get; set; }
private string Password { get; set; }
private bool verified = false;
private bool tried = false;
private async Task SubmitForm()
{
tried = true;
AccountData target = (await AccountsRepository.getAccountsByMailAsync(Email))[0];
if (target == null)
{
verified = false;
return;
}
verified = BCrypt.Net.BCrypt.Verify(Password, target.Password);
if (verified)
{
verified = true;
return;
}
verified = false;
}
}