refactor(SendMailHandler): remove TextToHtml
This commit is contained in:
parent
b5fec7bb46
commit
991943d6bd
@ -1,14 +1,30 @@
|
||||
using OtpNet;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Common.Extensions
|
||||
namespace EnvelopeGenerator.Application.Common.Extensions;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class StringExtension
|
||||
{
|
||||
public static class StringExtension
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="totp"></param>
|
||||
/// <param name="secret"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidTotp(this string totp, string secret)
|
||||
{
|
||||
public static bool IsValidTotp(this string totp, string secret)
|
||||
{
|
||||
var secret_bytes = Base32Encoding.ToBytes(secret);
|
||||
var secret_totp = new Totp(secret_bytes);
|
||||
return secret_totp.VerifyTotp(totp, out _, VerificationWindow.RfcSpecifiedNetworkDelay);
|
||||
}
|
||||
var secret_bytes = Base32Encoding.ToBytes(secret);
|
||||
var secret_totp = new Totp(secret_bytes);
|
||||
return secret_totp.VerifyTotp(totp, out _, VerificationWindow.RfcSpecifiedNetworkDelay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="seperator"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <returns></returns>
|
||||
public static string Join(this IEnumerable<string> values, string seperator) => string.Join(seperator, values);
|
||||
}
|
||||
@ -111,7 +111,7 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
|
||||
var emailOut = new EmailOut
|
||||
{
|
||||
EmailAddress = notification.EmailAddress,
|
||||
EmailBody = TextToHtml(temp.Body),
|
||||
EmailBody = temp.Body,
|
||||
EmailSubj = temp.Subject,
|
||||
AddedWhen = DateTime.UtcNow,
|
||||
AddedWho = DispatcherParams.AddedWho,
|
||||
@ -132,22 +132,4 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
|
||||
text = text.Replace(ph.Key, ph.Value);
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string TextToHtml(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return "";
|
||||
|
||||
// HTML encoding special characters
|
||||
string encoded = System.Net.WebUtility.HtmlEncode(input);
|
||||
|
||||
// Convert tabs to (4 non-breaking spaces)
|
||||
encoded = encoded.Replace("\t", " ");
|
||||
|
||||
// Convert line breaks to <br />
|
||||
encoded = encoded.Replace("\r\n", "<br />"); // Windows
|
||||
encoded = encoded.Replace("\r", "<br />"); // Mac old
|
||||
encoded = encoded.Replace("\n", "<br />"); // Unix/Linux
|
||||
|
||||
return encoded;
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ public class DocSignedNotificationTests : TestBase
|
||||
services.AddTransient<SendSignedMailHandler>();
|
||||
|
||||
// overwrite EmailOutRepository
|
||||
services.AddDbRepository(opt => opt.RegisterEntity<Fake.EGDbContext2Prod, EmailOut>(ctx => ctx.EMailOuts))
|
||||
services.AddDbRepository(opt => opt.RegisterEntity<Fake.EGDbContext2Prod, EmailOut>(ctx => ctx.EMailOuts));
|
||||
}
|
||||
|
||||
public override async Task Setup()
|
||||
|
||||
@ -20,6 +20,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Infrastructure;
|
||||
using EnvelopeGenerator.Application.Common.Extensions;
|
||||
|
||||
namespace EnvelopeGenerator.Tests.Application;
|
||||
|
||||
@ -174,7 +175,7 @@ public static class Extensions
|
||||
public static CreateEnvelopeCommand CreateEnvelopeCommand(this Faker fake, int userId) => new()
|
||||
{
|
||||
Message = fake.Lorem.Paragraph(fake.Random.Number(2, 5)),
|
||||
Title = fake.Lorem.Paragraph(fake.Random.Number(1, 2)),
|
||||
Title = fake.Lorem.Words(fake.Random.Number(3, 4)).Join(" "),
|
||||
UserId = userId,
|
||||
UseSQLExecutor = false
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user