Skip to content

Commit

Permalink
Merge pull request #201 from belmirp/aws-ses-implementation
Browse files Browse the repository at this point in the history
AWS SES implementation
  • Loading branch information
caseyswilliams authored Feb 21, 2023
2 parents 20a378f + 394ea9a commit c922aa1
Show file tree
Hide file tree
Showing 34 changed files with 1,405 additions and 422 deletions.
7 changes: 7 additions & 0 deletions UT4MasterServer.Common/Enums/AccountStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace UT4MasterServer.Common.Enums;

public enum AccountStatus
{
PendingActivation = 0,
Active = 1,
}
14 changes: 14 additions & 0 deletions UT4MasterServer.Common/Exceptions/AccountActivationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace UT4MasterServer.Common.Exceptions;

[Serializable]
public sealed class AccountActivationException : Exception
{
public AccountActivationException(string message) : base(message)
{
}

public AccountActivationException(string message, Exception innerException) : base(message, innerException)
{
}
}

13 changes: 13 additions & 0 deletions UT4MasterServer.Common/Exceptions/AccountNotActiveException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace UT4MasterServer.Common.Exceptions;

[Serializable]
public sealed class AccountNotActiveException : Exception
{
public AccountNotActiveException(string message) : base(message)
{
}

public AccountNotActiveException(string message, Exception innerException) : base(message, innerException)
{
}
}
13 changes: 13 additions & 0 deletions UT4MasterServer.Common/Exceptions/AwsSesClientException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace UT4MasterServer.Common.Exceptions;

[Serializable]
public sealed class AwsSesClientException : Exception
{
public AwsSesClientException(string message) : base(message)
{
}

public AwsSesClientException(string message, Exception innerException) : base(message, innerException)
{
}
}
13 changes: 13 additions & 0 deletions UT4MasterServer.Common/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace UT4MasterServer.Common.Exceptions;

[Serializable]
public sealed class NotFoundException : Exception
{
public NotFoundException(string message) : base(message)
{
}

public NotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
}
13 changes: 13 additions & 0 deletions UT4MasterServer.Common/Exceptions/RateLimitExceededException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace UT4MasterServer.Common.Exceptions;

[Serializable]
public sealed class RateLimitExceededException : Exception
{
public RateLimitExceededException(string message) : base(message)
{
}

public RateLimitExceededException(string message, Exception innerException) : base(message, innerException)
{
}
}
9 changes: 9 additions & 0 deletions UT4MasterServer.Models/DTO/Request/SendEmailRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace UT4MasterServer.Models.DTO.Request;

public sealed class SendEmailRequest
{
public string From { get; set; } = string.Empty;
public List<string> To { get; set; } = new();
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
}
14 changes: 14 additions & 0 deletions UT4MasterServer.Models/Database/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public class Account
[BsonElement("Flags")]
public AccountFlags Flags { get; set; } = 0;

[BsonIgnoreIfNull]
public string? ActivationLinkGUID { get; set; }

[BsonIgnoreIfNull]
public DateTime? ActivationLinkExpiration { get; set; }

[BsonIgnoreIfNull]
public string? ResetLinkGUID { get; set; }

[BsonIgnoreIfNull]
public DateTime? ResetLinkExpiration { get; set; }

public AccountStatus Status { get; set; } = AccountStatus.PendingActivation;

