Kaynağa Gözat

🐛fix: Fix the issue where new whitelist email domain names cannot be added in the system settings

Apple\Apple 8 ay önce
ebeveyn
işleme
995c19a997
1 değiştirilmiş dosya ile 34 ekleme ve 0 silme
  1. 34 0
      web/src/components/SystemSetting.js

+ 34 - 0
web/src/components/SystemSetting.js

@@ -81,6 +81,7 @@ const SystemSetting = () => {
   const [showPasswordLoginConfirmModal, setShowPasswordLoginConfirmModal] =
     useState(false);
   const [linuxDOOAuthEnabled, setLinuxDOOAuthEnabled] = useState(false);
+  const [emailToAdd, setEmailToAdd] = useState('');
 
   const getOptions = async () => {
     setLoading(true);
@@ -292,6 +293,29 @@ const SystemSetting = () => {
     }
   };
 
+  const handleAddEmail = () => {
+    if (emailToAdd && emailToAdd.trim() !== '') {
+      const domain = emailToAdd.trim();
+
+      // 验证域名格式
+      const domainRegex = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
+      if (!domainRegex.test(domain)) {
+        showError('邮箱域名格式不正确,请输入有效的域名,如 gmail.com');
+        return;
+      }
+
+      // 检查是否已存在
+      if (emailDomainWhitelist.includes(domain)) {
+        showError('该域名已存在于白名单中');
+        return;
+      }
+
+      setEmailDomainWhitelist([...emailDomainWhitelist, domain]);
+      setEmailToAdd('');
+      showSuccess('已添加到白名单');
+    }
+  };
+
   const submitWeChat = async () => {
     const options = [];
 
@@ -765,6 +789,16 @@ const SystemSetting = () => {
                     placeholder='输入域名后回车'
                     style={{ width: '100%', marginTop: 16 }}
                   />
+                  <Form.Input
+                    placeholder='输入要添加的邮箱域名'
+                    value={emailToAdd}
+                    onChange={(value) => setEmailToAdd(value)}
+                    style={{ marginTop: 16 }}
+                    suffix={
+                      <Button theme="solid" type="primary" onClick={handleAddEmail}>添加</Button>
+                    }
+                    onEnterPress={handleAddEmail}
+                  />
                   <Button
                     onClick={submitEmailDomainWhitelist}
                     style={{ marginTop: 10 }}