def mysqltest(request): host = request.POST.get('host') database = request.POST.get('database') DBUser = request.POST.get('DBUser') password = request.POST.get('password') port = request.POST.get('port') try: username = request.session.get('username') if username == returnadminusernamevalue: if dbinfotest(host,DBUser, password, port,database): try: # dir_now = os.path.dirname(os.path.abspath("settings.py")) writeprofile("mysql", "host", host) writeprofile("mysql", "username", DBUser) writeprofile("mysql", "Password", encrypt_and_decode().encrypted_text(password)) writeprofile("mysql", "Port", port) writeprofile("mysql", "database", database) creatmysqltable()# 创建mysql数据库的一些表格 result = {'isSuccess': True, "message": '成功'} except: result = {'isSuccess': False, "message": '出现异常'} else: result = {'isSuccess': False, "message": '连接失败'} else: result = {'isSuccess': False, "message": '连接失败'} except Exception as e: result = {'isSuccess': True, "message": str(e)} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def mysqllinktest(request): post = request.POST host = post.get("host") username = post.get("username") password = post.get("password") port = post.get("port") database = post.get("database") try: if dbinfotest(host, username, password, port, database): # dir_now = os.path.dirname(os.path.abspath("settings.py")) writeprofile("mysql", "host", host) writeprofile("mysql", "username", username) writeprofile("mysql", "password", encrypt_and_decode().encrypted_text(password)) writeprofile("mysql", "port", port) writeprofile("mysql", "database", database) result = {'isSuccess': True, 'message': '修改mysql配置成功'} else: result = {'isSuccess': False, 'message': '修改mysql配置失败'} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response except Exception as e: result = {'isSuccess': False, 'message': '修改mysql配置失败:' + str(e)} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def changadminpwd(request): try: post = request.POST adminoldpwd = post.get("oldpassword") adminnewpwd = post.get("newpassword1") adminrealnewpwd = post.get("newpassword2") username = request.session.get('username') if username.lower() == returnadminusernamevalue: if adminoldpwd !='' and adminnewpwd != '' and adminrealnewpwd != '': if adminnewpwd == adminrealnewpwd: adminoldassword = readprofile('password', 'administratorpassword') if check_password(adminoldpwd, adminoldassword): realpassword = make_password(adminnewpwd) writeprofile("password", "administratorpassword", realpassword) result = {'isSuccess': True, "message": '成功'} else: result = {'isSuccess': False, "message": '旧密码错误'} else: result = {'isSuccess': False, "message": '两次密码不一致'} else: result = {'isSuccess': False, "message": '请填写完整信息'} else: result = {'isSuccess': False, "message": '权限不足'} except Exception as e: result = {'isSuccess': False, "message": '出现异常'+str(e)} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response