diff --git a/SharpbinV3.Server/EmailTemplates/Base.html b/SharpbinV3.Server/EmailTemplates/Base.html new file mode 100644 index 0000000..b5bd4a8 --- /dev/null +++ b/SharpbinV3.Server/EmailTemplates/Base.html @@ -0,0 +1,108 @@ + + +
+ + +Hi {{USERNAME}},
+Thank you for signing up for Sharpbin. To complete your registration, please verify your email address by clicking the button below.
+ +If the button doesn't work, you can copy and paste this link into your browser:
+ +This link will expire in 24 hours.
+If you didn't create an account with Sharpbin, you can safely ignore this email.
diff --git a/SharpbinV3.Server/Services/AuthService.cs b/SharpbinV3.Server/Services/AuthService.cs index ac5f2b1..5e09088 100644 --- a/SharpbinV3.Server/Services/AuthService.cs +++ b/SharpbinV3.Server/Services/AuthService.cs @@ -230,11 +230,10 @@ namespace SharpbinV3.Server.Services string token = Utilities.GenerateSecureRandomString(EmailVerificationTokenLength); string tokenHash = Utilities.ComputeSha256(token); - await _email.SendAsync( - user.Email, - "Verify Your Email", - $"{(_appSettings.Https ? "https" : "http")}://{_appSettings.Domain}/verify-email?token={token}" - ); + string verificationUrl = $"{(_appSettings.Https ? "https" : "http")}://{_appSettings.Domain}/verify-email?token={token}"; + string emailBody = EmailTemplates.VerifyEmail(verificationUrl, user.Username); + + await _email.SendAsync(user.Email, "Verify Your Email - Sharpbin", emailBody); var verificationToken = new EmailVerificationToken { TokenHash = tokenHash, diff --git a/SharpbinV3.Server/Services/EmailTemplates.cs b/SharpbinV3.Server/Services/EmailTemplates.cs new file mode 100644 index 0000000..eb48f57 --- /dev/null +++ b/SharpbinV3.Server/Services/EmailTemplates.cs @@ -0,0 +1,41 @@ +using System.Reflection; + +namespace SharpbinV3.Server.Services +{ + public static class EmailTemplates + { + private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); + private static readonly string BaseTemplateName = "SharpbinV3.Server.EmailTemplates.Base.html"; + + private static string LoadEmbeddedResource(string resourceName) + { + using var stream = Assembly.GetManifestResourceStream(resourceName); + if (stream == null) + throw new FileNotFoundException($"Embedded resource not found: {resourceName}"); + + using var reader = new StreamReader(stream); + return reader.ReadToEnd(); + } + + private static string RenderTemplate(string title, string contentTemplate, Dictionary