Lots of Bugfixes (#2356)

This commit is contained in:
Joe Milazzo 2023-10-27 16:18:56 -05:00 committed by GitHub
parent 86e931dd9a
commit 226d6831df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 359 additions and 225 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
@ -27,6 +28,7 @@ public interface IEmailService
Task<bool> IsDefaultEmailService();
Task SendEmailChangeEmail(ConfirmationEmailDto data);
Task<string?> GetVersion(string emailUrl);
bool IsValidEmail(string email);
}
public class EmailService : IEmailService
@ -123,6 +125,11 @@ public class EmailService : IEmailService
return null;
}
public bool IsValidEmail(string email)
{
return new EmailAddressAttribute().IsValid(email);
}
public async Task SendConfirmationEmail(ConfirmationEmailDto data)
{
var emailLink = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.EmailServiceUrl)).Value;
@ -138,8 +145,15 @@ public class EmailService : IEmailService
// This is the only exception for using the default because we need an external service to check if the server is accessible for emails
try
{
if (IsLocalIpAddress(host)) return false;
return await SendEmailWithGet(DefaultApiUrl + "/api/reachable?host=" + host);
if (IsLocalIpAddress(host))
{
_logger.LogDebug("[EmailService] Server is not accessible, using local ip");
return false;
}
var url = DefaultApiUrl + "/api/reachable?host=" + host;
_logger.LogDebug("[EmailService] Checking if this server is accessible for sending an email to: {Url}", url);
return await SendEmailWithGet(url);
}
catch (Exception)
{