
updates for new database and encrpytions, application updates, refactors
@176675e2882d590d6eff42ba293ee15d874a1e88
--- action.py
+++ action.py
... | ... | @@ -34,7 +34,9 @@ |
34 | 34 |
|
35 | 35 |
|
36 | 36 |
@Action.route('/gps_update') |
37 |
+ |
|
37 | 38 |
class GPS_update(Resource): |
39 |
+ @Action.doc(responses={200: 'Success'}) |
|
38 | 40 |
@Action.doc(responses={401: 'Unauthorized'}) |
39 | 41 |
@Action.doc(responses={500: 'Internal Error'}) |
40 | 42 |
def post(self): |
... | ... | @@ -68,12 +70,10 @@ |
68 | 70 |
500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}" |
69 | 71 |
} |
70 | 72 |
|
71 |
- |
|
72 | 73 |
df = pd.DataFrame(data["trip_log"]) |
73 | 74 |
df["user_id"] = data["user_id"] |
74 | 75 |
df["trip_id"] = data["trip_id"] |
75 |
- |
|
76 |
- |
|
76 |
+ |
|
77 | 77 |
columns = df.columns |
78 | 78 |
data_csv_block = df.to_csv(header=False, index=False) |
79 | 79 |
print(f"recieved : {data}") |
... | ... | @@ -110,8 +110,8 @@ |
110 | 110 |
return {"result" : "ERROR! INVALID TRIP_ID!"}, 500 |
111 | 111 |
|
112 | 112 |
trip_id = data["trip_id"] |
113 |
- trip_distance_m = data["trip_distance_m"] |
|
114 |
- trip_time_s = data["trip_time_s"] |
|
113 |
+ trip_distance_m = data["total_distance_m"] |
|
114 |
+ trip_time_s = data["total_time_s"] |
|
115 | 115 |
abrupt_start_count = data["abrupt_start_count"] |
116 | 116 |
abrupt_stop_count = data["abrupt_stop_count"] |
117 | 117 |
abrupt_acceleration_count = data["abrupt_acceleration_count"] |
... | ... | @@ -146,7 +146,7 @@ |
146 | 146 |
# Check if token is provided |
147 | 147 |
if not token: |
148 | 148 |
return {'result': 'fail', 'msg': '토큰이 없습니다.'}, 401 |
149 |
- |
|
149 |
+ |
|
150 | 150 |
try: |
151 | 151 |
# Decode the token to verify it |
152 | 152 |
decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
... | ... | @@ -157,9 +157,13 @@ |
157 | 157 |
return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401 |
158 | 158 |
|
159 | 159 |
# Interact with the DB to get user history |
160 |
+ |
|
161 |
+ data = request.get_json() |
|
162 |
+ user_id = data["user_id"] |
|
160 | 163 |
try: |
161 | 164 |
db = DB() |
162 | 165 |
result, status_code = db.get_history(user_name=user_id) |
163 | 166 |
return {'result': 'success', 'data': result}, status_code |
164 | 167 |
except Exception as e: |
165 |
- return {'result': 'fail', 'msg': str(e)}, 500(파일 끝에 줄바꿈 문자 없음) |
|
168 |
+ print(str(e)) |
|
169 |
+ return {'result': 'fail', 'msg': str(e)}, 500 |
--- app.py
+++ app.py
... | ... | @@ -27,5 +27,5 @@ |
27 | 27 |
api.add_namespace(Action, '/action') |
28 | 28 |
|
29 | 29 |
if __name__ == "__main__": |
30 |
- app.run(debug=True, host='0.0.0.0', port=15857) |
|
30 |
+ app.run(debug=True, host='0.0.0.0', port=27461) |
|
31 | 31 |
print("Flask Start") |
--- auth.py
+++ auth.py
... | ... | @@ -1,5 +1,5 @@ |
1 |
-from flask import request,jsonify,render_template,redirect,url_for |
|
2 |
-from flask_restx import Resource, Api, Namespace, fields |
|
1 |
+from flask import request,jsonify |
|
2 |
+from flask_restx import Resource, Namespace, fields |
|
3 | 3 |
from database.database import DB |
4 | 4 |
import datetime |
5 | 5 |
import jwt |
... | ... | @@ -34,7 +34,7 @@ |
34 | 34 |
}) |
35 | 35 |
|
36 | 36 |
user_fields_register = Auth.inherit('User reigster', user_fields, { |
37 |
- 'password': fields.String(description='Password', required=True),'email': fields.String(description='email', required=True),'user_sex': fields.String(description='sex', required=True),'phone': fields.String(description='phone', required=True) |
|
37 |
+ 'password': fields.String(description='Password', required=True),'email': fields.String(description='email', required=True),'phone': fields.String(description='phone', required=True) |
|
38 | 38 |
|
39 | 39 |
}) |
40 | 40 |
|
... | ... | @@ -58,9 +58,6 @@ |
58 | 58 |
}, 200 |
59 | 59 |
|
60 | 60 |
|
61 |
- |
|
62 |
- |
|
63 |
- |
|
64 | 61 |
@Auth.route('/register') |
65 | 62 |
class AuthRegister(Resource): |
66 | 63 |
@Auth.expect(user_fields_register) |
... | ... | @@ -73,7 +70,7 @@ |
73 | 70 |
id_ = data['id'] |
74 | 71 |
password = data['password'] |
75 | 72 |
user_email = data['email'] |
76 |
- sex = data['user_sex'] |
|
73 |
+ # sex = data['user_sex'] |
|
77 | 74 |
phone = data['phone'] |
78 | 75 |
|
79 | 76 |
# Prepare data for registration |
... | ... | @@ -81,7 +78,7 @@ |
81 | 78 |
'username': id_, |
82 | 79 |
'password': password, |
83 | 80 |
'email': user_email, |
84 |
- 'sex': sex, |
|
81 |
+ # 'sex': sex, |
|
85 | 82 |
'phone': phone |
86 | 83 |
} |
87 | 84 |
|
... | ... | @@ -159,23 +156,23 @@ |
159 | 156 |
|
160 | 157 |
if result['status'] == 'success': |
161 | 158 |
payload = { |
162 |
- 'id': id, |
|
159 |
+ 'id': id_, |
|
163 | 160 |
'exp': datetime.datetime.utcnow() + datetime.timedelta(days=14) |
164 | 161 |
} |
165 | 162 |
token = jwt.encode(payload, "secret", algorithm='HS256') |
166 |
- return jsonify({'result': 'success', 'token': token}) |
|
163 |
+ return {'result': 'success', 'token': token}, 200 |
|
167 | 164 |
else : |
168 |
- return jsonify({'result': 'fail', 'msg': '아이디/비밀번호가 일치하지 않습니다.'}) |
|
165 |
+ return {'result': 'fail', 'msg': '아이디/비밀번호가 일치하지 않습니다.'}, 401 |
|
169 | 166 |
|
170 | 167 |
|
171 |
-@Auth.route('/secession') |
|
172 |
-class AuthSecession(Resource): |
|
168 |
+@Auth.route('/withdraw') |
|
169 |
+class AuthWithdraw(Resource): |
|
173 | 170 |
def post(self): |
174 | 171 |
db=DB() |
175 | 172 |
id = request.json['token'] |
176 | 173 |
payload = jwt.decode(id, "secret", algorithms=['HS256']) |
177 | 174 |
db.db_delete_id(payload['id']) |
178 |
- return {'secession':'success'} |
|
175 |
+ return {'secession':'success'}, 200 |
|
179 | 176 |
|
180 | 177 |
|
181 | 178 |
|
--- database/database.py
+++ database/database.py
... | ... | @@ -73,13 +73,14 @@ |
73 | 73 |
password = data.get('password', '').strip() |
74 | 74 |
email = data.get('email', '').strip() |
75 | 75 |
phone = data.get('phone', '').strip() |
76 |
+ phone = phone.replace("-","") |
|
76 | 77 |
sex = data.get('sex', '').strip() |
77 | 78 |
|
78 | 79 |
# Validate username |
79 | 80 |
if not username: |
80 | 81 |
return None, "Username is required." |
81 |
- if len(username) > 255: |
|
82 |
- return None, "Username must not exceed 255 characters." |
|
82 |
+ if len(username) > 26: |
|
83 |
+ return None, "Username must not exceed 26 characters." |
|
83 | 84 |
|
84 | 85 |
# Validate password |
85 | 86 |
if not password: |
... | ... | @@ -96,11 +97,11 @@ |
96 | 97 |
return None, "Phone number must be in the format 010XXXXXXXX where X are digits." |
97 | 98 |
|
98 | 99 |
# Validate sex input |
99 |
- if not sex: |
|
100 |
- return None, "Sex is required." |
|
101 |
- if sex not in ['Male', 'Female', 'Non-binary', 'Other']: |
|
102 |
- return None, "Invalid value for sex." |
|
103 |
- |
|
100 |
+ # if not sex: |
|
101 |
+ # return None, "Sex is required." |
|
102 |
+ # if sex not in ['Male', 'Female', 'Non-binary', 'Other']: |
|
103 |
+ # return None, "Invalid value for sex." |
|
104 |
+ sex = "WHATEVER" |
|
104 | 105 |
return { |
105 | 106 |
'username': username, |
106 | 107 |
'password': password, |
... | ... | @@ -239,7 +240,7 @@ |
239 | 240 |
): |
240 | 241 |
|
241 | 242 |
self.cur.execute(f""" |
242 |
- INSERT INTO trip_log (username, trip_id, timestamp, total_distance_m, total_time_s, abrupt_start_count, abrupt_stop_count, |
|
243 |
+ INSERT INTO trip_log (user_id, trip_id, timestamp, total_distance_m, total_time_s, abrupt_start_count, abrupt_stop_count, |
|
243 | 244 |
abrupt_acceleration_count, abrupt_deceleration_count, helmet_on, final_score) |
244 | 245 |
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) |
245 | 246 |
""", ( |
... | ... | @@ -256,6 +257,15 @@ |
256 | 257 |
final_score |
257 | 258 |
) |
258 | 259 |
) |
260 |
+ |
|
261 |
+ def db_delete_id(self,user_id) : |
|
262 |
+ cur = self.conn.cursor() |
|
263 |
+ cur.execute(f''' |
|
264 |
+ delete |
|
265 |
+ from "{self.schema}".user_id ui |
|
266 |
+ where user_id = '{user_id}' |
|
267 |
+ ''') |
|
268 |
+ cur.close() |
|
259 | 269 |
|
260 | 270 |
def get_history(self, user_name): |
261 | 271 |
""" |
... | ... | @@ -294,7 +304,7 @@ |
294 | 304 |
abrupt_stop_count, abrupt_acceleration_count, abrupt_deceleration_count, |
295 | 305 |
helmet_on, final_score |
296 | 306 |
FROM trip_log |
297 |
- WHERE username = %s |
|
307 |
+ WHERE user_id = %s |
|
298 | 308 |
AND timestamp >= NOW() - INTERVAL '1 month' |
299 | 309 |
""", (user_name,)) |
300 | 310 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?