Started on implementing mail sending for store system
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Moonlight.App.Database.Entities;
|
using Moonlight.App.Database.Entities;
|
||||||
|
using Moonlight.App.Database.Entities.Store;
|
||||||
using Moonlight.App.Event.Args;
|
using Moonlight.App.Event.Args;
|
||||||
|
|
||||||
namespace Moonlight.App.Event;
|
namespace Moonlight.App.Event;
|
||||||
@@ -9,4 +10,5 @@ public class Events
|
|||||||
public static EventHandler<User> OnUserPasswordChanged;
|
public static EventHandler<User> OnUserPasswordChanged;
|
||||||
public static EventHandler<User> OnUserTotpSet;
|
public static EventHandler<User> OnUserTotpSet;
|
||||||
public static EventHandler<MailVerificationEventArgs> OnUserMailVerify;
|
public static EventHandler<MailVerificationEventArgs> OnUserMailVerify;
|
||||||
|
public static EventHandler<Service> OnServiceOrdered;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Moonlight.App.Database.Entities;
|
using Moonlight.App.Database.Entities;
|
||||||
|
using Moonlight.App.Database.Entities.Store;
|
||||||
using Moonlight.App.Event;
|
using Moonlight.App.Event;
|
||||||
|
|
||||||
namespace Moonlight.App.Services.Background;
|
namespace Moonlight.App.Services.Background;
|
||||||
@@ -12,12 +13,30 @@ public class AutoMailSendService // This service is responsible for sending mail
|
|||||||
{
|
{
|
||||||
MailService = mailService;
|
MailService = mailService;
|
||||||
ConfigService = configService;
|
ConfigService = configService;
|
||||||
|
|
||||||
Events.OnUserRegistered += OnUserRegistered;
|
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)
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Moonlight.App.Database.Entities;
|
using Moonlight.App.Database.Entities;
|
||||||
using Moonlight.App.Database.Entities.Store;
|
using Moonlight.App.Database.Entities.Store;
|
||||||
|
using Moonlight.App.Event;
|
||||||
using Moonlight.App.Exceptions;
|
using Moonlight.App.Exceptions;
|
||||||
|
using Moonlight.App.Extensions;
|
||||||
using Moonlight.App.Repositories;
|
using Moonlight.App.Repositories;
|
||||||
using Moonlight.App.Services.ServiceManage;
|
using Moonlight.App.Services.ServiceManage;
|
||||||
|
|
||||||
@@ -138,8 +140,12 @@ public class StoreOrderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create service
|
// Create service
|
||||||
return await serviceService.Admin.Create(u, p,
|
var service = await serviceService.Admin.Create(u, p,
|
||||||
service => { service.RenewAt = DateTime.UtcNow.AddDays(duration); });
|
service => { service.RenewAt = DateTime.UtcNow.AddDays(duration); });
|
||||||
|
|
||||||
|
await Events.OnServiceOrdered.InvokeAsync(service);
|
||||||
|
|
||||||
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task ValidateRenew(User u, Service s, int durationMultiplier)
|
public Task ValidateRenew(User u, Service s, int durationMultiplier)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
<Folder Include="App\Http\Requests\" />
|
<Folder Include="App\Http\Requests\" />
|
||||||
<Folder Include="App\Http\Resources\" />
|
<Folder Include="App\Http\Resources\" />
|
||||||
<Folder Include="storage\logs\" />
|
<Folder Include="storage\logs\" />
|
||||||
<Folder Include="storage\mail\" />
|
|
||||||
<Folder Include="wwwroot\img\" />
|
<Folder Include="wwwroot\img\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user