Spaces:
Runtime error
Runtime error
CaesarCloudSync commited on
Commit ·
afbaf2d
1
Parent(s): 3398148
RevisionBank Replace instead of delete_many
Browse files
main.py
CHANGED
|
@@ -289,12 +289,14 @@ async def changesendtoemail(data : JSONStructure = None, authorization: str = He
|
|
| 289 |
scheduled_exists = importcsv.db.scheduledcards.find_one({"email":current_user})
|
| 290 |
if scheduled_exists:
|
| 291 |
user_scheduled_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 292 |
-
importcsv.db.scheduledcards.delete_many(user_scheduled_cards)
|
| 293 |
del user_scheduled_cards["sendtoemail"]
|
| 294 |
sendtoemailscheduled = user_scheduled_cards["sendtoemail"]
|
| 295 |
user_scheduled_cards.update({"sendtoemail": sendtoemailscheduled})
|
| 296 |
-
importcsv.db.scheduledcards.insert_one(user_scheduled_cards)
|
| 297 |
-
|
|
|
|
|
|
|
| 298 |
|
| 299 |
user_revision_cards = list(importcsv.db.accountrevisioncards.find({"email": current_user}))[0]
|
| 300 |
#importcsv.db.accountrevisioncards.delete_many(user_revision_cards)
|
|
@@ -393,16 +395,22 @@ async def removerevisioncard(data : JSONStructure = None, authorization: str = H
|
|
| 393 |
for card in user_revision_cards["revisioncards"]:
|
| 394 |
if card == data:
|
| 395 |
user_revision_cards["revisioncards"].remove(card)
|
| 396 |
-
importcsv.db.accountrevisioncards.delete_many({"email":current_user})
|
| 397 |
-
importcsv.db.accountrevisioncards.insert_one(user_revision_cards)
|
|
|
|
|
|
|
|
|
|
| 398 |
# Remove the revision card from the scheduled cards
|
| 399 |
try:
|
| 400 |
user_scheduled_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 401 |
for card in user_scheduled_cards["revisioncards"]:
|
| 402 |
if card == data:
|
| 403 |
user_scheduled_cards["revisioncards"].remove(card)
|
| 404 |
-
importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 405 |
-
importcsv.db.scheduledcards.insert_one(user_scheduled_cards)
|
|
|
|
|
|
|
|
|
|
| 406 |
return {"message":"revision card removed"}
|
| 407 |
except IndexError as iex:
|
| 408 |
return {"message":"revision card removed"}
|
|
@@ -430,8 +438,11 @@ async def schedulerevisioncard(data : JSONStructure = None, authorization: str =
|
|
| 430 |
user_scheduled_cards["revisioncards"] = new_cards # Updates the list.
|
| 431 |
del user_scheduled_cards["_id"]
|
| 432 |
user_scheduled_cards["email"] = current_user # Sets the email to the current user.
|
| 433 |
-
importcsv.db.scheduledcards.delete_many({"email":current_user}) # Allows data to be updated.
|
| 434 |
-
importcsv.db.scheduledcards.insert_one(user_scheduled_cards) # Inserts the new data.
|
|
|
|
|
|
|
|
|
|
| 435 |
return {"message":"revision cards scheduled"}
|
| 436 |
elif cards_not_exist == []: # If the cards are already in the database, return a message.
|
| 437 |
return {"message":"revision cards already scheduled"}
|
|
@@ -452,8 +463,11 @@ async def unscheduleallrevisioncard(authorization: str = Header(None)):
|
|
| 452 |
if email_exists: # Checks if email exists
|
| 453 |
user_revision_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 454 |
user_revision_cards["revisioncards"] = []
|
| 455 |
-
importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 456 |
-
importcsv.db.scheduledcards.insert_one(user_revision_cards)
|
|
|
|
|
|
|
|
|
|
| 457 |
return {"message":"Allrevision card unscheduled"}
|
| 458 |
except Exception as ex:
|
| 459 |
return {f"error":f"{type(ex)},{str(ex)}"}
|
|
@@ -470,8 +484,11 @@ async def unschedulerevisioncard(data : JSONStructure = None, authorization: str
|
|
| 470 |
for card in user_revision_cards["revisioncards"]:
|
| 471 |
if card == data:
|
| 472 |
user_revision_cards["revisioncards"].remove(card)
|
| 473 |
-
importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 474 |
-
importcsv.db.scheduledcards.insert_one(user_revision_cards)
|
|
|
|
|
|
|
|
|
|
| 475 |
return {"message":"revision card unscheduled"}
|
| 476 |
except Exception as ex:
|
| 477 |
return {f"error":f"{type(ex)},{str(ex)}"}
|
|
@@ -1063,11 +1080,14 @@ async def resetpassword(data : JSONStructure = None, authorization: str = Header
|
|
| 1063 |
user_from_db = list(importcsv.db.users.find({"email": current_user}))[0]
|
| 1064 |
#print(user_from_db)
|
| 1065 |
# TODO Delete password from here and replace.
|
| 1066 |
-
importcsv.db.users.delete_many(user_from_db)
|
| 1067 |
del user_from_db["password"]
|
| 1068 |
encrypted_password = hashlib.sha256(data["password"].encode('utf-8')).hexdigest()
|
| 1069 |
user_from_db.update({"password": encrypted_password})
|
| 1070 |
-
importcsv.db.users.insert_one(user_from_db)
|
|
|
|
|
|
|
|
|
|
| 1071 |
return {"message": "Password reset successful."}
|
| 1072 |
elif not email_exists:
|
| 1073 |
return {"message": "Email Doesn't exist."}
|
|
@@ -1277,10 +1297,13 @@ async def getstudentsubscriptions(authorization: str = Header(None)):
|
|
| 1277 |
for student in student_user_from_db:
|
| 1278 |
del student["_id"], student["password"],student["hostemail"],student['subscription']
|
| 1279 |
|
| 1280 |
-
importcsv.db.users.delete_many(user_from_db) # Deletes the data in order to update it.
|
| 1281 |
del user_from_db["numofaccounts"] # Deletes the numofaccounts to update it.
|
| 1282 |
user_from_db.update({"numofaccounts": 200 - len(student_user_from_db)}) # Updates the number of accounts
|
| 1283 |
-
importcsv.db.users.insert_one(user_from_db) # inserts updated data into the host emails account
|
|
|
|
|
|
|
|
|
|
| 1284 |
return {"result":student_user_from_db}
|
| 1285 |
except Exception as ex:
|
| 1286 |
return {"error": f"{type(ex)}-{ex}"}
|
|
@@ -1321,11 +1344,14 @@ async def changestudentpassword(data : JSONStructure = None, authorization: str
|
|
| 1321 |
if hostkey and studentkey:
|
| 1322 |
student_user_from_db = list(importcsv.db.studentsubscriptions.find({"email": data["studentemail"]}))[0]
|
| 1323 |
# TODO Delete password from here and replace.
|
| 1324 |
-
importcsv.db.studentsubscriptions.delete_many(student_user_from_db)
|
| 1325 |
del student_user_from_db["password"]
|
| 1326 |
encrypted_password = hashlib.sha256(data["password"].encode('utf-8')).hexdigest()
|
| 1327 |
student_user_from_db.update({"password": encrypted_password})
|
| 1328 |
-
importcsv.db.studentsubscriptions.
|
|
|
|
|
|
|
|
|
|
| 1329 |
return {"message": "Password reset successful."}
|
| 1330 |
else:
|
| 1331 |
return {"error": "Student account does not exist."}
|
|
@@ -1361,7 +1387,7 @@ async def deletesubscription(authorization: str = Header(None)):
|
|
| 1361 |
if current_user:
|
| 1362 |
try:
|
| 1363 |
user_from_db = list(importcsv.db.users.find({"email": current_user}))[0]
|
| 1364 |
-
importcsv.db.users.delete_many(user_from_db)
|
| 1365 |
if "end_date_subscription" in user_from_db:
|
| 1366 |
del user_from_db["end_date_subscription"]
|
| 1367 |
if "start_date_subscription" in user_from_db:
|
|
@@ -1372,7 +1398,10 @@ async def deletesubscription(authorization: str = Header(None)):
|
|
| 1372 |
del user_from_db["emailsleft"]
|
| 1373 |
if "numofaccounts" in user_from_db:
|
| 1374 |
del user_from_db["numofaccounts"]
|
| 1375 |
-
importcsv.db.users.
|
|
|
|
|
|
|
|
|
|
| 1376 |
|
| 1377 |
return {"message":"Subscription deleted from expiration"}
|
| 1378 |
except Exception as ex:
|
|
|
|
| 289 |
scheduled_exists = importcsv.db.scheduledcards.find_one({"email":current_user})
|
| 290 |
if scheduled_exists:
|
| 291 |
user_scheduled_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 292 |
+
#importcsv.db.scheduledcards.delete_many(user_scheduled_cards)
|
| 293 |
del user_scheduled_cards["sendtoemail"]
|
| 294 |
sendtoemailscheduled = user_scheduled_cards["sendtoemail"]
|
| 295 |
user_scheduled_cards.update({"sendtoemail": sendtoemailscheduled})
|
| 296 |
+
#importcsv.db.scheduledcards.insert_one(user_scheduled_cards)
|
| 297 |
+
importcsv.db.scheduledcards.replace_one(
|
| 298 |
+
{"email":current_user},user_scheduled_cards
|
| 299 |
+
)
|
| 300 |
|
| 301 |
user_revision_cards = list(importcsv.db.accountrevisioncards.find({"email": current_user}))[0]
|
| 302 |
#importcsv.db.accountrevisioncards.delete_many(user_revision_cards)
|
|
|
|
| 395 |
for card in user_revision_cards["revisioncards"]:
|
| 396 |
if card == data:
|
| 397 |
user_revision_cards["revisioncards"].remove(card)
|
| 398 |
+
#importcsv.db.accountrevisioncards.delete_many({"email":current_user})
|
| 399 |
+
#importcsv.db.accountrevisioncards.insert_one(user_revision_cards)
|
| 400 |
+
importcsv.db.accountrevisioncards.replace_one(
|
| 401 |
+
{"email":current_user},user_revision_cards
|
| 402 |
+
)
|
| 403 |
# Remove the revision card from the scheduled cards
|
| 404 |
try:
|
| 405 |
user_scheduled_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 406 |
for card in user_scheduled_cards["revisioncards"]:
|
| 407 |
if card == data:
|
| 408 |
user_scheduled_cards["revisioncards"].remove(card)
|
| 409 |
+
#importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 410 |
+
#importcsv.db.scheduledcards.insert_one(user_scheduled_cards)
|
| 411 |
+
importcsv.db.scheduledcards.replace_one(
|
| 412 |
+
{"email":current_user},user_scheduled_cards
|
| 413 |
+
)
|
| 414 |
return {"message":"revision card removed"}
|
| 415 |
except IndexError as iex:
|
| 416 |
return {"message":"revision card removed"}
|
|
|
|
| 438 |
user_scheduled_cards["revisioncards"] = new_cards # Updates the list.
|
| 439 |
del user_scheduled_cards["_id"]
|
| 440 |
user_scheduled_cards["email"] = current_user # Sets the email to the current user.
|
| 441 |
+
#importcsv.db.scheduledcards.delete_many({"email":current_user}) # Allows data to be updated.
|
| 442 |
+
#importcsv.db.scheduledcards.insert_one(user_scheduled_cards) # Inserts the new data.
|
| 443 |
+
importcsv.db.scheduledcards.replace_one(
|
| 444 |
+
{"email":current_user},user_scheduled_cards
|
| 445 |
+
)
|
| 446 |
return {"message":"revision cards scheduled"}
|
| 447 |
elif cards_not_exist == []: # If the cards are already in the database, return a message.
|
| 448 |
return {"message":"revision cards already scheduled"}
|
|
|
|
| 463 |
if email_exists: # Checks if email exists
|
| 464 |
user_revision_cards = list(importcsv.db.scheduledcards.find({"email": current_user}))[0]
|
| 465 |
user_revision_cards["revisioncards"] = []
|
| 466 |
+
#importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 467 |
+
#importcsv.db.scheduledcards.insert_one(user_revision_cards)
|
| 468 |
+
importcsv.db.scheduledcards.replace_one(
|
| 469 |
+
{"email":current_user},user_revision_cards
|
| 470 |
+
)
|
| 471 |
return {"message":"Allrevision card unscheduled"}
|
| 472 |
except Exception as ex:
|
| 473 |
return {f"error":f"{type(ex)},{str(ex)}"}
|
|
|
|
| 484 |
for card in user_revision_cards["revisioncards"]:
|
| 485 |
if card == data:
|
| 486 |
user_revision_cards["revisioncards"].remove(card)
|
| 487 |
+
#importcsv.db.scheduledcards.delete_many({"email":current_user})
|
| 488 |
+
#importcsv.db.scheduledcards.insert_one(user_revision_cards)
|
| 489 |
+
importcsv.db.scheduledcards.replace_one(
|
| 490 |
+
{"email":current_user},user_revision_cards
|
| 491 |
+
)
|
| 492 |
return {"message":"revision card unscheduled"}
|
| 493 |
except Exception as ex:
|
| 494 |
return {f"error":f"{type(ex)},{str(ex)}"}
|
|
|
|
| 1080 |
user_from_db = list(importcsv.db.users.find({"email": current_user}))[0]
|
| 1081 |
#print(user_from_db)
|
| 1082 |
# TODO Delete password from here and replace.
|
| 1083 |
+
#importcsv.db.users.delete_many(user_from_db)
|
| 1084 |
del user_from_db["password"]
|
| 1085 |
encrypted_password = hashlib.sha256(data["password"].encode('utf-8')).hexdigest()
|
| 1086 |
user_from_db.update({"password": encrypted_password})
|
| 1087 |
+
#importcsv.db.users.insert_one(user_from_db)
|
| 1088 |
+
importcsv.db.users.replace_one(
|
| 1089 |
+
{"email":current_user},user_from_db
|
| 1090 |
+
)
|
| 1091 |
return {"message": "Password reset successful."}
|
| 1092 |
elif not email_exists:
|
| 1093 |
return {"message": "Email Doesn't exist."}
|
|
|
|
| 1297 |
for student in student_user_from_db:
|
| 1298 |
del student["_id"], student["password"],student["hostemail"],student['subscription']
|
| 1299 |
|
| 1300 |
+
#importcsv.db.users.delete_many(user_from_db) # Deletes the data in order to update it.
|
| 1301 |
del user_from_db["numofaccounts"] # Deletes the numofaccounts to update it.
|
| 1302 |
user_from_db.update({"numofaccounts": 200 - len(student_user_from_db)}) # Updates the number of accounts
|
| 1303 |
+
#importcsv.db.users.insert_one(user_from_db) # inserts updated data into the host emails account
|
| 1304 |
+
importcsv.db.users.replace_one(
|
| 1305 |
+
{"email":current_user},user_from_db
|
| 1306 |
+
)
|
| 1307 |
return {"result":student_user_from_db}
|
| 1308 |
except Exception as ex:
|
| 1309 |
return {"error": f"{type(ex)}-{ex}"}
|
|
|
|
| 1344 |
if hostkey and studentkey:
|
| 1345 |
student_user_from_db = list(importcsv.db.studentsubscriptions.find({"email": data["studentemail"]}))[0]
|
| 1346 |
# TODO Delete password from here and replace.
|
| 1347 |
+
#importcsv.db.studentsubscriptions.delete_many(student_user_from_db)
|
| 1348 |
del student_user_from_db["password"]
|
| 1349 |
encrypted_password = hashlib.sha256(data["password"].encode('utf-8')).hexdigest()
|
| 1350 |
student_user_from_db.update({"password": encrypted_password})
|
| 1351 |
+
importcsv.db.studentsubscriptions.replace_one(
|
| 1352 |
+
{"email":current_user},student_user_from_db
|
| 1353 |
+
)
|
| 1354 |
+
#importcsv.db.studentsubscriptions.insert_one(student_user_from_db)
|
| 1355 |
return {"message": "Password reset successful."}
|
| 1356 |
else:
|
| 1357 |
return {"error": "Student account does not exist."}
|
|
|
|
| 1387 |
if current_user:
|
| 1388 |
try:
|
| 1389 |
user_from_db = list(importcsv.db.users.find({"email": current_user}))[0]
|
| 1390 |
+
#importcsv.db.users.delete_many(user_from_db)
|
| 1391 |
if "end_date_subscription" in user_from_db:
|
| 1392 |
del user_from_db["end_date_subscription"]
|
| 1393 |
if "start_date_subscription" in user_from_db:
|
|
|
|
| 1398 |
del user_from_db["emailsleft"]
|
| 1399 |
if "numofaccounts" in user_from_db:
|
| 1400 |
del user_from_db["numofaccounts"]
|
| 1401 |
+
importcsv.db.users.replace_one(
|
| 1402 |
+
{"email":current_user},user_from_db
|
| 1403 |
+
)
|
| 1404 |
+
#importcsv.db.users.update_one( { "email": current_user}, {"$set": user_from_db}, upsert = True )
|
| 1405 |
|
| 1406 |
return {"message":"Subscription deleted from expiration"}
|
| 1407 |
except Exception as ex:
|