feat: added docker stuff, started working on login system
This commit is contained in:
parent
c2d40c172a
commit
7c0cef6f65
15 changed files with 216 additions and 143 deletions
|
@ -1,21 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ImageBoardServerApp.Data;
|
||||
|
||||
public class AccountData
|
||||
{
|
||||
[Required]
|
||||
[DatabaseGenerated((DatabaseGeneratedOption.Identity))]
|
||||
[Key]
|
||||
public int AccountID { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PermissionInteger { get; set; }
|
||||
}
|
|
@ -8,7 +8,6 @@ internal sealed class AppDBContext : DbContext
|
|||
public DbSet<PostData> Posts { get; set; }
|
||||
public DbSet<ImageData> Images { get; set; }
|
||||
public DbSet<CommentData> Comments { get; set; }
|
||||
public DbSet<AccountData> Accounts { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
=> optionsBuilder.UseSqlite("Data Source=./Data/Nils.db");
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -16,10 +16,10 @@ public static class UsersRepository
|
|||
return await db.Users.FirstOrDefaultAsync(user => user.UserID == userId);
|
||||
}
|
||||
|
||||
public static async Task<UserData> getUserByIPAsync(string userIp)
|
||||
public static async Task<UserData> getUserByEmailAsync(string email)
|
||||
{
|
||||
await using var db = new AppDBContext();
|
||||
return await db.Users.FirstOrDefaultAsync(user => user.Ipv4Address == userIp);
|
||||
return await db.Users.FirstOrDefaultAsync(user => user.Email == email);
|
||||
}
|
||||
|
||||
public static async Task<int> createUserAsync(UserData userToCreate)
|
||||
|
|
|
@ -11,12 +11,9 @@ public class UserData
|
|||
[DatabaseGenerated((DatabaseGeneratedOption.Identity))]
|
||||
[Key]
|
||||
public int UserID { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
public string Ipv4Address { get; set; }
|
||||
|
||||
[Required]
|
||||
public bool Banned { get; set; }
|
||||
public long TimeBanned { get; set; }
|
||||
|
||||
[Required]
|
||||
public long lastActionTimeStamp { get; set; }
|
||||
|
@ -24,4 +21,16 @@ public class UserData
|
|||
public List<PostData> Posts { get; set; }
|
||||
|
||||
public List<CommentData> Comments { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PermissionInteger { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Role { get; set; }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue