Added temp mail check
This commit is contained in:
parent
8f9508f30b
commit
b75147e4c0
3 changed files with 47 additions and 3 deletions
37
Moonlight/App/Services/Background/TempMailService.cs
Normal file
37
Moonlight/App/Services/Background/TempMailService.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System.Net.Mail;
|
||||
using Moonlight.App.Helpers;
|
||||
|
||||
namespace Moonlight.App.Services.Background;
|
||||
|
||||
public class TempMailService
|
||||
{
|
||||
private string[] Domains = Array.Empty<string>();
|
||||
|
||||
public TempMailService()
|
||||
{
|
||||
Task.Run(Init);
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
{
|
||||
var client = new HttpClient();
|
||||
var text = await client.GetStringAsync("https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf");
|
||||
|
||||
Domains = text
|
||||
.Split("\n")
|
||||
.Select(x => x.Trim())
|
||||
.ToArray();
|
||||
|
||||
Logger.Info($"Fetched {Domains.Length} temp mail domains");
|
||||
}
|
||||
|
||||
public Task<bool> IsTempMail(string mail)
|
||||
{
|
||||
var address = new MailAddress(mail);
|
||||
|
||||
if (Domains.Contains(address.Host))
|
||||
return Task.FromResult(true);
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ using Moonlight.App.Exceptions;
|
|||
using Moonlight.App.Helpers;
|
||||
using Moonlight.App.Models.Misc;
|
||||
using Moonlight.App.Repositories;
|
||||
using Moonlight.App.Services.Background;
|
||||
using Moonlight.App.Services.Mail;
|
||||
using Moonlight.App.Services.Sessions;
|
||||
|
||||
|
@ -19,6 +20,7 @@ public class UserService
|
|||
private readonly IpLocateService IpLocateService;
|
||||
private readonly DateTimeService DateTimeService;
|
||||
private readonly ConfigService ConfigService;
|
||||
private readonly TempMailService TempMailService;
|
||||
|
||||
private readonly string JwtSecret;
|
||||
|
||||
|
@ -29,7 +31,8 @@ public class UserService
|
|||
MailService mailService,
|
||||
IdentityService identityService,
|
||||
IpLocateService ipLocateService,
|
||||
DateTimeService dateTimeService)
|
||||
DateTimeService dateTimeService,
|
||||
TempMailService tempMailService)
|
||||
{
|
||||
UserRepository = userRepository;
|
||||
TotpService = totpService;
|
||||
|
@ -38,6 +41,7 @@ public class UserService
|
|||
IdentityService = identityService;
|
||||
IpLocateService = ipLocateService;
|
||||
DateTimeService = dateTimeService;
|
||||
TempMailService = tempMailService;
|
||||
|
||||
JwtSecret = configService
|
||||
.Get()
|
||||
|
@ -48,6 +52,9 @@ public class UserService
|
|||
{
|
||||
if (ConfigService.Get().Moonlight.Auth.DenyRegister)
|
||||
throw new DisplayException("This operation was disabled");
|
||||
|
||||
if (await TempMailService.IsTempMail(email))
|
||||
throw new DisplayException("This email is blacklisted");
|
||||
|
||||
// Check if the email is already taken
|
||||
var emailTaken = UserRepository.Get().FirstOrDefault(x => x.Email == email) != null;
|
||||
|
|
|
@ -103,8 +103,6 @@ namespace Moonlight
|
|||
}
|
||||
}
|
||||
|
||||
Logger.Info($"Working dir: {Directory.GetCurrentDirectory()}");
|
||||
|
||||
Logger.Info("Running pre-init tasks");
|
||||
var databaseCheckupService = new DatabaseCheckupService(configService);
|
||||
|
||||
|
@ -246,6 +244,7 @@ namespace Moonlight
|
|||
builder.Services.AddSingleton<CleanupService>();
|
||||
builder.Services.AddSingleton<MalwareScanService>();
|
||||
builder.Services.AddSingleton<TelemetryService>();
|
||||
builder.Services.AddSingleton<TempMailService>();
|
||||
|
||||
// Other
|
||||
builder.Services.AddSingleton<MoonlightService>();
|
||||
|
@ -291,6 +290,7 @@ namespace Moonlight
|
|||
_ = app.Services.GetRequiredService<DiscordNotificationService>();
|
||||
_ = app.Services.GetRequiredService<MalwareScanService>();
|
||||
_ = app.Services.GetRequiredService<TelemetryService>();
|
||||
_ = app.Services.GetRequiredService<TempMailService>();
|
||||
|
||||
_ = app.Services.GetRequiredService<MoonlightService>();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue