Skip to content

Commit

Permalink
local cors
Browse files Browse the repository at this point in the history
  • Loading branch information
shamith09 committed Oct 15, 2024
1 parent a482aec commit 6d00101
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
28 changes: 19 additions & 9 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
ROUTING_NUMBER_KEY = getenv("FERNET_ROUTING_NUMBER_KEY")
BLUEVINE_PASSWORD_KEY = getenv("FERNET_BLUEVINE_PASSWORD_NUMBER_KEY")

logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")


@app.after_request
def after_request(response):
# cors
if getenv("ENVIRONMENT") == "local":
origin = "http://localhost:3000"
origin = "*"
elif getenv("ENVIRONMENT") == "production":
origin = "https://plextech-member-portal.vercel.app"

Expand Down Expand Up @@ -137,8 +138,17 @@ def reencrypt_user_credentials():
if update_fields:
db.Users.update_one({"_id": user["_id"]}, {"$set": update_fields})


def decrypt_all_users():
users = db.Users.find({"$or": [{"bank.accountNumber": {"$exists": True}}, {"bank.routingNumber": {"$exists": True}}, {"bluevinePassword": {"$exists": True}}]})
users = db.Users.find(
{
"$or": [
{"bank.accountNumber": {"$exists": True}},
{"bank.routingNumber": {"$exists": True}},
{"bluevinePassword": {"$exists": True}},
]
}
)
for user in users:
try:
if "bank" in user:
Expand All @@ -149,7 +159,10 @@ def decrypt_all_users():
if "bluevinePassword" in user:
decrypt(user["bluevinePassword"], BLUEVINE_PASSWORD_KEY)
except InvalidToken:
logging.warning(f"Invalid token for user: {user.get('email', 'Unknown email')}")
logging.warning(
f"Invalid token for user: {user.get('email', 'Unknown email')}"
)


@app.route("/logout/", methods=["POST", "OPTIONS"])
@jwt_required()
Expand Down Expand Up @@ -274,7 +287,7 @@ def protected_user_routes():
):
user["bank"]["accountNumber"] = str(user["bank"]["accountNumber"])[:20]
user["bank"]["routingNumber"] = str(user["bank"]["routingNumber"])[:20]

if "bluevinePassword" in user:
user["bluevinePassword"] = str(user["bluevinePassword"])[:20]
return dict(user), 200
Expand Down Expand Up @@ -749,10 +762,7 @@ def requests():
)
if not req:
return {"error": "request not found"}, 404
request_user = db.Users.find_one(
{"_id": req["user_id"]},
{"_id": 1, "firstName": 1, "lastName": 1, "email": 1},
)

user = db.Users.find_one(
{"_id": id}, {"_id": 1, "firstName": 1, "lastName": 1, "email": 1}
)
Expand Down
4 changes: 2 additions & 2 deletions server/token.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"token": "ya29.a0AcM612zg2q9_fh8Tm0u2zrFgqj157sc3JRgLepnlMvG_G1qW-g_MI_7LGyqvg1XlKecre9A4HFuwJumL3UyHC_He8wMgakMuhtO4fUcJLOys38JunO57Y8fkeEKyU8Riup0yGCPgN43nQ755v9RdOJHWJGlUmxOfdh5BLw6zxwsaCgYKATgSARISFQHGX2MieGgRlb4Te-NyNGmbCo9mlw0178",
"token": "ya29.a0AcM612zkwOuqgbc8XMVC2QRQxGYplIpaPeEtI5_3YPwKjo5G5Ic5eDt-kZZHaCsIGUrD8fLBmaSigbCpVveYp4QGgDaERmzasQu74h9qnY0_LV7MmpnUvwMEQ-lT1OdkGKI-N5ZYDpmVEN_PS-6yl9tMi-mXCjcXkq-cClPjqCMaCgYKAT4SARISFQHGX2MiI-7eEWbX4ojTI24Ifxwe6w0178",
"refresh_token": "1//06EwKtLXaoqBsCgYIARAAGAYSNwF-L9Irggll9sz3DSiOwEJjliMNK0gDfK_waEP3hDDY0anT9iYpvId0y5PiwenblVcXP94vMFM",
"token_uri": "https://oauth2.googleapis.com/token",
"client_id": "968100881152-garl97325rjhdanp1igoa1m1ttl298uh.apps.googleusercontent.com",
"client_secret": "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",
"scopes": ["https://www.googleapis.com/auth/spreadsheets"],
"expiry": "2024-10-14T20:47:00.994145Z"
"expiry": "2024-10-15T20:02:31.516411Z"
}

0 comments on commit 6d00101

Please sign in to comment.