reset password fix

pull/26/head
ibuler 2015-12-15 19:36:33 +08:00
parent e817715da3
commit ef7f42cf6d
3 changed files with 99 additions and 47 deletions

View File

@ -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)

View File

@ -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&timestamp=%s&hash=%s
%s/juser/password/reset/?uuid=%s&timestamp=%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&timestamp=%s&hash=%s' % (uuid_r, timestamp, hash_encode)
action = '/juser/password/reset/?uuid=%s&timestamp=%s&hash=%s' % (uuid_r, timestamp, hash_encode)
if request.method == 'POST':
password = request.POST.get('password')

View File

@ -47,40 +47,39 @@
</p>
<form id="form" action="#" class="wizard-big" >
<h1>管理员账户</h1>
<fieldset>
<h2>管理员账号是首次登陆的账号</h2>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>用户名 *</label>
<input id="username" name="username" type="text" class="form-control required" minlength="5" >
</div>
<div class="form-group">
<label>密码 *</label>
<input id="password" name="password" type="password" class="form-control required password" minlength="8">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>邮件 *</label>
<input id="email" name="email" type="email" class="form-control required">
</div>
<div class="form-group">
<label>确认密码 *</label>
<input id="pass_confirm" name="pass_confirm" type="password" equalto="#password" class="form-control required">
</div>
</div>
<div class="col-sm-4">
<div class="text-center">
<div style="margin-top: 20px">
<i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>
</div>
</div>
</div>
</div>
</fieldset>
{# <h1>管理员账户</h1>#}
{# <fieldset>#}
{# <h2>管理员账号是首次登陆的账号</h2>#}
{# <div class="row">#}
{# <div class="col-sm-6">#}
{# <div class="form-group">#}
{# <label>用户名 *</label>#}
{# <input id="username" name="username" type="text" class="form-control required" minlength="5" >#}
{# </div>#}
{# <div class="form-group">#}
{# <label>密码 *</label>#}
{# <input id="password" name="password" type="password" class="form-control required password" minlength="8">#}
{# </div>#}
{# </div>#}
{# <div class="col-sm-6">#}
{# <div class="form-group">#}
{# <label>邮件 *</label>#}
{# <input id="email" name="email" type="email" class="form-control required">#}
{# </div>#}
{# <div class="form-group">#}
{# <label>确认密码 *</label>#}
{# <input id="pass_confirm" name="pass_confirm" type="password" equalto="#password" class="form-control required">#}
{# </div>#}
{# </div>#}
{# <div class="col-sm-4">#}
{# <div class="text-center">#}
{# <div style="margin-top: 20px">#}
{# <i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </fieldset>#}
<h1>数据库</h1>
<fieldset>
<h2>数据库连接信息</h2>
@ -110,7 +109,7 @@
</div>
<div class="form-group">
<div></div>
<a href="{% url 'user_add' %}" class="btn btn-sm btn-warning" style="float: right"> 测试连接 </a>
<a id="db_btn" value="{% url 'install_test' 'db' %}" class="btn btn-sm btn-warning" style="float: right"> 测试连接 </a>
</div>
</div>
</div>
@ -123,7 +122,7 @@
<div class="col-sm-6">
<div class="form-group">
<label>SMTP *</label>
<input id="smtp" name="smtp" type="text" class="form-control required">
<input id="smtp_host" name="smtp_host" type="text" class="form-control required">
</div>
<div class="form-group">
<label>端口 *</label>
@ -137,11 +136,11 @@
</div>
<div class="form-group">
<label>密码 *</label>
<input id="dbpass" name="dbpass" type="password" class="form-control">
<input id="mail_pass" name="mail_pass" type="password" class="form-control">
</div>
<div class="form-group">
<div></div>
<a href="{% url 'user_add' %}" class="btn btn-sm btn-warning" style="float: right"> 测试邮件 </a>
<a id="mail_btn" href="{% url 'install_test' 'mail' %}" class="btn btn-sm btn-warning" style="float: right"> 测试邮件 </a>
</div>
</div>
</div>
@ -184,6 +183,29 @@
<script>
$(document).ready(function(){
// $("#wizard").steps();
$('#db_btn').click(function(){
console.log('hello');
var db_host = $('#db_host').val();
var db_port = $('#db_port').val();
var db_user = $('#db_user').val();
var db_pass = $('#db_pass').val();
$.post(
$(this).attr('value'),
{'db_host': db_host,
'db_port': db_port,
'db_user': db_user,
'db_pass': db_pass
},
function(data, status){
alert(data)
}
);
return false;
});
$("#form").steps({
bodyTag: "fieldset",
onStepChanging: function (event, currentIndex, newIndex)