Added services. Added admin ui. Added delete button
This commit is contained in:
@@ -41,6 +41,7 @@ public class DataContext : DbContext
|
|||||||
public DbSet<AaPanel> AaPanels { get; set; }
|
public DbSet<AaPanel> AaPanels { get; set; }
|
||||||
public DbSet<Website> Websites { get; set; }
|
public DbSet<Website> Websites { get; set; }
|
||||||
public DbSet<DdosAttack> DdosAttacks { get; set; }
|
public DbSet<DdosAttack> DdosAttacks { get; set; }
|
||||||
|
public DbSet<Subscription> Subscriptions { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,5 @@ public class Subscription
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; } = "";
|
public string Name { get; set; } = "";
|
||||||
public string Description { get; set; } = "";
|
public string Description { get; set; } = "";
|
||||||
public string SellPassId { get; set; } = "";
|
public string LimitsJson { get; set; } = "";
|
||||||
public int Duration { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -42,4 +42,10 @@ public class User
|
|||||||
// Date stuff
|
// Date stuff
|
||||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Subscriptions
|
||||||
|
|
||||||
|
public Subscription? CurrentSubscription { get; set; } = null;
|
||||||
|
public DateTime SubscriptionSince { get; set; } = DateTime.Now;
|
||||||
|
public int SubscriptionDuration { get; set; }
|
||||||
}
|
}
|
||||||
1005
Moonlight/App/Database/Migrations/20230403131343_AddedNewSubscriptionData.Designer.cs
generated
Normal file
1005
Moonlight/App/Database/Migrations/20230403131343_AddedNewSubscriptionData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.App.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedNewSubscriptionData : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "CurrentSubscriptionId",
|
||||||
|
table: "Users",
|
||||||
|
type: "int",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "SubscriptionDuration",
|
||||||
|
table: "Users",
|
||||||
|
type: "int",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "SubscriptionSince",
|
||||||
|
table: "Users",
|
||||||
|
type: "datetime(6)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Subscriptions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
Name = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Description = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
LimitsJson = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Subscriptions", x => x.Id);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Users_CurrentSubscriptionId",
|
||||||
|
table: "Users",
|
||||||
|
column: "CurrentSubscriptionId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Users_Subscriptions_CurrentSubscriptionId",
|
||||||
|
table: "Users",
|
||||||
|
column: "CurrentSubscriptionId",
|
||||||
|
principalTable: "Subscriptions",
|
||||||
|
principalColumn: "Id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Users_Subscriptions_CurrentSubscriptionId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Subscriptions");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Users_CurrentSubscriptionId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CurrentSubscriptionId",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SubscriptionDuration",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SubscriptionSince",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -599,6 +599,29 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.ToTable("SharedDomains");
|
b.ToTable("SharedDomains");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.App.Database.Entities.Subscription", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("LimitsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Subscriptions");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b =>
|
modelBuilder.Entity("Moonlight.App.Database.Entities.SupportMessage", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -667,6 +690,9 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.Property<DateTime>("CreatedAt")
|
b.Property<DateTime>("CreatedAt")
|
||||||
.HasColumnType("datetime(6)");
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<int?>("CurrentSubscriptionId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<long>("DiscordId")
|
b.Property<long>("DiscordId")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
@@ -693,6 +719,12 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("SubscriptionDuration")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("SubscriptionSince")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
b.Property<bool>("SupportPending")
|
b.Property<bool>("SupportPending")
|
||||||
.HasColumnType("tinyint(1)");
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
@@ -711,6 +743,8 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CurrentSubscriptionId");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -914,6 +948,15 @@ namespace Moonlight.App.Database.Migrations
|
|||||||
b.Navigation("Sender");
|
b.Navigation("Sender");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.App.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Moonlight.App.Database.Entities.Subscription", "CurrentSubscription")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CurrentSubscriptionId");
|
||||||
|
|
||||||
|
b.Navigation("CurrentSubscription");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Moonlight.App.Database.Entities.Website", b =>
|
modelBuilder.Entity("Moonlight.App.Database.Entities.Website", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel")
|
b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel")
|
||||||
|
|||||||
13
Moonlight/App/Models/Forms/SubscriptionDataModel.cs
Normal file
13
Moonlight/App/Models/Forms/SubscriptionDataModel.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Models.Forms;
|
||||||
|
|
||||||
|
public class SubscriptionDataModel
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "You need to enter a name")]
|
||||||
|
[MaxLength(32, ErrorMessage = "Max lenght for name is 32")]
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to enter a description")]
|
||||||
|
public string Description { get; set; } = "";
|
||||||
|
}
|
||||||
14
Moonlight/App/Models/Misc/SubscriptionLimit.cs
Normal file
14
Moonlight/App/Models/Misc/SubscriptionLimit.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace Moonlight.App.Models.Misc;
|
||||||
|
|
||||||
|
public class SubscriptionLimit
|
||||||
|
{
|
||||||
|
public string Identifier { get; set; } = "";
|
||||||
|
public int Amount { get; set; }
|
||||||
|
public List<LimitOption> Options { get; set; } = new();
|
||||||
|
|
||||||
|
public class LimitOption
|
||||||
|
{
|
||||||
|
public string Key { get; set; } = "";
|
||||||
|
public string Value { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
44
Moonlight/App/Repositories/SubscriptionRepository.cs
Normal file
44
Moonlight/App/Repositories/SubscriptionRepository.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.App.Database;
|
||||||
|
using Moonlight.App.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Repositories;
|
||||||
|
|
||||||
|
public class SubscriptionRepository : IDisposable
|
||||||
|
{
|
||||||
|
private readonly DataContext DataContext;
|
||||||
|
|
||||||
|
public SubscriptionRepository(DataContext dataContext)
|
||||||
|
{
|
||||||
|
DataContext = dataContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<Subscription> Get()
|
||||||
|
{
|
||||||
|
return DataContext.Subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Subscription Add(Subscription subscription)
|
||||||
|
{
|
||||||
|
var x = DataContext.Subscriptions.Add(subscription);
|
||||||
|
DataContext.SaveChanges();
|
||||||
|
return x.Entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(Subscription subscription)
|
||||||
|
{
|
||||||
|
DataContext.Subscriptions.Update(subscription);
|
||||||
|
DataContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(Subscription subscription)
|
||||||
|
{
|
||||||
|
DataContext.Subscriptions.Remove(subscription);
|
||||||
|
DataContext.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
DataContext.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Moonlight/App/Services/SubscriptionAdminService.cs
Normal file
45
Moonlight/App/Services/SubscriptionAdminService.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Moonlight.App.Database.Entities;
|
||||||
|
using Moonlight.App.Models.Misc;
|
||||||
|
using Moonlight.App.Repositories;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Services;
|
||||||
|
|
||||||
|
public class SubscriptionAdminService
|
||||||
|
{
|
||||||
|
private readonly SubscriptionRepository SubscriptionRepository;
|
||||||
|
private readonly OneTimeJwtService OneTimeJwtService;
|
||||||
|
|
||||||
|
public SubscriptionAdminService(OneTimeJwtService oneTimeJwtService, SubscriptionRepository subscriptionRepository)
|
||||||
|
{
|
||||||
|
OneTimeJwtService = oneTimeJwtService;
|
||||||
|
SubscriptionRepository = subscriptionRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<SubscriptionLimit[]> GetLimits(Subscription subscription)
|
||||||
|
{
|
||||||
|
return Task.FromResult(
|
||||||
|
JsonConvert.DeserializeObject<SubscriptionLimit[]>(subscription.LimitsJson)
|
||||||
|
?? Array.Empty<SubscriptionLimit>()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SaveLimits(Subscription subscription, SubscriptionLimit[] limits)
|
||||||
|
{
|
||||||
|
subscription.LimitsJson = JsonConvert.SerializeObject(limits);
|
||||||
|
SubscriptionRepository.Update(subscription);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GenerateCode(Subscription subscription, int duration)
|
||||||
|
{
|
||||||
|
return Task.FromResult(
|
||||||
|
OneTimeJwtService.Generate(data =>
|
||||||
|
{
|
||||||
|
data.Add("subscription", subscription.Id.ToString());
|
||||||
|
data.Add("duration", duration.ToString());
|
||||||
|
}, TimeSpan.FromDays(10324))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
140
Moonlight/App/Services/SubscriptionService.cs
Normal file
140
Moonlight/App/Services/SubscriptionService.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.App.Database.Entities;
|
||||||
|
using Moonlight.App.Exceptions;
|
||||||
|
using Moonlight.App.Models.Misc;
|
||||||
|
using Moonlight.App.Repositories;
|
||||||
|
using Moonlight.App.Services.Sessions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Moonlight.App.Services;
|
||||||
|
|
||||||
|
public class SubscriptionService
|
||||||
|
{
|
||||||
|
private readonly SubscriptionRepository SubscriptionRepository;
|
||||||
|
private readonly OneTimeJwtService OneTimeJwtService;
|
||||||
|
private readonly IdentityService IdentityService;
|
||||||
|
private readonly UserRepository UserRepository;
|
||||||
|
private readonly ConfigService ConfigService;
|
||||||
|
|
||||||
|
public SubscriptionService(
|
||||||
|
SubscriptionRepository subscriptionRepository,
|
||||||
|
OneTimeJwtService oneTimeJwtService,
|
||||||
|
IdentityService identityService,
|
||||||
|
UserRepository userRepository,
|
||||||
|
ConfigService configService)
|
||||||
|
{
|
||||||
|
SubscriptionRepository = subscriptionRepository;
|
||||||
|
OneTimeJwtService = oneTimeJwtService;
|
||||||
|
IdentityService = identityService;
|
||||||
|
UserRepository = userRepository;
|
||||||
|
ConfigService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Subscription?> GetCurrent()
|
||||||
|
{
|
||||||
|
var user = await GetCurrentUser();
|
||||||
|
|
||||||
|
if (user == null || user.CurrentSubscription == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var subscriptionEnd = user.SubscriptionSince.ToUniversalTime().AddDays(user.SubscriptionDuration);
|
||||||
|
|
||||||
|
if (subscriptionEnd > DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
return user.CurrentSubscription;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ApplyCode(string code)
|
||||||
|
{
|
||||||
|
var data = await OneTimeJwtService.Validate(code);
|
||||||
|
|
||||||
|
if (data == null)
|
||||||
|
throw new DisplayException("Invalid or expired subscription code");
|
||||||
|
|
||||||
|
var id = int.Parse(data["subscription"]);
|
||||||
|
var duration = int.Parse(data["duration"]);
|
||||||
|
|
||||||
|
var subscription = SubscriptionRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefault(x => x.Id == id);
|
||||||
|
|
||||||
|
if (subscription == null)
|
||||||
|
throw new DisplayException("The subscription the code is associated with does not exist");
|
||||||
|
|
||||||
|
var user = await GetCurrentUser();
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
throw new DisplayException("Unable to determine current user");
|
||||||
|
|
||||||
|
user.CurrentSubscription = subscription;
|
||||||
|
user.SubscriptionDuration = duration;
|
||||||
|
user.SubscriptionSince = DateTime.UtcNow;
|
||||||
|
|
||||||
|
UserRepository.Update(user);
|
||||||
|
|
||||||
|
await OneTimeJwtService.Revoke(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<SubscriptionLimit> GetLimit(string identifier)
|
||||||
|
{
|
||||||
|
var configSection = ConfigService.GetSection("Moonlight").GetSection("Subscriptions");
|
||||||
|
|
||||||
|
var defaultLimits = configSection.GetValue<SubscriptionLimit[]>("defaultLimits");
|
||||||
|
|
||||||
|
var subscription = await GetCurrent();
|
||||||
|
|
||||||
|
if (subscription == null)
|
||||||
|
{
|
||||||
|
var foundDefault = defaultLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||||
|
|
||||||
|
if (foundDefault != null)
|
||||||
|
return foundDefault;
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Identifier = identifier,
|
||||||
|
Amount = 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var subscriptionLimits =
|
||||||
|
JsonConvert.DeserializeObject<SubscriptionLimit[]>(subscription.LimitsJson)
|
||||||
|
?? Array.Empty<SubscriptionLimit>();
|
||||||
|
|
||||||
|
var foundLimit = subscriptionLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||||
|
|
||||||
|
if (foundLimit != null)
|
||||||
|
return foundLimit;
|
||||||
|
|
||||||
|
var foundDefault = defaultLimits.FirstOrDefault(x => x.Identifier == identifier);
|
||||||
|
|
||||||
|
if (foundDefault != null)
|
||||||
|
return foundDefault;
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Identifier = identifier,
|
||||||
|
Amount = 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<User?> GetCurrentUser()
|
||||||
|
{
|
||||||
|
var user = await IdentityService.Get();
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var userWithData = UserRepository
|
||||||
|
.Get()
|
||||||
|
.Include(x => x.CurrentSubscription)
|
||||||
|
.First(x => x.Id == user.Id);
|
||||||
|
|
||||||
|
return userWithData;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ namespace Moonlight
|
|||||||
builder.Services.AddScoped<AaPanelRepository>();
|
builder.Services.AddScoped<AaPanelRepository>();
|
||||||
builder.Services.AddScoped<WebsiteRepository>();
|
builder.Services.AddScoped<WebsiteRepository>();
|
||||||
builder.Services.AddScoped<DdosAttackRepository>();
|
builder.Services.AddScoped<DdosAttackRepository>();
|
||||||
|
builder.Services.AddScoped<SubscriptionRepository>();
|
||||||
|
|
||||||
builder.Services.AddScoped<AuditLogEntryRepository>();
|
builder.Services.AddScoped<AuditLogEntryRepository>();
|
||||||
builder.Services.AddScoped<ErrorLogEntryRepository>();
|
builder.Services.AddScoped<ErrorLogEntryRepository>();
|
||||||
@@ -94,6 +95,9 @@ namespace Moonlight
|
|||||||
builder.Services.AddScoped<GoogleOAuth2Service>();
|
builder.Services.AddScoped<GoogleOAuth2Service>();
|
||||||
builder.Services.AddScoped<DiscordOAuth2Service>();
|
builder.Services.AddScoped<DiscordOAuth2Service>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<SubscriptionService>();
|
||||||
|
builder.Services.AddScoped<SubscriptionAdminService>();
|
||||||
|
|
||||||
builder.Services.AddSingleton<CleanupService>();
|
builder.Services.AddSingleton<CleanupService>();
|
||||||
|
|
||||||
// Loggers
|
// Loggers
|
||||||
|
|||||||
57
Moonlight/Shared/Components/Forms/DeleteButton.razor
Normal file
57
Moonlight/Shared/Components/Forms/DeleteButton.razor
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
@using Moonlight.App.Services
|
||||||
|
@using Moonlight.App.Services.Interop
|
||||||
|
|
||||||
|
@inject SmartTranslateService SmartTranslateService
|
||||||
|
@inject AlertService AlertService
|
||||||
|
|
||||||
|
@if (!Working)
|
||||||
|
{
|
||||||
|
<button class="btn btn-danger" @onclick="Do">
|
||||||
|
<i class="bx bx-trash"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<button class="btn btn-danger disabled" disabled="">
|
||||||
|
<span class="spinner-border spinner-border-sm align-middle me-2"></span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private bool Working { get; set; } = false;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Func<Task>? OnClick { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool Confirm { get; set; } = false;
|
||||||
|
|
||||||
|
private async Task Do()
|
||||||
|
{
|
||||||
|
Working = true;
|
||||||
|
StateHasChanged();
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
if (Confirm)
|
||||||
|
{
|
||||||
|
var b = await AlertService.YesNo(
|
||||||
|
SmartTranslateService.Translate("Are you sure?"),
|
||||||
|
SmartTranslateService.Translate("Do you really want to delete it?"),
|
||||||
|
SmartTranslateService.Translate("Yes"),
|
||||||
|
SmartTranslateService.Translate("No")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
if(OnClick != null)
|
||||||
|
await OnClick.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Working = false;
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,13 +33,13 @@
|
|||||||
public object Model { get; set; }
|
public object Model { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<EditContext> OnValidSubmit { get; set; }
|
public Func<Task>? OnValidSubmit { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<EditContext> OnInvalidSubmit { get; set; }
|
public Func<Task>? OnInvalidSubmit { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<EditContext> OnSubmit { get; set; }
|
public Func<Task>? OnSubmit { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment ChildContent { get; set; }
|
public RenderFragment ChildContent { get; set; }
|
||||||
@@ -67,8 +67,14 @@
|
|||||||
|
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await InvokeAsync(() => OnValidSubmit.InvokeAsync(context));
|
await InvokeAsync(async () =>
|
||||||
await InvokeAsync(() => OnSubmit.InvokeAsync(context));
|
{
|
||||||
|
if (OnValidSubmit != null)
|
||||||
|
await OnValidSubmit.Invoke();
|
||||||
|
|
||||||
|
if (OnSubmit != null)
|
||||||
|
await OnSubmit.Invoke();
|
||||||
|
});
|
||||||
|
|
||||||
Working = false;
|
Working = false;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
@@ -87,7 +93,10 @@
|
|||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
await OnInvalidSubmit.InvokeAsync(context);
|
if (OnInvalidSubmit != null)
|
||||||
await OnSubmit.InvokeAsync(context);
|
await OnInvalidSubmit.Invoke();
|
||||||
|
|
||||||
|
if (OnSubmit != null)
|
||||||
|
await OnSubmit.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,6 +225,14 @@ else
|
|||||||
<span class="menu-title"><TL>Support</TL></span>
|
<span class="menu-title"><TL>Support</TL></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="menu-item">
|
||||||
|
<a class="menu-link" href="/admin/subscriptions">
|
||||||
|
<span class="menu-icon">
|
||||||
|
<i class="bx bx-credit-card"></i>
|
||||||
|
</span>
|
||||||
|
<span class="menu-title"><TL>Subscriptions</TL></span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="menu-item">
|
<div class="menu-item">
|
||||||
<a class="menu-link" href="/admin/statistics">
|
<a class="menu-link" href="/admin/statistics">
|
||||||
<span class="menu-icon">
|
<span class="menu-icon">
|
||||||
|
|||||||
72
Moonlight/Shared/Views/Admin/Subscriptions/Index.razor
Normal file
72
Moonlight/Shared/Views/Admin/Subscriptions/Index.razor
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
@page "/admin/subscriptions/"
|
||||||
|
@using Moonlight.App.Services
|
||||||
|
@using Moonlight.App.Database.Entities
|
||||||
|
@using Moonlight.App.Repositories
|
||||||
|
@using BlazorTable
|
||||||
|
|
||||||
|
@inject SmartTranslateService SmartTranslateService
|
||||||
|
@inject SubscriptionRepository SubscriptionRepository
|
||||||
|
|
||||||
|
<OnlyAdmin>
|
||||||
|
<div class="card">
|
||||||
|
<LazyLoader @ref="LazyLoader" Load="Load">
|
||||||
|
<div class="card-header border-0 pt-5">
|
||||||
|
<h3 class="card-title align-items-start flex-column">
|
||||||
|
<span class="card-label fw-bold fs-3 mb-1">
|
||||||
|
<TL>Subscriptions</TL>
|
||||||
|
</span>
|
||||||
|
</h3>
|
||||||
|
<div class="card-toolbar">
|
||||||
|
<a href="/admin/subscriptions/new" class="btn btn-sm btn-light-success">
|
||||||
|
<i class="bx bx-credit-card"></i>
|
||||||
|
<TL>New subscription</TL>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<Table TableItem="Subscription" Items="Subscriptions" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted">
|
||||||
|
<Column TableItem="Subscription" Title="@(SmartTranslateService.Translate("Id"))" Field="@(x => x.Id)" Sortable="true" Filterable="true"/>
|
||||||
|
<Column TableItem="Subscription" Title="@(SmartTranslateService.Translate("Name"))" Field="@(x => x.Name)" Sortable="true" Filterable="true"/>
|
||||||
|
<Column TableItem="Subscription" Title="@(SmartTranslateService.Translate("Description"))" Field="@(x => x.Description)" Sortable="true" Filterable="true"/>
|
||||||
|
<Column TableItem="Subscription" Title="@(SmartTranslateService.Translate("Manage"))" Field="@(x => x.Id)" Sortable="false" Filterable="false">
|
||||||
|
<Template>
|
||||||
|
<a href="/admin/subscriptions/edit/@(context.Id)/">
|
||||||
|
<TL>Manage</TL>
|
||||||
|
</a>
|
||||||
|
</Template>
|
||||||
|
</Column>
|
||||||
|
<Column TableItem="Subscription" Title="@(SmartTranslateService.Translate("Manage"))" Field="@(x => x.Id)" Sortable="false" Filterable="false">
|
||||||
|
<Template>
|
||||||
|
<DeleteButton Confirm="true" OnClick="() => Delete(context)" />
|
||||||
|
</Template>
|
||||||
|
</Column>
|
||||||
|
<Pager ShowPageNumber="true" ShowTotalCount="true"/>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</LazyLoader>
|
||||||
|
</div>
|
||||||
|
</OnlyAdmin>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private Subscription[] Subscriptions;
|
||||||
|
private LazyLoader LazyLoader;
|
||||||
|
|
||||||
|
private Task Load(LazyLoader arg)
|
||||||
|
{
|
||||||
|
Subscriptions = SubscriptionRepository
|
||||||
|
.Get()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Delete(Subscription subscription)
|
||||||
|
{
|
||||||
|
SubscriptionRepository.Delete(subscription);
|
||||||
|
|
||||||
|
await LazyLoader.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
137
Moonlight/Shared/Views/Admin/Subscriptions/New.razor
Normal file
137
Moonlight/Shared/Views/Admin/Subscriptions/New.razor
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
@page "/admin/subscriptions/new"
|
||||||
|
@using Moonlight.App.Models.Forms
|
||||||
|
@using Moonlight.App.Models.Misc
|
||||||
|
@using Moonlight.App.Repositories
|
||||||
|
@using Moonlight.App.Services
|
||||||
|
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject SubscriptionRepository SubscriptionRepository
|
||||||
|
@inject SubscriptionAdminService SubscriptionAdminService
|
||||||
|
|
||||||
|
<OnlyAdmin>
|
||||||
|
<div class="card card-body p-10">
|
||||||
|
<SmartForm Model="Model" OnValidSubmit="OnSubmit">
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Name</TL>
|
||||||
|
</label>
|
||||||
|
<div class="input-group mb-5">
|
||||||
|
<InputText @bind-Value="Model.Name" class="form-control"></InputText>
|
||||||
|
</div>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Description</TL>
|
||||||
|
</label>
|
||||||
|
<div class="input-group mb-5">
|
||||||
|
<InputText @bind-Value="Model.Description" class="form-control"></InputText>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
@foreach (var limitPart in Limits.Chunk(3))
|
||||||
|
{
|
||||||
|
<div class="row row-cols-3 mb-5">
|
||||||
|
@foreach (var limit in limitPart)
|
||||||
|
{
|
||||||
|
<div class="col">
|
||||||
|
<div class="card card-body border">
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Identifier</TL>
|
||||||
|
</label>
|
||||||
|
<div class="input-group mb-5">
|
||||||
|
<input @bind="limit.Identifier" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
<label class="form-label">
|
||||||
|
<TL>Amount</TL>
|
||||||
|
</label>
|
||||||
|
<div class="input-group mb-5">
|
||||||
|
<input @bind="limit.Amount" type="number" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="d-flex flex-column mb-15 fv-row">
|
||||||
|
<div class="fs-5 fw-bold form-label mb-3">
|
||||||
|
<TL>Options</TL>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<div class="dataTables_wrapper dt-bootstrap4 no-footer">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table align-middle table-row-dashed fw-semibold fs-6 gy-5 dataTable no-footer">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-start text-muted fw-bold fs-7 text-uppercase gs-0">
|
||||||
|
<th class="pt-0 sorting_disabled">
|
||||||
|
<TL>Key</TL>
|
||||||
|
</th>
|
||||||
|
<th class="pt-0 sorting_disabled">
|
||||||
|
<TL>Value</TL>
|
||||||
|
</th>
|
||||||
|
<th class="pt-0 text-end sorting_disabled">
|
||||||
|
<TL>Remove</TL>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var option in limit.Options)
|
||||||
|
{
|
||||||
|
<tr class="odd">
|
||||||
|
<td>
|
||||||
|
<input @bind="option.Key" type="text" class="form-control form-control-solid">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input @bind="option.Value" type="text" class="form-control form-control-solid">
|
||||||
|
</td>
|
||||||
|
<td class="text-end">
|
||||||
|
<button @onclick="() => limit.Options.Remove(option)" type="button" class="btn btn-icon btn-flex btn-active-light-primary w-30px h-30px me-3" data-kt-action="field_remove">
|
||||||
|
<i class="bx bx-trash"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12 col-md-5 d-flex align-items-center justify-content-center justify-content-md-start"></div>
|
||||||
|
<div class="col-sm-12 col-md-7 d-flex align-items-center justify-content-center justify-content-md-end"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="btn-group mt-5">
|
||||||
|
<button @onclick:preventDefault @onclick="() => limit.Options.Add(new())" type="button" class="btn btn-light-primary me-auto">Add option</button>
|
||||||
|
<button @onclick:preventDefault @onclick="() => Limits.Remove(limit)" class="btn btn-danger float-end">
|
||||||
|
<i class="bx bx-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="float-end">
|
||||||
|
<button @onclick:preventDefault @onclick="() => Limits.Add(new())" class="btn btn-primary">
|
||||||
|
<TL>Add new limit</TL>
|
||||||
|
</button>
|
||||||
|
<button type="submit" class="btn btn-success">
|
||||||
|
<TL>Create subscription</TL>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</SmartForm>
|
||||||
|
</div>
|
||||||
|
</OnlyAdmin>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private SubscriptionDataModel Model = new();
|
||||||
|
private List<SubscriptionLimit> Limits = new();
|
||||||
|
|
||||||
|
private async Task OnSubmit()
|
||||||
|
{
|
||||||
|
var sub = SubscriptionRepository.Add(new()
|
||||||
|
{
|
||||||
|
Name = Model.Name,
|
||||||
|
Description = Model.Description
|
||||||
|
});
|
||||||
|
|
||||||
|
await SubscriptionAdminService.SaveLimits(sub, Limits.ToArray());
|
||||||
|
|
||||||
|
NavigationManager.NavigateTo("/admin/subscriptions");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,8 +87,10 @@
|
|||||||
User = await IdentityService.Get();
|
User = await IdentityService.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Save()
|
private Task Save()
|
||||||
{
|
{
|
||||||
UserRepository.Update(User);
|
UserRepository.Update(User);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -454,3 +454,11 @@ Finish activation;Finish activation
|
|||||||
New password;New password
|
New password;New password
|
||||||
Secure your account;Secure your account
|
Secure your account;Secure your account
|
||||||
2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.;2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.
|
2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.;2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.
|
||||||
|
New subscription;New subscription
|
||||||
|
You need to enter a name;You need to enter a name
|
||||||
|
You need to enter a description;You need to enter a description
|
||||||
|
Add new limit;Add new limit
|
||||||
|
Create subscription;Create subscription
|
||||||
|
Options;Options
|
||||||
|
Amount;Amount
|
||||||
|
Do you really want to delete it?;Do you really want to delete it?
|
||||||
|
|||||||
Reference in New Issue
Block a user