文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 3bf46332 by 李景熙

add 接口login

parent a01af0ee
......@@ -12956,6 +12956,11 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true
},
"vuex": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/vuex/-/vuex-3.4.0.tgz",
"integrity": "sha512-ajtqwEW/QhnrBZQsZxCLHThZZaa+Db45c92Asf46ZDXu6uHXgbfVuBaJ4gzD2r4UX0oMJHstFwd2r2HM4l8umg=="
},
"watchpack": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.1.tgz",
......
......@@ -33,7 +33,7 @@ def create_user(username, password, email):
user = User(username=username, password=password, email=email)
try:
user.save()
except BaseException:
except Exception:
print(0)
else:
print(1)
......
from flask import Flask
from views.uploadDownload import uploadDownload
from views.textAnnotation import textAnnotation
# from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation
from views.login import user
app = Flask(__name__)
app.register_blueprint(textAnnotation)
app.register_blueprint(uploadDownload)
# app.register_blueprint(textAnnotation)
# app.register_blueprint(uploadDownload)
app.register_blueprint(user)
@app.route("/")
......
import json
from flask import Blueprint
from flask import request
from Dao import User
user = Blueprint("user", __name__, url_prefix="/user")
@user.route("/register")
def register():
username = request.args['username']
password = request.args['passwd']
email = request.args['email']
User.create_user(username, password, email)
return json.dumps(username)
@user.route("/login", methods=["Post"])
def login():
username = request.form['name']
passwd = request.form['passwd']
User.find_user(username, passwd)
return json.dumps(username)
import json
from flask import Blueprint
from flask import request
from Dao import mongodbTest
textAnnotation = Blueprint("textAnnotation", __name__, url_prefix="/textAnnotation")
collectionTest = mongodbTest.db.test
# x = mongodbTest.revOne(collectionTest, {"annotatorId": "10"}, {"$set": {"fragmentId": "1000"}})
x = mongodbTest.findAll(collectionTest)
# mongodbTest.insert(collectionTest,{"annotatorId": "10", "fragmentId": "1000",
# "textUrl": "198.111.23.12:23/file/10.txt",
# "tokenList":
# [{"entityId": "1", "word": "滑坡1号", "begin": "1", "end": "4", "attribute": "滑坡 基本信息 滑坡名称"}]})
mongodbTest.addToken(collectionTest, {"annotatorId": "10"}, {"entityId": "2", "word": "滑坡2号", "begin": "10", "end": "14", "attribute": "滑坡 基本信息 滑坡名称"})
mongodbTest.deleteToken(collectionTest, {"annotatorId": "10"}, {"entityId": "1"})
@textAnnotation.route("/")
def hello_world():
return json.dumps(x, ensure_ascii=False)
@textAnnotation.route("/test", methods=["POST"])
def check():
# 默认返回内容
return_dict = {'return_code': '200', 'return_info': '处理成功', 'result': False}
# 判断传入的json数据是否为空
# if request.get_data() is None:
# return_dict['return_code'] = '5004'
# return_dict['return_info'] = '请求参数为空'
# return json.dumps(return_dict, ensure_ascii=False)
# 获取传入的参数
get_Data = request.get_data()
# 传入的参数为bytes类型,需要转化成json
get_Data = json.loads(get_Data)
name = get_Data.get('name')
age = get_Data.get('age')
# 对参数进行操作
return_dict['result'] = "%s,%s" % (name, age)
return json.dumps(return_dict, ensure_ascii=False)
# import json
# from flask import Blueprint
# from flask import request
# from Dao import mongodbTest
#
# textAnnotation = Blueprint("textAnnotation", __name__, url_prefix="/textAnnotation")
# collectionTest = mongodbTest.db.test
# # x = mongodbTest.revOne(collectionTest, {"annotatorId": "10"}, {"$set": {"fragmentId": "1000"}})
# x = mongodbTest.findAll(collectionTest)
# # mongodbTest.insert(collectionTest,{"annotatorId": "10", "fragmentId": "1000",
# # "textUrl": "198.111.23.12:23/file/10.txt",
# # "tokenList":
# # [{"entityId": "1", "word": "滑坡1号", "begin": "1", "end": "4", "attribute": "滑坡 基本信息 滑坡名称"}]})
# mongodbTest.addToken(collectionTest, {"annotatorId": "10"}, {"entityId": "2", "word": "滑坡2号", "begin": "10", "end": "14", "attribute": "滑坡 基本信息 滑坡名称"})
# mongodbTest.deleteToken(collectionTest, {"annotatorId": "10"}, {"entityId": "1"})
#
#
# @textAnnotation.route("/")
# def hello_world():
# return json.dumps(x, ensure_ascii=False)
#
#
# @textAnnotation.route("/test", methods=["POST"])
# def check():
# # 默认返回内容
# return_dict = {'return_code': '200', 'return_info': '处理成功', 'result': False}
# # 判断传入的json数据是否为空
# # if request.get_data() is None:
# # return_dict['return_code'] = '5004'
# # return_dict['return_info'] = '请求参数为空'
# # return json.dumps(return_dict, ensure_ascii=False)
# # 获取传入的参数
# get_Data = request.get_data()
# # 传入的参数为bytes类型,需要转化成json
# get_Data = json.loads(get_Data)
# name = get_Data.get('name')
# age = get_Data.get('age')
# # 对参数进行操作
# return_dict['result'] = "%s,%s" % (name, age)
# return json.dumps(return_dict, ensure_ascii=False)
#
import json
import os
import time
from flask import Blueprint
from support import basedir
from flask import jsonify, request, send_file
from werkzeug.utils import secure_filename
uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/uploadDownload")
UPLOAD_FOLDER = 'upload' # 用于保存上传文件的文件夹名称
ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx'} # 允许上传的文件格式
# 用于判断文件后缀
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
# 上传文件
@uploadDownload.route('/upload', methods=['POST'], strict_slashes=False)
def upload():
file_dir = os.path.join(basedir, UPLOAD_FOLDER)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值
if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型
fName = secure_filename(f.filename)
ext = fName.rsplit('.', 1)[1] # 获取文件后缀
unix_time = int(time.time())
new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名
f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
print(new_filename)
return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename})
else:
return jsonify({"errno": 1001, "errmsg": u"failed"})
# 下载接口
@uploadDownload.route('/download/<fileName>', methods=['GET'])
def download(fileName):
file_dir = os.path.join(basedir, UPLOAD_FOLDER, fileName)
return send_file(file_dir, as_attachment=True, attachment_filename=fileName)
# 显示文档
@uploadDownload.route('/getfile/<path>', methods=['GET'])
def today(path):
fileStr = open(os.path.join(basedir, UPLOAD_FOLDER, path), 'r', encoding='UTF-8').read()
x1 = [{"file": fileStr}]
return json.dumps(x1, ensure_ascii=False)
# import json
# import os
# import time
#
#
# from flask import Blueprint
# from support import basedir
# from flask import jsonify, request, send_file
# from werkzeug.utils import secure_filename
#
#
# uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/uploadDownload")
# UPLOAD_FOLDER = 'upload' # 用于保存上传文件的文件夹名称
# ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx'} # 允许上传的文件格式
#
#
# # 用于判断文件后缀
# def allowed_file(filename):
# return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
#
#
# # 上传文件
# @uploadDownload.route('/upload', methods=['POST'], strict_slashes=False)
# def upload():
# file_dir = os.path.join(basedir, UPLOAD_FOLDER)
# if not os.path.exists(file_dir):
# os.makedirs(file_dir)
# f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值
#
# if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型
# fName = secure_filename(f.filename)
# ext = fName.rsplit('.', 1)[1] # 获取文件后缀
# unix_time = int(time.time())
# new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名
# f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
# print(new_filename)
#
# return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename})
# else:
# return jsonify({"errno": 1001, "errmsg": u"failed"})
#
#
# # 下载接口
# @uploadDownload.route('/download/<fileName>', methods=['GET'])
# def download(fileName):
# file_dir = os.path.join(basedir, UPLOAD_FOLDER, fileName)
# return send_file(file_dir, as_attachment=True, attachment_filename=fileName)
#
#
# # 显示文档
# @uploadDownload.route('/getfile/<path>', methods=['GET'])
# def today(path):
# fileStr = open(os.path.join(basedir, UPLOAD_FOLDER, path), 'r', encoding='UTF-8').read()
# x1 = [{"file": fileStr}]
# return json.dumps(x1, ensure_ascii=False)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment