Added event system, soft error handler and added some things from helio
This commit is contained in:
42
Moonlight/App/Database/DataContext.cs
Normal file
42
Moonlight/App/Database/DataContext.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moonlight.App.Database.Entities;
|
||||
using Moonlight.App.Services;
|
||||
|
||||
namespace Moonlight.App.Database;
|
||||
|
||||
public class DataContext : DbContext
|
||||
{
|
||||
private readonly ConfigService ConfigService;
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
public DataContext(ConfigService configService)
|
||||
{
|
||||
ConfigService = configService;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
var config = ConfigService.Get().Database;
|
||||
|
||||
if (config.UseSqlite)
|
||||
optionsBuilder.UseSqlite($"Data Source={config.SqlitePath}");
|
||||
else
|
||||
{
|
||||
var connectionString = $"host={config.Host};" +
|
||||
$"port={config.Port};" +
|
||||
$"database={config.Database};" +
|
||||
$"uid={config.Username};" +
|
||||
$"pwd={config.Password}";
|
||||
|
||||
optionsBuilder.UseMySql(
|
||||
connectionString,
|
||||
ServerVersion.AutoDetect(connectionString),
|
||||
builder => builder.EnableRetryOnFailure(5)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Moonlight/App/Database/Entities/User.cs
Normal file
19
Moonlight/App/Database/Entities/User.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Moonlight.App.Database.Entities;
|
||||
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string? Avatar { get; set; } = null;
|
||||
public string? TotpKey { get; set; } = null;
|
||||
|
||||
// Meta data
|
||||
public string Flags { get; set; } = "";
|
||||
public int Permissions { get; set; } = 0;
|
||||
|
||||
// Timestamps
|
||||
public DateTime TokenValidTimestamp { get; set; } = DateTime.UtcNow.AddMinutes(-10);
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
Reference in New Issue
Block a user