update
This commit is contained in:
parent
c67a976f61
commit
a137fdacc0
@ -10,10 +10,10 @@ pip install --upgrade pip
|
||||
// 根据依赖文件安装环境
|
||||
pip install -r requirements.txt
|
||||
// 设置全局变量
|
||||
export FLASK_APP=ccb.py
|
||||
export FLASK_APP=canary.py
|
||||
export FLASK_ENV=development
|
||||
// 启动临时服务
|
||||
flask run --host=127.0.0.1 -p 5005
|
||||
flask run --host=127.0.0.1 -p 6000
|
||||
// 启动永久服务
|
||||
gunicorn ccb:app -c gunicorn.conf.py
|
||||
// 查看已启动服务
|
||||
|
@ -11,13 +11,10 @@ from flask_cors import CORS
|
||||
# 取消跨域访问限制,方便本地测试 注册CORS, "/*" 允许访问所有api
|
||||
CORS(app, resources=r'/*')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", debug=True, port="80")
|
||||
|
||||
# 测试用根路由
|
||||
@app.route('/api/')
|
||||
def sayHello():
|
||||
return 'Hello! Glad to serve you, please go to the official website: https://api.canary.moe'
|
||||
return 'Hello! Glad to serve you, please go to the official website: https://canary.lacus.site'
|
||||
|
||||
# 登录或者注册
|
||||
@app.route('/api/login', methods=["POST"])
|
||||
@ -46,4 +43,7 @@ def upload():
|
||||
# 访问拦截器转发到根路由
|
||||
@app.errorhandler(404)
|
||||
def miss(e):
|
||||
return redirect('/api')
|
||||
return redirect('/api')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", debug=True, port="80")
|
8
getDb.py
8
getDb.py
@ -9,7 +9,7 @@ setting = 'development'
|
||||
|
||||
# 获取数据集
|
||||
def col(arg):
|
||||
conn = MongoClient('mongodb://ccb:wL2wG2aD6aI1@0.0.0.0:27017/ccb')
|
||||
conn = MongoClient('mongodb://ccb:wL2wG2aD6aI1@mongo:27017/ccb')
|
||||
if setting == 'development':
|
||||
arg += '_test'
|
||||
if arg == 'user_info':
|
||||
@ -19,7 +19,7 @@ def col(arg):
|
||||
else:
|
||||
return False
|
||||
|
||||
def logData():
|
||||
def getUserInfo():
|
||||
user_list = []
|
||||
try:
|
||||
for i in col('user_info').find({},{"_id":0}):
|
||||
@ -31,8 +31,8 @@ def logData():
|
||||
print(e)
|
||||
return ('数据库查询失败', 111)
|
||||
|
||||
def getImg():
|
||||
content = logData()
|
||||
def writeData2Json():
|
||||
content = getUserInfo()
|
||||
if content[-1] != 200:
|
||||
return
|
||||
content = json.dumps(content[0]).encode()
|
||||
|
2
go.sh
2
go.sh
@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo start
|
||||
gunicorn ccb:app -c gunicorn.conf.py
|
||||
gunicorn canary:app -c gunicorn.conf.py
|
@ -1,14 +1,7 @@
|
||||
# 并行工作线程数
|
||||
workers = 4
|
||||
# 监听内网端口5000【按需要更改】
|
||||
# bind = '127.0.0.1:5001'
|
||||
bind = '0.0.0.0:80'
|
||||
# 设置守护进程【关闭连接时,程序仍在运行】
|
||||
daemon = True
|
||||
# 设置超时时间120s,默认为30s。按自己的需求进行设置
|
||||
timeout = 120
|
||||
# 设置访问日志和错误信息日志路径
|
||||
accesslog = './logs/acess.log'
|
||||
errorlog = './logs/error.log'
|
||||
#自动重启
|
||||
autostart = True
|
@ -40,7 +40,9 @@ def manageLogin(request):
|
||||
if time_difference > 1000 * 60 * 5:
|
||||
# 超过五分钟,重新发送uuid
|
||||
send_str = '非常感谢您的使用,您的验证码为:' + user_info['uuid']
|
||||
print(send_str)
|
||||
sendMail('欢迎注册Canary Codebook', send_str, [user_info['mail_addr']])
|
||||
print('stop at send')
|
||||
return {'errcode': 108, 'errmsg': '用户未激活,已重新发送邮件'}
|
||||
else:
|
||||
return {'errcode': 105, 'errmsg': '用户未激活,未重新发送邮件'}
|
||||
@ -164,8 +166,8 @@ def checkData(data):
|
||||
md = md5()
|
||||
md.update(d.encode('utf-8'))
|
||||
r = md.hexdigest().upper()
|
||||
# return r == data['sign']
|
||||
return True
|
||||
return r == data['sign']
|
||||
# return True
|
||||
|
||||
# 创建用户初始信息
|
||||
def createUserData(data):
|
||||
@ -184,7 +186,7 @@ def create_uuid():
|
||||
# 生成当前时间
|
||||
nowTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
# 生成的随机整数n,其中0<=n<=100
|
||||
randomNum = random.randint(0, 100)
|
||||
randomNum = random.randint(0, 99)
|
||||
if randomNum <= 10:
|
||||
randomNum = str(0) + str(randomNum)
|
||||
uniqueNum = str(nowTime) + str(randomNum)
|
||||
|
@ -3,7 +3,7 @@ from bson import ObjectId, json_util
|
||||
import re
|
||||
|
||||
# 主环境 (生产环境为production,开发环境为development)
|
||||
setting = 'development'
|
||||
setting = 'production'
|
||||
|
||||
# 获取数据集
|
||||
def col(arg):
|
||||
@ -23,6 +23,7 @@ def searchUser(mail_addr):
|
||||
try:
|
||||
user_info = col('user_info').find_one({"mail_addr": mail_addr})
|
||||
if user_info:
|
||||
user_info.pop("_id")
|
||||
return {'errcode': 200, 'user_info': user_info, 'errmsg': 'ok'}
|
||||
else:
|
||||
return {'errcode': 101, 'errmsg': '用户不存在'}
|
||||
|
@ -8,7 +8,7 @@ def sendMail(title, content, mailto_list):
|
||||
#发送邮箱地址
|
||||
sender = 'canarycodebook@163.com'
|
||||
#邮箱授权码,非登陆密码
|
||||
password = 'eTn49CftDfaytar'
|
||||
password = 'HHFLFTMNHUXQTRAE'
|
||||
#收件箱地址
|
||||
#receiver = '19xxxxxxx9@qq.com'
|
||||
# mailto_list = ['1144131090@qq.com','nayiyewosile@qq.com'] #群发邮箱地址
|
||||
@ -23,10 +23,10 @@ def sendMail(title, content, mailto_list):
|
||||
#主题
|
||||
msg['Subject'] = title
|
||||
|
||||
server = smtplib.SMTP(smtp_server,25) # SMTP协议默认端口是25
|
||||
server = smtplib.SMTP_SSL(smtp_server,465) # SMTP协议默认端口是25
|
||||
server.login(sender,password) #ogin()方法用来登录SMTP服务器
|
||||
server.set_debuglevel(1) #打印出和SMTP服务器交互的所有信息。
|
||||
server.sendmail(sender,mailto_list,msg.as_string()) #msg.as_string()把MIMEText对象变成str server.quit()
|
||||
|
||||
# 第一个参数为发送者,第二个参数为接收者,可以添加多个例如:['hello@163.com','xxx@qq.com',]# 第三个参数为发送的内容
|
||||
server.quit()
|
||||
server.quit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user