@@ -77,16 +77,18 @@ def loginHandler():
77
77
user = userCollection .find_one ({ "email" : username })
78
78
print (user .keys ())
79
79
if "location" in user .keys ():
80
+
80
81
print (user ["location" ])
81
- location = locationCollection .find_one ({"id" : int (user ["location" ])})
82
+ #location = locationCollection.find_one({"id" : int(user["location"])})
83
+ location = user ["location" ]
82
84
if "name" in user .keys ():
83
85
name = user ["name" ]
84
86
85
87
isPasswordCorrect = bcrypt .checkpw (password .encode (), user ["password" ])
86
88
# print(isPasswordCorrect)
87
89
print (user )
88
90
if isPasswordCorrect :
89
- accessToken = create_access_token (identity = {"username" : username , "role" : "user" , "name" :name } )
91
+ accessToken = create_access_token (identity = {"username" : username , "role" : "user" , "name" :name , "location" : location }, expires_delta = datetime . timedelta ( days = 365 ) )
90
92
return {"result" : {
91
93
"access_token" : accessToken
92
94
}}
@@ -164,7 +166,19 @@ def detect():
164
166
165
167
access_token = None
166
168
result = load_image_and_detect (base64Image , filters )
167
- if auth :
169
+ print (type (result ))
170
+ result = json .loads (result )
171
+ temp = result ["object_detected" ]
172
+ highest = 0
173
+ highest_obj = None
174
+ for i in temp :
175
+ if i ['confidence' ]> highest :
176
+ highest = i ['confidence' ]
177
+ highest_obj = i
178
+
179
+
180
+
181
+ if auth and result ["status" ] != "failed" :
168
182
access_token = auth .split (" " )[1 ]
169
183
decoded = decode_token (access_token )
170
184
historiesCollection = clientDB ["histories" ]
@@ -176,7 +190,7 @@ def detect():
176
190
"detected_at" : current_time ,
177
191
"location" : decoded ["sub" ]["location" ],
178
192
"name" : decoded ["sub" ]["name" ],
179
- "detection_result" : result
193
+ "detection_result" : highest_obj
180
194
})
181
195
182
196
@@ -193,7 +207,7 @@ def getDetectionHistory():
193
207
histories = list (histories )
194
208
results = []
195
209
for hist in histories :
196
- results .append ({"username" : hist ["username" ], "image" : hist ["image" ], "detected_at" : hist ["detected_at" ], "location" : hist ["location" ], "name" : hist ["name" ], "detection_result" : json . loads ( hist ["detection_result" ]) })
210
+ results .append ({"username" : hist ["username" ], "image" : hist ["image" ], "detected_at" : hist ["detected_at" ], "location" : hist ["location" ], "name" : hist ["name" ], "detection_result" : hist ["detection_result" ]})
197
211
return make_response ({"result" :{"histories" : results }}, 200 )
198
212
199
213
@@ -210,16 +224,23 @@ def getUserProfile():
210
224
user = clientDB ["users" ].find_one ({"email" : decoded ["sub" ]["username" ]})
211
225
if "location" in user .keys ():
212
226
location = user ["location" ]
227
+ location = clientDB ["locations" ].find_one ({"id" : location })
228
+ if not location :
229
+ location = None
213
230
if "name" in user .keys ():
214
231
name = user ["name" ]
215
232
216
- return make_response ({
233
+ try :
234
+ return make_response ({
217
235
"result" : {
218
236
"username" : decoded ["sub" ]["username" ],
219
- "location" : location ,
237
+ "location" : location [ "id" ] ,
220
238
"name" : name
221
239
}
222
240
})
241
+ except Exception as E :
242
+ print (E )
243
+ return make_response ({"result" : {"username" : decoded ["sub" ]["username" ], "location_name" :None , "location_image" : None , "location_id" : None , "name" : name }}, 200 )
223
244
224
245
@app .route ("/upload-file" , methods = ["POST" ])
225
246
@jwt_required ()
0 commit comments