[BsonIgnore]
public float Level
{
Expand Down
8 changes: 8 additions & 0 deletions UT4MasterServer.Models/Settings/AWSSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UT4MasterServer.Models.Settings;

public sealed class AWSSettings
{
public string AccessKey { get; set; } = string.Empty;
public string SecretKey { get; set; } = string.Empty;
public string RegionName { get; set; } = string.Empty;
}
15 changes: 15 additions & 0 deletions UT4MasterServer.Models/Settings/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ public sealed class ApplicationSettings
/// </remarks>
public bool AllowPasswordGrantType { get; set; } = false;

/// <summary>
/// Used for URL generation when sending activation link, reset links, etc.
/// </summary>
public string WebsiteScheme { get; set; } = string.Empty;

/// <summary>
/// Used just to redirect users to correct domain when UT4UU is being used.
/// </summary>
public string WebsiteDomain { get; set; } = string.Empty;

/// <summary>
/// Used for URL generation when sending activation link, reset links, etc.
/// </summary>
public int WebsitePort { get; set; } = -1;

/// <summary>
/// File containing a list of trusted proxy servers (one per line).
/// This file is loaded only once when program starts and it add values to <see cref="ProxyServers"/>.
Expand All @@ -30,4 +40,9 @@ public sealed class ApplicationSettings
/// IP addresses of trusted proxy servers.
/// </summary>
public List<string> ProxyServers { get; set; } = new List<string>();

/// <summary>
/// No-reply email that will be used for activation links, reset password links, etc
/// </summary>
public string NoReplyEmail { get; set; } = string.Empty;
}
78 changes: 35 additions & 43 deletions UT4MasterServer.Services/Hosted/ApplicationStartupService.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using UT4MasterServer.Models.Settings;
using UT4MasterServer.Services.Scoped;

namespace UT4MasterServer.Services.Hosted
namespace UT4MasterServer.Services.Hosted;

public sealed class ApplicationStartupService : IHostedService
{
public sealed class ApplicationStartupService : IHostedService
private readonly ILogger<ApplicationStartupService> logger;
private readonly IServiceProvider serviceProvider;

public ApplicationStartupService(ILogger<ApplicationStartupService> logger, IServiceProvider serviceProvider)
{
this.logger = logger;
this.serviceProvider = serviceProvider;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
private readonly ILogger<ApplicationStartupService> logger;
private readonly AccountService accountService;
private readonly StatisticsService statisticsService;
private readonly CloudStorageService cloudStorageService;
private readonly ClientService clientService;
private readonly RatingsService ratingsService;

public ApplicationStartupService(
ILogger<ApplicationStartupService> logger,
ILogger<StatisticsService> statsLogger,
IOptions<ApplicationSettings> settings,
ILogger<CloudStorageService> cloudStorageLogger,
ILogger<RatingsService> ratingsLogger)
{
this.logger = logger;
var db = new DatabaseContext(settings);
accountService = new AccountService(db, settings);
statisticsService = new StatisticsService(statsLogger, db);
cloudStorageService = new CloudStorageService(db, cloudStorageLogger);
clientService = new ClientService(db);
ratingsService = new RatingsService(ratingsLogger, db);
}

public async Task StartAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Configuring MongoDB indexes.");
await accountService.CreateIndexesAsync();
await statisticsService.CreateIndexesAsync();
await ratingsService.CreateIndexesAsync();

logger.LogInformation("Initializing MongoDB CloudStorage.");
await cloudStorageService.EnsureSystemFilesExistAsync();

logger.LogInformation("Initializing MongoDB Clients.");
await clientService.UpdateDefaultClientsAsync();
}

public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
using var scope = serviceProvider.CreateScope();

var accountService = scope.ServiceProvider.GetRequiredService<AccountService>();
var statisticsService = scope.ServiceProvider.GetRequiredService<StatisticsService>();
var ratingsService = scope.ServiceProvider.GetRequiredService<RatingsService>();
var cloudStorageService = scope.ServiceProvider.GetRequiredService<CloudStorageService>();
var clientService = scope.ServiceProvider.GetRequiredService<ClientService>();

logger.LogInformation("Configuring MongoDB indexes.");
await accountService.CreateIndexesAsync();
await statisticsService.CreateIndexesAsync();
await ratingsService.CreateIndexesAsync();

logger.LogInformation("Initializing MongoDB CloudStorage.");
await cloudStorageService.EnsureSystemFilesExistAsync();

logger.LogInformation("Initializing MongoDB Clients.");
await clientService.UpdateDefaultClientsAsync();
}

public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
Loading

0 comments on commit c922aa1

Please sign in to comment.