diff --git a/src/GZCTF/Controllers/TeamController.cs b/src/GZCTF/Controllers/TeamController.cs index a042da77f..ec2883222 100644 --- a/src/GZCTF/Controllers/TeamController.cs +++ b/src/GZCTF/Controllers/TeamController.cs @@ -555,7 +555,8 @@ public async Task DeleteTeam(int id, CancellationToken token) await teamRepository.DeleteTeam(team, token); - logger.Log(Program.StaticLocalizer[nameof(Resources.Program.Team_Deleted), team.Name], user, TaskStatus.Success); + logger.Log(Program.StaticLocalizer[nameof(Resources.Program.Team_Deleted), team.Name], user, + TaskStatus.Success); return Ok(); } diff --git a/src/GZCTF/Services/Interface/IMailSender.cs b/src/GZCTF/Services/Interface/IMailSender.cs index 8125933b3..3cce4dc72 100644 --- a/src/GZCTF/Services/Interface/IMailSender.cs +++ b/src/GZCTF/Services/Interface/IMailSender.cs @@ -26,7 +26,8 @@ public interface IMailSender /// 用户新注册的Email /// 确认链接 /// 本地化 - public bool SendConfirmEmailUrl(string? userName, string? email, string? confirmLink, IStringLocalizer localizer); + public bool SendConfirmEmailUrl(string? userName, string? email, string? confirmLink, + IStringLocalizer localizer); /// /// 发送邮箱重置邮件 @@ -35,7 +36,8 @@ public interface IMailSender /// 用户的电子邮件 /// 重置链接 /// 本地化 - public bool SendChangeEmailUrl(string? userName, string? email, string? resetLink, IStringLocalizer localizer); + public bool SendChangeEmailUrl(string? userName, string? email, string? resetLink, + IStringLocalizer localizer); /// /// 发送密码重置邮件 @@ -44,5 +46,6 @@ public interface IMailSender /// 用户的电子邮件 /// 重置链接 /// 本地化 - public bool SendResetPasswordUrl(string? userName, string? email, string? resetLink, IStringLocalizer localizer); + public bool SendResetPasswordUrl(string? userName, string? email, string? resetLink, + IStringLocalizer localizer); } \ No newline at end of file diff --git a/src/GZCTF/Services/MailSender.cs b/src/GZCTF/Services/MailSender.cs index fbe892af3..91d8b1bd8 100644 --- a/src/GZCTF/Services/MailSender.cs +++ b/src/GZCTF/Services/MailSender.cs @@ -14,7 +14,7 @@ public sealed class MailSender : IMailSender, IDisposable { private readonly ConcurrentQueue _mailQueue = new(); private readonly EmailConfig? _options; - private readonly IOptionsSnapshot _globalConfig; + private readonly IOptions _globalConfig; private readonly ILogger _logger; private readonly SmtpClient? _smtpClient; private readonly CancellationTokenSource _cancellationTokenSource = new(); @@ -24,7 +24,7 @@ public sealed class MailSender : IMailSender, IDisposable public MailSender( IOptions options, - IOptionsSnapshot globalConfig, + IOptions globalConfig, ILogger logger) { _globalConfig = globalConfig; @@ -36,7 +36,8 @@ public MailSender( { _smtpClient = new(); _smtpClient.AuthenticationMechanisms.Remove("XOAUTH2"); - Task.Factory.StartNew(MailSenderWorker, _cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); + Task.Factory.StartNew(MailSenderWorker, _cancellationToken, TaskCreationOptions.LongRunning, + TaskScheduler.Default); } } @@ -103,12 +104,14 @@ private async Task MailSenderWorker() { if (!_smtpClient.IsConnected) { - await _smtpClient.ConnectAsync(_options!.Smtp!.Host, _options.Smtp.Port!.Value, cancellationToken: _cancellationToken); + await _smtpClient.ConnectAsync(_options!.Smtp!.Host, _options.Smtp.Port!.Value, + cancellationToken: _cancellationToken); } if (!_smtpClient.IsAuthenticated) { - await _smtpClient.AuthenticateAsync(_options!.UserName, _options.Password, cancellationToken: _cancellationToken); + await _smtpClient.AuthenticateAsync(_options!.UserName, _options.Password, + cancellationToken: _cancellationToken); } while (_mailQueue.TryDequeue(out var content)) @@ -130,16 +133,20 @@ private async Task MailSenderWorker() } } - public bool SendConfirmEmailUrl(string? userName, string? email, string? confirmLink, IStringLocalizer localizer) => + public bool SendConfirmEmailUrl(string? userName, string? email, string? confirmLink, + IStringLocalizer localizer) => SendUrlIfPossible(userName, email, confirmLink, MailType.ConfirmEmail, localizer); - public bool SendChangeEmailUrl(string? userName, string? email, string? resetLink, IStringLocalizer localizer) => + public bool SendChangeEmailUrl(string? userName, string? email, string? resetLink, + IStringLocalizer localizer) => SendUrlIfPossible(userName, email, resetLink, MailType.ChangeEmail, localizer); - public bool SendResetPasswordUrl(string? userName, string? email, string? resetLink, IStringLocalizer localizer) => + public bool SendResetPasswordUrl(string? userName, string? email, string? resetLink, + IStringLocalizer localizer) => SendUrlIfPossible(userName, email, resetLink, MailType.ResetPassword, localizer); - bool SendUrlIfPossible(string? userName, string? email, string? resetLink, MailType type, IStringLocalizer localizer) + bool SendUrlIfPossible(string? userName, string? email, string? resetLink, MailType type, + IStringLocalizer localizer) { if (_smtpClient is null) return false; diff --git a/src/GZCTF/Utils/AsyncManualResetEvent.cs b/src/GZCTF/Utils/AsyncManualResetEvent.cs index 217a17ce9..c5c3ca12b 100644 --- a/src/GZCTF/Utils/AsyncManualResetEvent.cs +++ b/src/GZCTF/Utils/AsyncManualResetEvent.cs @@ -71,4 +71,4 @@ public void Reset() return; } } -} +} \ No newline at end of file