Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Jan 17, 2024
1 parent ef7e515 commit 8a90d04
Showing 1 changed file with 98 additions and 55 deletions.
153 changes: 98 additions & 55 deletions src/Snap.Hutao.Server/Snap.Hutao.Server/Service/MailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,142 +20,185 @@ public MailService(IHttpClientFactory httpClientFactory, AppOptions appOptions,
mailerSecret = appOptions.MailerSecret;
}

public Task SendRegistrationVerifyCodeAsync(string emailAddress, string code, string language = "chs")
public Task SendRegistrationVerifyCodeAsync(string emailAddress, string code, string language = "CHS")
{
logger.LogInformation("Send Registration Mail to [{Email}] with [{Code}] in [{language}]", emailAddress, code, language);
MailOptions options = new()
{
Subject = language == "chs" ? "Snap Hutao 账号安全" : "Snap Hutao Account Security",
Subject = language == "CHS"
? "Snap Hutao 通行证安全"
: "Snap Hutao Passport Security",
Address = emailAddress,
Title = language == "chs" ? "感谢您注册 Snap Hutao 账号" : "Thank you for registering Snap Hutao account",
RawContent = language == "chs" ? $"""
<p>以下是您注册账号所需的验证码:</p>
Title = language == "CHS"
? "感谢您注册 Snap Hutao 通行证"
: "Thank you for registering Snap Hutao Passport",
RawContent = language == "CHS"
? $"""
<p>以下是您注册通行证所需的验证码:</p>
<span class="mail-code">{code}</span>
<p>如果您没有注册账号,请忽略此邮件,不会有任何事情发生。</p>
""" : $"""
<p>Here is the verification code you need for registering your account:</p>
<p>如果您没有注册通行证,请忽略此邮件,不会有任何事情发生。</p>
"""
: $"""
<p>Here is the verification code you need for registering your passport:</p>
<span class="mail-code">{code}</span>
<p>If you did not register an account, please ignore this email, nothing will happen.</p>
<p>If you did not register an passport, please ignore this email, nothing will happen.</p>
""",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


public Task SendResetPasswordVerifyCodeAsync(string emailAddress, string code, string language = "chs")
public Task SendResetPasswordVerifyCodeAsync(string emailAddress, string code, string language = "CHS")
{
logger.LogInformation("Send ResetPassword Mail to [{Email}] with [{Code}]", emailAddress, code);
MailOptions options = new()
{
Subject = language == "chs" ? "Snap Hutao 账号安全" : "Snap Hutao Account Security",
Subject = language == "CHS"
? "Snap Hutao 通行证安全"
: "Snap Hutao Passport Security",
Address = emailAddress,
Title = language == "chs" ? "您正在修改 Snap Hutao 账号密码" : "You are changing your Snap Hutao account password",
RawContent = language == "chs" ? $"""
Title = language == "CHS"
? "您正在修改 Snap Hutao 通行证密码"
: "You are changing your Snap Hutao passport password",
RawContent = language == "CHS"
? $"""
<p>以下是您修改密码所需的验证码:</p>
<span class="mail-code">{code}</span>
<p>如果您没有重置密码,请忽略此邮件,不会有任何事情发生。</p>
""" : $"""
"""
: $"""
<p>The following is the verification code you need to change your password:</p>
<span class="mail-code">{code}</span>
<p>If you did not reset your password, please ignore this email, nothing will happen.</p>
""",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


public Task SendCancelRegistrationVerifyCodeAsync(string emailAddress, string code, string language = "chs")
public Task SendCancelRegistrationVerifyCodeAsync(string emailAddress, string code, string language = "CHS")
{
logger.LogInformation("Send CancelRegistration Mail to [{Email}] with [{Code}]", emailAddress, code);
MailOptions options = new()
{
Subject = language == "chs" ? "Snap Hutao 账号安全" : "Snap Hutao Account Security",
Subject = language == "CHS"
? "Snap Hutao 通行证安全"
: "Snap Hutao Passport Security",
Address = emailAddress,
Title = language == "chs" ? "您正在注销 Snap Hutao 账号" : "You are deleting your Snap Hutao account",
RawContent = language == "chs" ? $"""
<p><b>请注意:注销账号的操作是不可逆的</b></p>
<p>以下是您注销账号所需的验证码:</p>
Title = language == "CHS"
? "您正在注销 Snap Hutao 通行证"
: "You are deleting your Snap Hutao Passport",
RawContent = language == "CHS"
? $"""
<p><b>请注意:注销通行证的操作是不可逆的</b></p>
<p>以下是您注销通行证所需的验证码:</p>
<span class="mail-code">{code}</span>
<p>如果您没有注销账号,请忽略此邮件,不会有任何事情发生。</p>
""" : $"""
<p><b>Please note: The operation of delete your account is not recoverable.</b></p>
<p>The following is the verification code you need to delete your account:</p>
<p>如果您没有注销通行证,请忽略此邮件,不会有任何事情发生。</p>
"""
: $"""
<p><b>Please note: The operation of delete your passport is not recoverable.</b></p>
<p>The following is the verification code you need to delete your passport:</p>
<span class="mail-code">{code}</span>
<p>If you did not delete your account, please ignore this email, nothing will happen.</p>
<p>If you did not delete your passport, please ignore this email, nothing will happen.</p>
""",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


public Task SendPurchaseGachaLogStorageServiceAsync(string emailAddress, string expireAt, string tradeNumber, string language = "chs")
public Task SendPurchaseGachaLogStorageServiceAsync(string emailAddress, string expireAt, string tradeNumber, string language = "CHS")
{
logger.LogInformation("Send GachaLog Mail to [{Email}] with [{Number}]", emailAddress, tradeNumber);
MailOptions options = new()
{
Subject = language == "chs" ? "胡桃云服务" : "Hutao Cloud Service",
Subject = language == "CHS"
? "胡桃云服务"
: "Snap Hutao Cloud Service",
Address = emailAddress,
Title = language == "chs" ? "感谢您购买 Snap Hutao 祈愿记录上传服务" : "Thank you for purchasing Snap Hutao Wish Record Backup Service",
RawContent = language == "chs" ? $"""
Title = language == "CHS"
? "感谢您购买 Snap Hutao 祈愿记录上传服务"
: "Thank you for purchasing Snap Hutao Wish Record Backup Service",
RawContent = language == "CHS"
? $"""
<p>服务有效期至</p>
<span class="mail-code">{expireAt}</span>
<p>请妥善保存此邮件,订单编号:{tradeNumber}</p>
""" : $"""
"""
: $"""
<p>The service is valid until</p>
<span class="mail-code">{expireAt}</span>
<p>Please keep this email safe, order number: {tradeNumber}</p>
""",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


public Task SendOpenSourceLicenseNotificationApprovalAsync(string emailAddress, string language = "chs")
public Task SendOpenSourceLicenseNotificationApprovalAsync(string emailAddress, string language = "CHS")
{
MailOptions options = new()
{
Subject = language == "chs" ? "胡桃开放平台" : "Hutao Open Platform",
Subject = language == "CHS"
? "胡桃开放平台"
: "Snap Hutao Open Platform",
Address = emailAddress,
Title = language == "chs" ? "胡桃开放平台开发者申请" : "Hutao Open Platform Developer Application",
RawContent = language == "chs" ? $"{emailAddress},你的开发者许可申请已经通过" : $"{emailAddress}, your developer license application has been approved",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Title = language == "CHS"
? "胡桃开放平台开发者申请"
: "Snap Hutao Open Platform Developer Application",
RawContent = language == "CHS"
? $"{emailAddress},你的开发者许可申请已经通过"
: $"{emailAddress}, your developer license application has been approved",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


public Task SendApproveOpenSourceLicenseNotificationAsync(string userName, string url, string code, string language = "chs")
public Task SendApproveOpenSourceLicenseNotificationAsync(string userName, string url, string code, string language = "CHS")
{
MailOptions options = new()
{
Subject = language == "chs" ? "胡桃开放平台" : "Hutao Open Platform",
Subject =
language == "CHS"
? "胡桃开放平台"
: "Hutao Open Platform",
Address = smtpOptions.DiagnosticEmailAddress,
Title = language == "chs" ? "胡桃开放平台开发者申请" : "Hutao Open Platform Developer Application",
RawContent = language == "chs" ? $"""
<p>申请账号:{userName}</p>
Title = language == "CHS"
? "胡桃开放平台开发者申请"
: "Snap Hutao Open Platform Developer Application",
RawContent = language == "CHS"
? $"""
<p>申请通行证:{userName}</p>
<p>维护网站:<a href="{url}">{url}</a></p>
<a href="https://homa.snapgenshin.com/Accession/ApproveOpenSourceLicense?userName={userName}&code={code}">批准</a>
""" : $"""
<p>Application account: {userName}</p>
"""
: $"""
<p>Application passport: {userName}</p>
<p>Maintenance website: <a href="{url}">{url}</a></p>
<a href="https://homa.snapgenshin.com/Accession/ApproveOpenSourceLicense?userName={userName}&code={code}">Approve</a>
""",
Footer = language == "chs" ? "该邮件是 DGP-Studio 系统自动发送的,请勿回复" : "This email is automatically sent by the DGP-Studio system, please do not reply",
Footer = language == "CHS"
? "该邮件是 DGP Studio 系统自动发送的,请勿回复"
: "This email is automatically sent by the DGP Studio system, please do not reply",
};

return SendMailAsync(options);
}


private static string ComposeMailBody(MailOptions options)
{
return $$"""
Expand All @@ -164,7 +207,7 @@ private static string ComposeMailBody(MailOptions options)
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DGP-Studio Mail Template</title>
<title>DGP Studio Mail Template</title>
<style>
#mail-table {
margin: auto;
Expand Down Expand Up @@ -248,7 +291,7 @@ private static string ComposeMailBody(MailOptions options)
</div>
<div id="mail-footer">
<span>{{options.Footer}}</span>
<span>&copy; 2023 <a href="https://github.com/DGP-Studio">DGP-Studio</a> | <a href="https://github.com/DGP-Studio/Snap.Hutao">Snap Hutao</a> Dev Team</span>
<span>&copy; 2023 <a href="https://github.com/DGP Studio">DGP Studio</a> | <a href="https://github.com/DGP Studio/Snap.Hutao">Snap Hutao</a> Dev Team</span>
</div>
</div>
</body>
Expand Down

0 comments on commit 8a90d04

Please sign in to comment.