mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat(email): add email verification html templates
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{TITLE}}</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
background-color: #0a0a0a;
|
||||
color: #ffffff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 40px auto;
|
||||
background-color: #171717;
|
||||
border: 2px solid #262626;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
background-color: #171717;
|
||||
padding: 32px 30px;
|
||||
border-bottom: 1px solid #262626;
|
||||
}
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
.content {
|
||||
padding: 32px 30px;
|
||||
}
|
||||
.content h2 {
|
||||
margin: 0 0 20px 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
}
|
||||
.content p {
|
||||
margin: 0 0 16px 0;
|
||||
font-size: 15px;
|
||||
line-height: 1.6;
|
||||
color: #d4d4d4;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 12px 24px;
|
||||
background-color: #404040;
|
||||
color: #ffffff !important;
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
font-size: 15px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.button:hover {
|
||||
background-color: #525252;
|
||||
}
|
||||
.link-box {
|
||||
background-color: #262626;
|
||||
padding: 16px;
|
||||
border-radius: 6px;
|
||||
margin: 16px 0;
|
||||
word-break: break-all;
|
||||
}
|
||||
.link-box a {
|
||||
color: #3b82f6;
|
||||
text-decoration: underline;
|
||||
font-size: 14px;
|
||||
}
|
||||
.footer {
|
||||
padding: 24px 30px;
|
||||
text-align: center;
|
||||
background-color: #0a0a0a;
|
||||
border-top: 1px solid #262626;
|
||||
}
|
||||
.footer p {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 13px;
|
||||
color: #737373;
|
||||
}
|
||||
.footer .brand {
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
font-size: 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Sharpbin</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{CONTENT}}
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p class="brand">Sharpbin</p>
|
||||
<p>This is an automated email. Please do not reply to this message.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,12 @@
|
||||
<h2>Verify Your Email Address</h2>
|
||||
<p>Hi <strong>{{USERNAME}}</strong>,</p>
|
||||
<p>Thank you for signing up for Sharpbin. To complete your registration, please verify your email address by clicking the button below.</p>
|
||||
<p style="text-align: center;">
|
||||
<a href="{{VERIFICATION_URL}}" class="button">Verify Email Address</a>
|
||||
</p>
|
||||
<p>If the button doesn't work, you can copy and paste this link into your browser:</p>
|
||||
<div class="link-box">
|
||||
<a href="{{VERIFICATION_URL}}">{{VERIFICATION_URL}}</a>
|
||||
</div>
|
||||
<p><strong>This link will expire in 24 hours.</strong></p>
|
||||
<p>If you didn't create an account with Sharpbin, you can safely ignore this email.</p>
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string, string> replacements)
|
||||
{
|
||||
var baseTemplate = LoadEmbeddedResource(BaseTemplateName);
|
||||
var content = contentTemplate;
|
||||
|
||||
foreach (var (key, value) in replacements)
|
||||
{
|
||||
content = content.Replace($"{{{{{key}}}}}", value);
|
||||
}
|
||||
|
||||
return baseTemplate.Replace("{{TITLE}}", title).Replace("{{CONTENT}}", content);
|
||||
}
|
||||
|
||||
public static string VerifyEmail(string verificationUrl, string username)
|
||||
{
|
||||
var contentTemplate = LoadEmbeddedResource("SharpbinV3.Server.EmailTemplates.VerifyEmail.html");
|
||||
var replacements = new Dictionary<string, string> { { "USERNAME", username }, { "VERIFICATION_URL", verificationUrl } };
|
||||
|
||||
return RenderTemplate("Verify Your Email", contentTemplate, replacements);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,8 @@
|
||||
<PackageReference Include="Otp.NET" Version="1.4.1" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="EmailTemplates\*.html" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user