From 83098fbd1d5780f827a4aca41eb87321f3d2ab21 Mon Sep 17 00:00:00 2001 From: zypo Date: Sun, 17 May 2020 13:16:45 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE=20-=20?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E8=AE=BE=E7=BD=AE=20-=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=82=AE=E4=BB=B6=E6=9C=8D=E5=8A=A1=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/setting/urls.py | 1 + spug_api/apps/setting/views.py | 19 +++++++++++++++ .../src/pages/system/setting/AlarmSetting.js | 24 +++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/spug_api/apps/setting/urls.py b/spug_api/apps/setting/urls.py index c18fc4e1..737cbae3 100644 --- a/spug_api/apps/setting/urls.py +++ b/spug_api/apps/setting/urls.py @@ -8,5 +8,6 @@ urlpatterns = [ url(r'^$', SettingView.as_view()), url(r'^ldap_test/$', ldap_test), + url(r'^email_test/$', email_test), url(r'^about/$', get_about) ] diff --git a/spug_api/apps/setting/views.py b/spug_api/apps/setting/views.py index 3bc642db..d13532f8 100644 --- a/spug_api/apps/setting/views.py +++ b/spug_api/apps/setting/views.py @@ -9,6 +9,7 @@ from apps.setting.models import Setting import platform import ldap +import smtplib class SettingView(View): @@ -44,6 +45,24 @@ def ldap_test(request): return json_response(error=error) +def email_test(request): + form, error = JsonParser( + Argument('server'), + Argument('port', type=int), + Argument('username'), + Argument('password'), + ).parse(request.body) + if error is None: + try: + server = smtplib.SMTP_SSL(form.server, form.port) + server.login(form.username, form.password) + return json_response() + except Exception as e: + error = e.smtp_error.decode('utf-8') + return json_response(error=error) + return json_response(error=error) + + def get_about(request): return json_response({ 'python_version': platform.python_version(), diff --git a/spug_web/src/pages/system/setting/AlarmSetting.js b/spug_web/src/pages/system/setting/AlarmSetting.js index eda3b00d..91f755ae 100644 --- a/spug_web/src/pages/system/setting/AlarmSetting.js +++ b/spug_web/src/pages/system/setting/AlarmSetting.js @@ -19,10 +19,22 @@ class AlarmSetting extends React.Component { this.setting = JSON.parse(lds.get(store.settings, 'mail_service.value', "{}")); this.state = { mode: this.setting['server'] === undefined ? '1' : '2', - spug_key: lds.get(store.settings, 'spug_key.value', "") + spug_key: lds.get(store.settings, 'spug_key.value', ""), + mail_test_loading: false, } } + handleEmailTest = () => { + this.props.form.validateFields((error, data) => { + if (!error) { + this.setState({mail_test_loading: true}); + http.post('/api/setting/email_test/', data).then(()=> { + message.success('邮件服务连接成功') + }).finally(()=> this.setState({mail_test_loading: false})) + } + }) + }; + _doSubmit = (formData) => { store.loading = true; http.post('/api/setting/', {data: formData}) @@ -126,11 +138,15 @@ class AlarmSetting extends React.Component { +
+ +
)