This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community.py
124 lines (98 loc) · 3.36 KB
/
community.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from flask import Flask, request, jsonify, make_response, abort,render_template
from data import User
from flask_cors import CORS, cross_origin
app = Flask(__name__)
# CORS(app)
# cors = CORS(app, resources={r"/*": {"origins": "http://localhost:63342\*"}})
app.secret_key = '123'
user = User()
@app.route('/', methods=['POST'])
def log():
content = request.get_json(force=True)
username = content["username"]
password = content["password"]
if username != "" and password != "":
user_info = dict({"username": username, "password": password})
result = user.user_login(user_info)
return jsonify(result)
else:
return jsonify(meg="请输入信息")
# @app.route('/remember_me',methods=["POST"])
# def remember_me():
# content = request.get_json(force=True)
# remember_me=content["remember_me"]
# Token=content["Token"]
# user_info = dict({"remember_me":remember_me,"Token":Token})
# result = user.user_login(user_info)
# return result
@app.route('/signup', methods=['GET', 'POST'])
def signup():
content = request.get_json(force=True)
username = content["username"]
password = content["password"]
info_user = dict({"username": username, "password": password})
result = user.signup(info_user)
return jsonify({"result": result})
@app.route('/write_post', methods=['POST'])
def write_posts():
content = request.get_json(force=True)
username =content["username"]
post=content["post"]
dicts = dict({"post": post, "username": username})
user.post(dicts)
return jsonify({"success":"success"})
@app.route('/comments', methods=["POST"])
def write_comments():
content=request.get_json(force=True)
dicts={
"comment":content["comment"],
"_id": content["_id"],
"root_id": content["root_id"],
# "order": request.json.get("order"),
"username":content["username"]
}
result=user.comments(dicts)
return result
@app.route('/community', methods=['POST'])
def read_posts():
# username = request.json.get("username")
content=request.get_json(force=True)
order = content["order"]
username=content["username"]
result = user.read_post(dict({"order": order,"username":username}))
return jsonify(result)
@app.route('/logout',methods=['POST'])
def logout():
content=request.get_json(force=True)
username = content['username']
result = user.logout(username)
return jsonify({"result":result})
@app.route('/praise', methods=['POST'])
def praise():
content=request.get_json(force=True)
_id = content["_id"]
user.praise(_id)
return jsonify({"success": "success"})
@app.route('/get_info', methods=["POST"])
def get_info():
content=request.get_json(force=True)
username = content["username"]
dicts = dict({"username": username})
data = user.get_info(dicts)
if data == []:
return jsonify(meg="无提醒")
else:
return jsonify(data)
@app.route('/recommend', methods=["POST"])
def recommend():
content = request.get_json(force=True)
praise = content["praise"]
username = content["username"]
result = user.recommend(dict({"praise": praise, "username": username}))
return jsonify(result)
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
if __name__ == '__main__':
app.run()
app.debug = True