Skip to content

Commit

Permalink
login
Browse files Browse the repository at this point in the history
  • Loading branch information
shamith09 committed Oct 7, 2024
1 parent a7a41f8 commit 97930e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
17 changes: 10 additions & 7 deletions server/bluevine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import requests
import pymongo
import logging

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

load_dotenv()

Expand Down Expand Up @@ -40,7 +43,7 @@ def login(
{"email": bluevineEmail, "password": bluevinePassword},
headers={"referer": "https://app.bluevine.com/dashboard"},
)
print(res.text)
logging.info(res.text)
if res.status_code != 200:
raise Exception("Failed to login to bluevine: " + str(res.json()))
s.headers.update({"x-csrftoken": s.cookies["csrftoken"]})
Expand All @@ -51,14 +54,14 @@ def login(
f"https://app.bluevine.com/api/v3/company/{login_data['company_slug']}/user/{login_data['slug']}/mfa/",
headers={"referer": "https://app.bluevine.com/dashboard"},
)
print(res.text)
logging.info(res.text)

# get mfa
res = s.post(
f"https://app.bluevine.com/api/v3/company/{login_data['company_slug']}/user/{login_data['slug']}/mfa/send_token/",
headers={"referer": "https://app.bluevine.com/dashboard"},
)
print(res.text)
logging.info(res.text)

# start a new thread that waits for mfa then runs after_login

Expand Down Expand Up @@ -95,11 +98,11 @@ def after_login(
request_id,
description=None,
):
print('after_login started')
logging.info('after_login started')

i = 0
while not len(list(db.MFA.find({}))):
print('waiting for mfa')
logging.info('waiting for mfa')
sleep(1)
if i > 60:
return {"error": "mfa timeout"}, 400
Expand All @@ -112,7 +115,7 @@ def after_login(
{"token": code, "trust_device": True},
headers={"referer": "https://app.bluevine.com/dashboard"},
)
print('verify mfa', res.text)
logging.info('verify mfa: %s', res.text)

# if not res.ok:
# return {"error": "bad mfa"}, 400
Expand Down Expand Up @@ -172,7 +175,7 @@ def after_login(
"x-csrftoken": s.cookies["csrftoken"],
},
)
print('send money', res.text)
logging.info('send money: %s', res.text)

if res.status_code == 428:
res = s.post(
Expand Down
11 changes: 5 additions & 6 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pymongo
import json
import subprocess
import logging

load_dotenv()

Expand All @@ -41,6 +42,7 @@
ROUTING_NUMBER_KEY = getenv("FERNET_ROUTING_NUMBER_KEY")
BLUEVINE_PASSWORD_KEY = getenv("FERNET_BLUEVINE_PASSWORD_NUMBER_KEY")

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

@app.after_request
def after_request(response):
Expand Down Expand Up @@ -73,7 +75,7 @@ def after_request(response):
response.data = json.dumps(data)
return response
except (RuntimeError, KeyError):
# Case where there is not a valid JWT. Just return the original respone
# Case where there is not a valid JWT. Just return the original response
return response


Expand All @@ -100,7 +102,7 @@ def decrypt(c, key):


def reencrypt_user_credentials():
old_key = "8evSmxioOt4uAN798OjQGbhNT2OWIFRZBYGq0l4OP9g="
old_key = "REDACTED"
users = db.Users.find({"bank": {"$exists": True}})
for user in users:
update_fields = {}
Expand Down Expand Up @@ -147,7 +149,7 @@ def decrypt_all_users():
if "bluevinePassword" in user:
decrypt(user["bluevinePassword"], BLUEVINE_PASSWORD_KEY)
except InvalidToken:
print(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 @@ -315,9 +317,6 @@ def login_signup_add_PIC():
return {"error": "Incorrect email"}, 401

if form["method"] == "login":
access_token = create_access_token(identity=str(user["_id"]))
res = {"access_token": access_token}
return res
# login success
if not user["registered"]:
return {}, 404
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.a0AcM612yR_4sc1s-SgbJr__h0E36ujCCCZT9MI8WG1h5kfCfrFR-oeCHmaOGCjO8_D1MX8EZ-0p2PHhWxpLw5pkG77rLs30qn9s5U2IjRzy9Q6209_i-NVtrSQzeuxszYxRXjyB0RDl7AcqKaPaHzCED2g_-8yayes8I0g2VXnw4aCgYKAXISARISFQHGX2MigaAqepG3dAFxlNEuYyBQ6w0178",
"token": "ya29.a0AcM612x6woyO0_gNWnd71qcnkUPfmWJgWTh9Y6HCW2xcX5E9iUPeB8DYVVtb9Nkk9MfswDKGSG1Xs8y3ahbt5lqI7PKR9l7sLAVi_9LqGFd6BzJSMtXyTOAs6R19GszOCb-3PgblMD6uy7jVXQW_uVnyBi2RrDU_grsf0KgHGhcaCgYKAWISARISFQHGX2MiNGwbdWAfJscqtHKM19lQPA0178",
"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-09-27T00:25:28.359187Z"
"expiry": "2024-10-07T18:58:08.254885Z"
}

0 comments on commit 97930e8

Please sign in to comment.