-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path服务器.py
77 lines (76 loc) · 3.28 KB
/
服务器.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, request, render_template
import pymysql
import time
HTML_404="msg:请求错误,请联系管理员<a href='http://www.yonxi.cn' target='_blank'>小新</a>"
sql_con = pymysql.connect(host='114.117.208.100', # 数据库地址:本机地址为【localhost】;非本机地址填入第三方地址。
port=3306, # 端口号,数字类型,不加引号
user='zhh', # 用户名
password='3zBTN2XwFnFySTWC', # 数据库密码
db='zhh', # 数据库名
charset='utf8') # 数据库编码,一般为utf8)
cursor = sql_con.cursor() # 链接数据库
#查好SELECT * FROM `ZHH` WHERE `账号` LIKE '1712203688'
#查密SELECT * FROM `ZHH` WHERE `密码` LIKE 'zyx123..'
# 查询账号密码SELECT * FROM `ZHH` WHERE `账号` LIKE '1712203688' AND `密码` LIKE 'zyx123..'
app=Flask(__name__)
@app.route("/")
def index():
try:
return render_template("index.html")
except Exception :
return HTML_404
#登录区块
@app.route("/login",methods=["post"])
def login():
try:
name=request.form.get("dlname")
mim=request.form.get("dlpass")
cursor.execute("SELECT * FROM `ZHH` WHERE `账号` LIKE '%s' AND `密码` LIKE '%s'" % (name,mim))
sql_con.commit()
a = cursor.fetchone()
if name == str(a[1]) or mim==str(a[2]):
time1 = name, "于", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "请求登录"
file = open("log.txt", "a")
file.write(str(time1) + '\n')
print(time1)
return a[1]+"登录成功了"
except Exception:
#return "msg:提交错误,账号或密码错误<a href='http://127.0.0.1:5000/' target='_blank'>返回首页</a>'"
return render_template("cwtz.html")
#注册区块
@app.route("/regist",methods=["post"])
def regist():
try:
name=request.form.get("zcname")
mim=request.form.get("zcpass")
cursor.execute("SELECT * FROM `ZHH` WHERE `账号` LIKE '%s'" % (name))
sql_con.commit()
b = cursor.fetchone()
if name == b[1]:
return render_template("cwtz.html")
except Exception:
cursor.execute("INSERT INTO ZHH VALUES (NULL, '%s', '%s')" % (name, mim))
sql_con.commit()
return name+"添加成功,从此解放双手吧,小新全程24h为你挂机服务!"
@app.route("/cx", methods=["post"])
def cx():
try:
name=request.form.get("cxname")
count=cursor.execute("SELECT * FROM `log` WHERE `账号` LIKE '%s'" % (name))
sql_con.commit()
for i in range(count):
result = cursor.fetchone()
print(result)
# openw = open("templates/log.txt", "w")
# bl = name + " 于 " + result[1]
# openw.write(bl + '\n')
return str(result)
except Exception:
#return "msg:提交错误,账号或密码错误<a href='http://127.0.0.1:5000/' target='_blank'>返回首页</a>'"
return "没有这个账号,或没有签到记录"
#错误提示
@app.route('/<name>')
def show(name):
return HTML_404
if __name__ == "__main__":
app.run(threaded=True)