diff --git a/ImageBoardServerApp/App.razor b/ImageBoardServerApp/App.razor index 9a74b62..6e090be 100644 --- a/ImageBoardServerApp/App.razor +++ b/ImageBoardServerApp/App.razor @@ -7,8 +7,10 @@ Not found

404

- noimageFound -

Sorry, there's nothing at this address.

+
+ noimageFound +

Sorry, nothing found. Please go back to the main page. Or watch the tree and find the hidden Cat..

+
\ No newline at end of file diff --git a/ImageBoardServerApp/App.razor.css b/ImageBoardServerApp/App.razor.css new file mode 100644 index 0000000..06c0239 --- /dev/null +++ b/ImageBoardServerApp/App.razor.css @@ -0,0 +1,5 @@ +.Error404{ + text-align: center; + align-items:center; + font-style: italic; +} \ No newline at end of file diff --git a/ImageBoardServerApp/Data/AccountData.cs b/ImageBoardServerApp/Data/AccountData.cs index 868a91e..c12ce39 100644 --- a/ImageBoardServerApp/Data/AccountData.cs +++ b/ImageBoardServerApp/Data/AccountData.cs @@ -15,4 +15,7 @@ public class AccountData [Required] public string Password { get; set; } + + [Required] + public int PermissionInteger { get; set; } } \ No newline at end of file diff --git a/ImageBoardServerApp/Data/Repository/AccountsRepository.cs b/ImageBoardServerApp/Data/Repository/AccountsRepository.cs new file mode 100644 index 0000000..a198f26 --- /dev/null +++ b/ImageBoardServerApp/Data/Repository/AccountsRepository.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore; + +namespace ImageBoardServerApp.Data.Repository; + +public static class AccountsRepository +{ + public static async Task> getAccountsAsync() + { + await using var db = new AppDBContext(); + return await db.Accounts.ToListAsync(); + } + + public static async Task> getAccountsByMailAsync(string email) + { + await using var db = new AppDBContext(); + return await db.Accounts + .Where(acc => acc.Email.Equals(email)) + .ToListAsync(); + } + + public static async Task getAccountByIdAsync(int accountId) + { + await using var db = new AppDBContext(); + return await db.Accounts.FirstOrDefaultAsync(post => post.AccountID == accountId); + } + + public static async Task 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 updateAccountAsync(AccountData accountToUpdate) + { + await using var db = new AppDBContext(); + db.Accounts.Update(accountToUpdate); + return await db.SaveChangesAsync() >= 1; + } + + public static async Task deleteAccountAsync(int postId) + { + await using var db = new AppDBContext(); + AccountData accountToDelete = await getAccountByIdAsync(postId); + db.Remove(accountToDelete); + return await db.SaveChangesAsync() >= 1; + } +} \ No newline at end of file diff --git a/ImageBoardServerApp/ImageBoardServerApp.csproj b/ImageBoardServerApp/ImageBoardServerApp.csproj index 968bf22..ef2c7bc 100644 --- a/ImageBoardServerApp/ImageBoardServerApp.csproj +++ b/ImageBoardServerApp/ImageBoardServerApp.csproj @@ -7,6 +7,7 @@ + all diff --git a/ImageBoardServerApp/Pages/Login.razor b/ImageBoardServerApp/Pages/Login.razor new file mode 100644 index 0000000..3856758 --- /dev/null +++ b/ImageBoardServerApp/Pages/Login.razor @@ -0,0 +1,58 @@ +@page "/Login" +@using ImageBoardServerApp.Data.Repository +

Login

+
+
+
+ + +
+
+ + +
+ +
+ + @if (tried) + { + @if (verified) + { + Verifed! + } + else + { + False login + } + } + else + { + Plz login + } + +
+@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; + } +} \ No newline at end of file