-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
191 lines (164 loc) · 5.58 KB
/
server.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from flask import Flask, jsonify, request
from common.preferences import DEBUG_MODE, ALLOW_HOST, LOAD_PORT
from middleware.users import User
from json import loads
from flask_cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
users = User()
@app.route('/')
def homes():
return 'Привет Хакатон'
@app.route('/new_user', methods=['POST'])
def new_user():
try:
jsn = loads(request.data)
print(jsn)
login = jsn['login']
passw = jsn['passw']
mail = jsn['mail']
return jsonify(users.create_user(login, passw,mail))
except Exception as _ex:
print(_ex)
return jsonify({'status': 'False'})
@app.route('/confirmation/<link>', methods=['get'])
def confirmation_new_user(link):
try:
return users.confirmation_user(link)
except Exception as _ex:
print(_ex)
return "<h1>Технические неполадки</h1>"
@app.route('/question/create', methods=['POST'])
def posts_create():
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
description = jsn['description']
text_body = jsn['text_body']
try:
label = jsn['label']
except:
label = None
try:
doc = jsn['document']
except:
doc = None
users.create_post(login, description, text_body, label, doc)
return jsonify({'status': 'True'})
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
print(_ex)
return jsonify({'status': 'Erore'})
@app.route('/question/<int:post_id>/answer', methods=['POST'])
def posts_answer(post_id):
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
post_id = str(post_id)
body = jsn['text_body']
try:
doc = jsn['document']
except:
doc = None
try:
id_answ = jsn['id_answ']
except:
id_answ = -1
users.create_answ(login, body, post_id, doc, id_answ)
return jsonify({'status': 'True'})
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
print(_ex)
return jsonify({'status': 'Erore'})
@app.route('/auth', methods=['POST'])
def auth():
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
return jsonify({'status': 'True'})
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
return jsonify({'status': 'Erore'})
@app.route('/questions', methods=['POST'])
def posts_read():
try:
jsn = loads(request.data)
try:
filter = jsn['filter']
except:
filter = None
return jsonify(users.read_posts(filter))
except Exception as _ex:
print(_ex)
return jsonify({'status': 'Erore'})
@app.route('/question/<int:post_id>', methods=['POST'])
def posts_read_question(post_id):
try:
return jsonify(users.read_current_post(str(post_id)))
except Exception as _ex:
print(_ex)
return jsonify({'status': 'Erore'})
@app.route('/answer/<int:id>/statis', methods=['POST'])
def answer_statis(id):
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
jsn = loads(request.data)
operator = jsn['operator']
return jsonify({'status': users.upd_statis(id, operator)})
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
return jsonify({'status': 'Erore'})
@app.route('/answer/<int:id>/status', methods=['POST'])
def answer_status(id):
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
jsn = loads(request.data)
operator = jsn['operator']
return jsonify({'status': users.upd_status(id, login, operator)})
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
return jsonify({'status': 'Erore'})
@app.route('/profile', methods=['POST'])
def profile_info():
try:
jsn = loads(request.data)
login = jsn['login']
passw = jsn['passw']
ck = users.check_user(login, passw)
if ck == 1:
return jsonify(users.read_current_user(login))
elif ck == 'mail':
return jsonify({'status': 'UnconfirmedEmail'})
return jsonify({'status': 'IncorrectValue'})
except Exception as _ex:
print(_ex)
return jsonify({'status': 'Erore'})
app.run(debug=DEBUG_MODE, host=ALLOW_HOST, port=LOAD_PORT)