From ef7f42cf6d45864473e444f698cd25b3c2bbcab0 Mon Sep 17 00:00:00 2001
From: ibuler
Date: Tue, 15 Dec 2015 19:36:33 +0800
Subject: [PATCH] reset password fix
---
jumpserver/views.py | 44 ++++++++++++++++---
juser/views.py | 4 +-
templates/install.html | 98 ++++++++++++++++++++++++++----------------
3 files changed, 99 insertions(+), 47 deletions(-)
diff --git a/jumpserver/views.py b/jumpserver/views.py
index 3cd2424c8..2c207e157 100644
--- a/jumpserver/views.py
+++ b/jumpserver/views.py
@@ -361,12 +361,42 @@ def install(request):
def install_test(request, offset):
- if offset == 'db':
- db_host = request.GET.get('db_host')
- db_port = request.GET.get('db_port')
- db_user = request.GET.get('db_user')
- db_pass = request.GET.get('db_pass')
- db = request.GET.get('db')
-
+ if request.method == 'post':
+ if offset == 'db':
+ import MySQLdb
+ db_host = request.GET.get('db_host')
+ db_port = int(request.GET.get('db_port'))
+ db_user = request.GET.get('db_user')
+ db_pass = request.GET.get('db_pass')
+ db = request.GET.get('db')
+
+ try:
+ conn = MySQLdb.connect(host=db_host, port=db_port, user=db_user, passwd=db_pass, db=db)
+ except Exception:
+ return HttpResponse('链接失败', status=500)
+ else:
+ return HttpResponse('连接成功')
+
+ elif offset == 'mail':
+ from smtplib import SMTP
+ smtp_host = request.GET.get('smtp_host')
+ smtp_port = request.GET.get('smtp_port')
+ mail_addr = request.GET.get('mail_addr')
+ mail_pass = request.GET.get('mail_pass')
+
+ try:
+ smtp = SMTP(smtp_host, port=smtp_port)
+ smtp.login(mail_addr, mail_pass)
+ smtp.sendmail(mail_addr, (mail_addr),
+ '''From:%s\r\nTo:%s\r\nSubject:Jumpserver Mail Test!\r\n\r\n Mail test passed!\r\n''')
+ smtp.quit()
+
+ except Exception:
+ return HttpResponse('测试失败', status=500)
+ else:
+ return HttpResponse(u'登陆 %s邮箱查看邮件' % mail_addr)
+ else:
+ print request.method
+ return HttpResponse('请求方法错误', status=500)
diff --git a/juser/views.py b/juser/views.py
index f72cd4432..f5351599e 100644
--- a/juser/views.py
+++ b/juser/views.py
@@ -295,7 +295,7 @@ def forget_password(request):
hash_encode = PyCrypt.md5_crypt(str(user.uuid) + str(timestamp) + KEY)
msg = u"""
Hi %s, 请点击下面链接重设密码!
- %s/juser/reset_password/?uuid=%s×tamp=%s&hash=%s
+ %s/juser/password/reset/?uuid=%s×tamp=%s&hash=%s
""" % (user.name, URL, user.uuid, timestamp, hash_encode)
send_mail('忘记跳板机密码', msg, MAIL_FROM, [email], fail_silently=False)
msg = u'请登陆邮箱,点击邮件重设密码'
@@ -311,7 +311,7 @@ def reset_password(request):
uuid_r = request.GET.get('uuid', '')
timestamp = request.GET.get('timestamp', '')
hash_encode = request.GET.get('hash', '')
- action = '/juser/reset_password/?uuid=%s×tamp=%s&hash=%s' % (uuid_r, timestamp, hash_encode)
+ action = '/juser/password/reset/?uuid=%s×tamp=%s&hash=%s' % (uuid_r, timestamp, hash_encode)
if request.method == 'POST':
password = request.POST.get('password')
diff --git a/templates/install.html b/templates/install.html
index 76ddba8a0..09965e14b 100644
--- a/templates/install.html
+++ b/templates/install.html
@@ -47,40 +47,39 @@