mirror of
https://github.com/Ikatono/ComiServ.git
synced 2025-10-28 20:45:35 -05:00
v1.0 release
This commit is contained in:
@@ -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!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
16
Entities/ComicRead.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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
38
Entities/User.cs
Normal 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
28
Entities/UserType.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user