Skip to content

Commit

Permalink
feat:update email for english
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou committed Feb 27, 2025
1 parent 97eb08a commit 7e72a64
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 55 deletions.
128 changes: 73 additions & 55 deletions frontend/desktop/src/services/backend/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,67 +123,85 @@ export const emailSmsReq = async (email: string) => {

const code = Math.floor(Math.random() * 900000 + 100000).toString();
const transporter = getTransporter();
const language = emailConfig.language === 'zh' ? 'zh' : 'en';

const getLocalizedContent = (content: string, subject: string, language: 'zh' | 'en') => {
return `
<!DOCTYPE html>
<html lang="${language}">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${subject}</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #3498db;
}
p {
text-align: center;
}
.verification-code {
font-size: 24px;
color: #333;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
${content}
</div>
</body>
</html>
`;
};
const subjectMap = {
zh: '【sealos】验证码',
en: '【sealos】Verification Code'
} as const;
const htmlMap = {
zh: getLocalizedContent(
`
<h2>尊敬的用户,您正在进行邮箱绑定操作。请输入以下验证码完成验证。</h2>
<p>您的验证码是:</p>
<p class="verification-code">${code}</p>
`,
subjectMap['zh'],
'zh'
),
en: getLocalizedContent(
`
<h2>Dear user, you are currently performing an email binding operation. Please enter the following verification code to complete the verification.</h2>
<p>Your verification code is:</p>
<p class="verification-code">${code}</p>
`,
subjectMap['en'],
'en'
)
} as const;

await retrySerially(
() =>
transporter.sendMail({
from: emailConfig.user,
to: email,
subject: '【sealos】验证码',
html: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>【sealos】验证码</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #3498db;
}
.verification-code {
font-size: 24px;
color: #333;
margin-bottom: 20px;
}
.button {
padding: 10px 20px;
background-color: #3498db;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #2980b9;
}
</style>
</head>
<body>
<div class="container">
<h2>尊敬的用户,您正在进行邮箱绑定操作。请输入以下验证码完成验证。</h2>
<p>您的验证码是:</p>
<p class="verification-code">${code}</p>
</div>
</body>
</html>`
subject: subjectMap[language],
html: htmlMap[language]
}),
3
);
Expand Down
1 change: 1 addition & 0 deletions frontend/desktop/src/types/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export type AuthConfigType = {
port: number;
user: string;
password: string;
language?: string;
};
};
captcha?: {
Expand Down

0 comments on commit 7e72a64

Please sign in to comment.