v1.0 release

This commit is contained in:
Cameron
2024-08-27 03:29:38 -05:00
parent a4403ce17b
commit ef7c3f9dbd
38 changed files with 1172 additions and 73 deletions

View File

@@ -12,6 +12,6 @@ namespace ComiServ.Entities
public int Id { get; set; }
[Required]
public string Name { get; set; } = null!;
public ICollection<ComicAuthor> ComicAuthors = null!;
public ICollection<ComicAuthor> ComicAuthors { get; set; } = null!;
}
}

View File

@@ -24,9 +24,12 @@ namespace ComiServ.Entities
public int PageCount { get; set; }
public long SizeBytes { get; set; }
public long FileXxhash64 { get; set; }
public byte[]? ThumbnailWebp { get; set; }
[InverseProperty("Comic")]
public ICollection<ComicTag> ComicTags { get; set; } = [];
[InverseProperty("Comic")]
public ICollection<ComicAuthor> ComicAuthors { get; set; } = [];
[InverseProperty("Comic")]
public ICollection<ComicRead> ReadBy { get; set; } = [];
}
}

16
Entities/ComicRead.cs Normal file
View File

@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace ComiServ.Entities
{
[PrimaryKey(nameof(UserId), nameof(ComicId))]
[Index(nameof(UserId))]
[Index(nameof(ComicId))]
public class ComicRead
{
public int UserId { get; set; }
public User User { get; set; }
public int ComicId { get; set; }
public Comic Comic { get; set; }
}
}

View File

@@ -11,6 +11,6 @@ namespace ComiServ.Entities
public int Id { get; set; }
[Required]
public string Name { get; set; } = null!;
public ICollection<ComicTag> ComicTags = null!;
public ICollection<ComicTag> ComicTags { get; set; } = null!;
}
}

38
Entities/User.cs Normal file
View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography;
namespace ComiServ.Entities
{
[PrimaryKey(nameof(Id))]
[Index(nameof(Username), IsUnique = true)]
public class User
{
public const int HashLengthBytes = 512 / 8;
public const int SaltLengthBytes = HashLengthBytes;
public int Id { get; set; }
[MaxLength(20)]
public string Username { get; set; }
[MaxLength(SaltLengthBytes)]
public byte[] Salt { get; set; }
[MaxLength(HashLengthBytes)]
public byte[] HashedPassword { get; set; }
public UserType UserType { get; set; }
public UserTypeEnum UserTypeId { get; set; }
[InverseProperty("User")]
public ICollection<ComicRead> ComicsRead { get; set; } = [];
//cryptography should probably be in a different class
public static byte[] MakeSalt()
{
byte[] arr = new byte[SaltLengthBytes];
RandomNumberGenerator.Fill(new Span<byte>(arr));
return arr;
}
public static byte[] Hash(byte[] password, byte[] salt)
{
var salted = salt.Append((byte)':').Concat(password).ToArray();
return SHA512.HashData(salted);
}
}
}

28
Entities/UserType.cs Normal file
View File

@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace ComiServ.Entities
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum UserTypeEnum
{
//important that this is 0 as a safety precaution,
//in case it's accidentally left as default
Invalid = 0,
//can create accounts
Administrator = 1,
//has basic access
User = 2,
//authenticates but does not give access
Restricted = 3,
//refuses to authenticate but maintains records
Disabled = 4,
}
public class UserType
{
public UserTypeEnum Id { get; set; }
[MaxLength(26)]
public string Name { get; set; }
public ICollection<User> Users { get; set; }
}
}