diff --git a/core/__pycache__/__init__.cpython-313.pyc b/core/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 41b87f7..0000000 Binary files a/core/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/admin.cpython-313.pyc b/core/__pycache__/admin.cpython-313.pyc deleted file mode 100644 index c12fd79..0000000 Binary files a/core/__pycache__/admin.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/apps.cpython-313.pyc b/core/__pycache__/apps.cpython-313.pyc deleted file mode 100644 index 64e1f81..0000000 Binary files a/core/__pycache__/apps.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/forms.cpython-313.pyc b/core/__pycache__/forms.cpython-313.pyc deleted file mode 100644 index bf01b5a..0000000 Binary files a/core/__pycache__/forms.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/models.cpython-313.pyc b/core/__pycache__/models.cpython-313.pyc deleted file mode 100644 index 5403959..0000000 Binary files a/core/__pycache__/models.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/urls.cpython-313.pyc b/core/__pycache__/urls.cpython-313.pyc deleted file mode 100644 index 613685e..0000000 Binary files a/core/__pycache__/urls.cpython-313.pyc and /dev/null differ diff --git a/core/__pycache__/views.cpython-313.pyc b/core/__pycache__/views.cpython-313.pyc deleted file mode 100644 index af19e40..0000000 Binary files a/core/__pycache__/views.cpython-313.pyc and /dev/null differ diff --git a/core/forms.py b/core/forms.py index 069d23b..1cb716e 100644 --- a/core/forms.py +++ b/core/forms.py @@ -1,3 +1,4 @@ +import re from django import forms from django.utils import timezone from .models import ( @@ -60,6 +61,7 @@ class TodayPlanForm(forms.ModelForm): class SystemConfigForm(forms.ModelForm): """系统配置表单""" + class Meta: model = SystemConfig fields = ['smtp_server', 'smtp_port', 'smtp_username', 'smtp_password', 'sender_email', 'send_time', 'recipient_email'] @@ -71,4 +73,22 @@ class SystemConfigForm(forms.ModelForm): 'sender_email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': '请输入发件人邮箱'}), 'send_time': forms.TimeInput(attrs={'type': 'time', 'class': 'form-control'}), 'recipient_email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': '请输入收件人邮箱'}), - } \ No newline at end of file + } + + def clean_sender_email(self): + sender_email = self.cleaned_data.get('sender_email') + if sender_email: + email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' + if not re.match(email_pattern, sender_email): + logger.warning(f"发件人邮箱格式不正确: {sender_email}") + raise forms.ValidationError("请输入有效的邮箱地址,格式如:example@domain.com") + return sender_email + + def clean_recipient_email(self): + recipient_email = self.cleaned_data.get('recipient_email') + if recipient_email: + email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' + if not re.match(email_pattern, recipient_email): + logger.warning(f"收件人邮箱格式不正确: {recipient_email}") + raise forms.ValidationError("请输入有效的邮箱地址,格式如:example@domain.com") + return recipient_email \ No newline at end of file diff --git a/core/management/commands/__pycache__/create_superuser.cpython-313.pyc b/core/management/commands/__pycache__/create_superuser.cpython-313.pyc deleted file mode 100644 index 70864a0..0000000 Binary files a/core/management/commands/__pycache__/create_superuser.cpython-313.pyc and /dev/null differ diff --git a/core/migrations/0004_systemconfig_sender_email.py b/core/migrations/0004_systemconfig_sender_email.py new file mode 100644 index 0000000..2baaa1a --- /dev/null +++ b/core/migrations/0004_systemconfig_sender_email.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.4 on 2026-01-18 10:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_readingrecord_note'), + ] + + operations = [ + migrations.AddField( + model_name='systemconfig', + name='sender_email', + field=models.EmailField(blank=True, max_length=254, null=True, verbose_name='发件人邮箱'), + ), + ] diff --git a/core/migrations/__pycache__/0001_initial.cpython-313.pyc b/core/migrations/__pycache__/0001_initial.cpython-313.pyc deleted file mode 100644 index f09bb60..0000000 Binary files a/core/migrations/__pycache__/0001_initial.cpython-313.pyc and /dev/null differ diff --git a/core/migrations/__pycache__/__init__.cpython-313.pyc b/core/migrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 3bed523..0000000 Binary files a/core/migrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/core/tests.py b/core/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/core/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/diary_family/__pycache__/__init__.cpython-313.pyc b/diary_family/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 0f30c28..0000000 Binary files a/diary_family/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/diary_family/__pycache__/celery.cpython-313.pyc b/diary_family/__pycache__/celery.cpython-313.pyc deleted file mode 100644 index bc24489..0000000 Binary files a/diary_family/__pycache__/celery.cpython-313.pyc and /dev/null differ diff --git a/diary_family/__pycache__/settings.cpython-313.pyc b/diary_family/__pycache__/settings.cpython-313.pyc deleted file mode 100644 index c0902c7..0000000 Binary files a/diary_family/__pycache__/settings.cpython-313.pyc and /dev/null differ diff --git a/diary_family/__pycache__/urls.cpython-313.pyc b/diary_family/__pycache__/urls.cpython-313.pyc deleted file mode 100644 index b18c621..0000000 Binary files a/diary_family/__pycache__/urls.cpython-313.pyc and /dev/null differ diff --git a/diary_family/__pycache__/wsgi.cpython-313.pyc b/diary_family/__pycache__/wsgi.cpython-313.pyc deleted file mode 100644 index 6347f45..0000000 Binary files a/diary_family/__pycache__/wsgi.cpython-313.pyc and /dev/null differ diff --git a/logs/app.log b/logs/app.log deleted file mode 100644 index 9859101..0000000 --- a/logs/app.log +++ /dev/null @@ -1,142 +0,0 @@ -2026-01-18 16:23:51.077 | INFO | __main__:test_email_config:39 - 邮件配置信息: -2026-01-18 16:23:51.092 | WARNING | __main__:test_email_config:42 - smtp_server: 未配置 -2026-01-18 16:23:51.093 | INFO | __main__:test_email_config:44 - smtp_port: 587 -2026-01-18 16:23:51.093 | WARNING | __main__:test_email_config:42 - smtp_username: 未配置 -2026-01-18 16:23:51.093 | WARNING | __main__:test_email_config:42 - smtp_password: 未配置 -2026-01-18 16:23:51.093 | WARNING | __main__:test_email_config:42 - recipient_email: 未配置 -2026-01-18 16:23:51.094 | INFO | __main__:test_email_config:44 - send_time: 08:00 -2026-01-18 16:23:51.094 | ERROR | __main__:test_email_config:54 - 缺少必要的邮件配置: smtp_server, smtp_username, smtp_password -2026-01-18 16:23:51.094 | INFO | __main__:test_email_config:55 - 请在系统配置页面配置以下参数: -2026-01-18 16:23:51.094 | INFO | __main__:test_email_config:56 - - SMTP服务器: SMTP服务器地址 -2026-01-18 16:23:51.095 | INFO | __main__:test_email_config:57 - - SMTP端口: SMTP端口(通常是587或465) -2026-01-18 16:23:51.095 | INFO | __main__:test_email_config:58 - - SMTP用户名: 发件邮箱 -2026-01-18 16:23:51.095 | INFO | __main__:test_email_config:59 - - SMTP密码: 发件邮箱密码 -2026-01-18 16:23:51.095 | INFO | __main__:main:510 - -[测试2] SMTP连接测试 -2026-01-18 16:23:51.095 | INFO | __main__:test_smtp_connection:72 - 开始测试SMTP连接... -2026-01-18 16:23:51.118 | INFO | __main__:test_smtp_connection:92 - 连接SMTP服务器: localhost:587 -2026-01-18 16:23:51.119 | INFO | __main__:test_smtp_connection:93 - 使用TLS: True, 使用SSL: False -2026-01-18 16:23:51.119 | INFO | __main__:test_smtp_connection:108 - 正在建立SMTP连接... -2026-01-18 16:23:56.491 | ERROR | __main__:test_smtp_connection:131 - SMTP连接测试失败: [WinError 10061] 由于目标计算机积极拒绝,无法连接。 -2026-01-18 16:23:56.492 | ERROR | __main__:test_smtp_connection:171 - 请检查: -2026-01-18 16:23:56.493 | ERROR | __main__:test_smtp_connection:172 - 1. SMTP服务器配置是否正确 -2026-01-18 16:23:56.494 | ERROR | __main__:test_smtp_connection:173 - 2. 邮箱账号和密码是否正确 -2026-01-18 16:23:56.494 | ERROR | __main__:test_smtp_connection:174 - 3. 网络连接是否正常 -2026-01-18 16:23:56.495 | ERROR | __main__:test_smtp_connection:175 - 4. 防火墙是否允许出站连接 -2026-01-18 16:23:56.496 | INFO | __main__:main:515 - -[测试3] 发送简单文本邮件 -2026-01-18 16:23:56.496 | INFO | __main__:test_send_simple_email:182 - 开始测试发送简单邮件... -2026-01-18 16:23:56.502 | ERROR | __main__:test_send_simple_email:198 - 未配置发件邮箱 (smtp_username) -2026-01-18 16:23:56.503 | INFO | __main__:main:520 - -[测试4] 发送HTML邮件(带附件) -2026-01-18 16:23:56.503 | INFO | __main__:test_send_html_email_with_attachment:288 - 开始测试发送HTML邮件(带附件)... -2026-01-18 16:23:56.506 | ERROR | __main__:test_send_html_email_with_attachment:304 - 未配置发件邮箱 -2026-01-18 16:23:56.507 | INFO | __main__:main:525 - -[测试5] 邮件发送性能测试 -2026-01-18 16:23:56.508 | INFO | __main__:test_email_performance:398 - 开始测试邮件发送性能... -2026-01-18 16:23:56.510 | ERROR | __main__:test_email_performance:415 - 未配置发件邮箱 -2026-01-18 16:23:56.511 | INFO | __main__:main:530 - -============================================================ -2026-01-18 16:23:56.511 | INFO | __main__:main:531 - 测试总结: -2026-01-18 16:23:56.511 | INFO | __main__:main:532 - 通过测试: 0/5 -2026-01-18 16:23:56.512 | INFO | __main__:main:533 - ============================================================ -2026-01-18 16:23:56.512 | ERROR | __main__:main:556 - 多数测试失败,邮件系统无法正常工作。 -2026-01-18 16:23:56.512 | INFO | __main__:main:557 - -紧急处理: -2026-01-18 16:23:56.512 | INFO | __main__:main:558 - 1. ❌ 检查SMTP服务器配置 -2026-01-18 16:23:56.512 | INFO | __main__:main:559 - 2. ❌ 验证邮箱账号和密码 -2026-01-18 16:23:56.513 | INFO | __main__:main:560 - 3. ❌ 检查网络连接 -2026-01-18 16:23:56.513 | INFO | __main__:main:561 - 4. 参考README中的邮件配置章节 -2026-01-18 16:23:56.513 | INFO | __main__:main:562 - 5. 查看详细错误日志 -2026-01-18 18:02:52.470 | INFO | __main__:test_email_config:39 - 邮件配置信息: -2026-01-18 18:02:52.471 | WARNING | __main__:test_email_config:42 - smtp_server: 未配置 -2026-01-18 18:02:52.471 | INFO | __main__:test_email_config:44 - smtp_port: 587 -2026-01-18 18:02:52.471 | WARNING | __main__:test_email_config:42 - smtp_username: 未配置 -2026-01-18 18:02:52.471 | WARNING | __main__:test_email_config:42 - smtp_password: 未配置 -2026-01-18 18:02:52.472 | WARNING | __main__:test_email_config:42 - recipient_email: 未配置 -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:44 - send_time: 08:00:00 -2026-01-18 18:02:52.472 | ERROR | __main__:test_email_config:54 - 缺少必要的邮件配置: smtp_server, smtp_username, smtp_password -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:55 - 请在系统配置页面配置以下参数: -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:56 - - SMTP服务器: SMTP服务器地址 -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:57 - - SMTP端口: SMTP端口(通常是587或465) -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:58 - - SMTP用户名: 发件邮箱 -2026-01-18 18:02:52.472 | INFO | __main__:test_email_config:59 - - SMTP密码: 发件邮箱密码 -2026-01-18 18:02:52.472 | INFO | __main__:main:551 - -[测试2] SMTP连接测试 -2026-01-18 18:02:52.472 | INFO | __main__:test_smtp_connection:72 - 开始测试SMTP连接... -2026-01-18 18:02:52.475 | INFO | __main__:test_smtp_connection:92 - 连接SMTP服务器: localhost:587 -2026-01-18 18:02:52.475 | INFO | __main__:test_smtp_connection:93 - 使用TLS: True, 使用SSL: False -2026-01-18 18:02:52.475 | INFO | __main__:test_smtp_connection:108 - 正在建立SMTP连接... -2026-01-18 18:02:57.860 | ERROR | __main__:test_smtp_connection:131 - SMTP连接测试失败: [WinError 10061] 由于目标计算机积极拒绝,无法连接。 -2026-01-18 18:02:57.861 | ERROR | __main__:test_smtp_connection:171 - 请检查: -2026-01-18 18:02:57.861 | ERROR | __main__:test_smtp_connection:172 - 1. SMTP服务器配置是否正确 -2026-01-18 18:02:57.862 | ERROR | __main__:test_smtp_connection:173 - 2. 邮箱账号和密码是否正确 -2026-01-18 18:02:57.862 | ERROR | __main__:test_smtp_connection:174 - 3. 网络连接是否正常 -2026-01-18 18:02:57.863 | ERROR | __main__:test_smtp_connection:175 - 4. 防火墙是否允许出站连接 -2026-01-18 18:02:57.863 | INFO | __main__:main:556 - -[测试3] 发送简单文本邮件 -2026-01-18 18:02:57.864 | INFO | __main__:test_send_simple_email:182 - 开始测试发送简单邮件... -2026-01-18 18:02:57.865 | ERROR | __main__:test_send_simple_email:198 - 未配置发件邮箱 (smtp_username) -2026-01-18 18:02:57.866 | INFO | __main__:main:561 - -[测试4] 发送HTML邮件(带附件) -2026-01-18 18:02:57.866 | INFO | __main__:test_send_html_email_with_attachment:301 - 开始测试发送HTML邮件(带附件)... -2026-01-18 18:02:57.868 | ERROR | __main__:test_send_html_email_with_attachment:317 - 未配置发件邮箱 -2026-01-18 18:02:57.869 | INFO | __main__:main:566 - -[测试5] 邮件发送性能测试 -2026-01-18 18:02:57.869 | INFO | __main__:test_email_performance:425 - 开始测试邮件发送性能... -2026-01-18 18:02:57.871 | ERROR | __main__:test_email_performance:442 - 未配置发件邮箱 -2026-01-18 18:02:57.871 | INFO | __main__:main:571 - -============================================================ -2026-01-18 18:02:57.872 | INFO | __main__:main:572 - 测试总结: -2026-01-18 18:02:57.872 | INFO | __main__:main:573 - 通过测试: 0/5 -2026-01-18 18:02:57.872 | INFO | __main__:main:574 - ============================================================ -2026-01-18 18:02:57.873 | ERROR | __main__:main:597 - 多数测试失败,邮件系统无法正常工作。 -2026-01-18 18:02:57.873 | INFO | __main__:main:598 - -紧急处理: -2026-01-18 18:02:57.873 | INFO | __main__:main:599 - 1. ❌ 检查SMTP服务器配置 -2026-01-18 18:02:57.873 | INFO | __main__:main:600 - 2. ❌ 验证邮箱账号和密码 -2026-01-18 18:02:57.874 | INFO | __main__:main:601 - 3. ❌ 检查网络连接 -2026-01-18 18:02:57.874 | INFO | __main__:main:602 - 4. 参考README中的邮件配置章节 -2026-01-18 18:02:57.874 | INFO | __main__:main:603 - 5. 查看详细错误日志 -2026-01-18 18:13:08.550 | INFO | __main__:test_celery_email_config:36 - Celery配置信息: -2026-01-18 18:13:08.550 | INFO | __main__:test_celery_email_config:45 - CELERY_BROKER_URL: redis://:xjjq1234!@*** -2026-01-18 18:13:08.552 | INFO | __main__:test_celery_email_config:45 - CELERY_RESULT_BACKEND: redis://:xjjq1234!@*** -2026-01-18 18:13:08.552 | INFO | __main__:test_celery_email_config:47 - CELERY_TIMEZONE: Asia/Shanghai -2026-01-18 18:13:08.555 | INFO | __main__:test_celery_email_config:58 - 邮件配置信息: -2026-01-18 18:13:08.555 | WARNING | __main__:test_celery_email_config:61 - smtp_server: 未配置 -2026-01-18 18:13:08.555 | INFO | __main__:test_celery_email_config:63 - smtp_port: 587 -2026-01-18 18:13:08.555 | WARNING | __main__:test_celery_email_config:61 - smtp_username: 未配置 -2026-01-18 18:13:08.555 | WARNING | __main__:test_celery_email_config:61 - recipient_email: 未配置 -2026-01-18 18:13:08.555 | ERROR | __main__:test_celery_email_config:77 - 缺少必要的配置: smtp_server, smtp_username, smtp_password -2026-01-18 18:13:08.556 | INFO | __main__:main:597 - -[测试2] Celery Worker状态检查 -2026-01-18 18:13:08.556 | INFO | __main__:test_celery_worker_status:119 - 检查Celery Worker状态... -2026-01-18 18:13:12.720 | WARNING | __main__:test_celery_worker_status:148 - 获取Worker状态失败: Error 10061 connecting to localhost:6379. 由于目标计算机积极拒绝,无法连接。. -2026-01-18 18:13:16.768 | WARNING | __main__:test_celery_worker_status:164 - 获取活跃任务失败: Error 10061 connecting to localhost:6379. 由于目标计算机积极拒绝,无法连接。. -2026-01-18 18:13:20.827 | WARNING | __main__:test_celery_worker_status:175 - 获取计划任务失败: Error 10061 connecting to localhost:6379. 由于目标计算机积极拒绝,无法连接。. -2026-01-18 18:13:20.828 | INFO | __main__:main:602 - -[测试3] Celery异步邮件任务测试 -2026-01-18 18:13:20.828 | INFO | __main__:test_celery_email_task:520 - 开始测试Celery异步邮件任务... -2026-01-18 18:13:20.830 | INFO | __main__:test_celery_email_task:530 - 发送Celery邮件任务到队列... -2026-01-18 18:15:09.488 | ERROR | __main__:test_celery_email_task:573 - Celery邮件任务测试失败: -Retry limit exceeded while trying to reconnect to the Celery redis result store backend. The Celery application must be restarted. - -2026-01-18 18:15:09.490 | INFO | __main__:test_celery_email_task:574 - 可能的原因: -2026-01-18 18:15:09.490 | INFO | __main__:test_celery_email_task:575 - 1. Celery worker未运行 -2026-01-18 18:15:09.491 | INFO | __main__:test_celery_email_task:576 - 2. Redis连接问题 -2026-01-18 18:15:09.492 | INFO | __main__:test_celery_email_task:577 - 3. 任务执行超时 -2026-01-18 18:15:09.493 | INFO | __main__:main:607 - -[测试4] 同步发送测试邮件 -2026-01-18 18:15:09.505 | ERROR | __main__:main:672 - 同步邮件测试失败: 未配置发件邮箱 -2026-01-18 18:15:09.506 | INFO | __main__:main:675 - -============================================================ -2026-01-18 18:15:09.506 | INFO | __main__:main:676 - 测试总结: -2026-01-18 18:15:09.508 | INFO | __main__:main:677 - 通过测试: 1/4 -2026-01-18 18:15:09.508 | INFO | __main__:main:678 - ============================================================ -2026-01-18 18:15:09.509 | ERROR | __main__:main:700 - 多数测试失败,Celery邮件功能异常。 -2026-01-18 18:15:09.510 | INFO | __main__:main:701 - -紧急处理: -2026-01-18 18:15:09.510 | INFO | __main__:main:702 - 1. ❌ 检查Celery worker: sudo supervisorctl status celery_worker -2026-01-18 18:15:09.511 | INFO | __main__:main:703 - 2. ❌ 检查Redis: sudo systemctl status redis-server -2026-01-18 18:15:09.512 | INFO | __main__:main:704 - 3. ❌ 检查SMTP配置 -2026-01-18 18:15:09.513 | INFO | __main__:main:705 - 4. ❌ 查看日志: tail -f /var/log/celery/worker.log