Started on implementing mail sending for store system

This commit is contained in:
Marcel Baumgartner 2023-10-24 16:16:45 +02:00
parent aa150a7a69
commit dae09668b2
4 changed files with 30 additions and 4 deletions

View file

@ -1,4 +1,5 @@
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Store;
using Moonlight.App.Event.Args;
namespace Moonlight.App.Event;
@ -9,4 +10,5 @@ public class Events
public static EventHandler<User> OnUserPasswordChanged;
public static EventHandler<User> OnUserTotpSet;
public static EventHandler<MailVerificationEventArgs> OnUserMailVerify;
public static EventHandler<Service> OnServiceOrdered;
}

View file

@ -1,4 +1,5 @@
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Store;
using Moonlight.App.Event;
namespace Moonlight.App.Services.Background;
@ -12,12 +13,30 @@ public class AutoMailSendService // This service is responsible for sending mail
{
MailService = mailService;
ConfigService = configService;
Events.OnUserRegistered += OnUserRegistered;
Events.OnServiceOrdered += OnServiceOrdered;
}
private async void OnServiceOrdered(object? _, Service service)
{
await MailService.Send(
service.Owner,
"New product ordered",
"serviceOrdered",
service,
service.Product,
service.Owner
);
}
private async void OnUserRegistered(object? _, User user)
{
await MailService.Send(user, $"Welcome {user.Username}", "welcome", user);
await MailService.Send(
user,
$"Welcome {user.Username}",
"welcome",
user
);
}
}

View file

@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Store;
using Moonlight.App.Event;
using Moonlight.App.Exceptions;
using Moonlight.App.Extensions;
using Moonlight.App.Repositories;
using Moonlight.App.Services.ServiceManage;
@ -138,8 +140,12 @@ public class StoreOrderService
}
// Create service
return await serviceService.Admin.Create(u, p,
var service = await serviceService.Admin.Create(u, p,
service => { service.RenewAt = DateTime.UtcNow.AddDays(duration); });
await Events.OnServiceOrdered.InvokeAsync(service);
return service;
}
public Task ValidateRenew(User u, Service s, int durationMultiplier)

View file

@ -19,7 +19,6 @@
<Folder Include="App\Http\Requests\" />
<Folder Include="App\Http\Resources\" />
<Folder Include="storage\logs\" />
<Folder Include="storage\mail\" />
<Folder Include="wwwroot\img\" />
</ItemGroup>