Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions app/auth.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# app/auth.py

import os, requests

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Multiple imports on one line (os, requests) Warning

Multiple imports on one line (os, requests)

Check warning

Code scanning / Prospector (reported by Codacy)

Multiple imports on one line (os, requests) (multiple-imports) Warning

Multiple imports on one line (os, requests) (multiple-imports)

Check warning

Code scanning / Prospector (reported by Codacy)

Unable to import 'requests' (import-error) Warning

Unable to import 'requests' (import-error)

Check warning

Code scanning / Pylint (reported by Codacy)

Multiple imports on one line (os, requests) Warning

Multiple imports on one line (os, requests)
from .schema import LoginSchema, SignUpSchema
from fastapi.responses import JSONResponse
from starlette import status
from firebase_admin import auth, firestore
from .firebase_init import db, firebase
from .firebase_init import db

FIREBASE_API_KEY = os.getenv("FIREBASE_API_KEY")

def _create_response(status_code: int, message: str, **kwargs):
content = {"message": message}
Expand Down Expand Up @@ -40,7 +43,7 @@
valid, msg = _validate_passwords(password, confirm_password)
if not valid:
return _create_response(status.HTTP_400_BAD_REQUEST, msg)

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12
college_id, college_data = _get_college_by_domain(email)
if not college_id:
return _create_response(
Expand All @@ -60,7 +63,7 @@
}
)
return _create_response(
status.HTTP_201_CREATED, "User created successfully", uid=user.uid

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
)
except Exception as e:
return _create_response(status.HTTP_500_INTERNAL_SERVER_ERROR, str(e))
Expand All @@ -76,16 +79,29 @@
status.HTTP_400_BAD_REQUEST,
"Your college domain is not registered.",
)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
try:
user = firebase.auth().sign_in_with_email_and_password(email, password)
return _create_response(
status.HTTP_200_OK,
"Login successful",
idToken=user["idToken"],
)
request_url = f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key={FIREBASE_API_KEY}"

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (113/100) Warning

Line too long (113/100)

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (113/100) Warning

Line too long (113/100)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
payload = {

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
"email": email,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"password": password,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"returnSecureToken": True

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
}
response = requests.post(request_url, json=payload)

Check warning on line 90 in app/auth.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/auth.py#L90

Call to requests without timeout

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
response_data = response.json()

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

if response.status_code == 200:

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Unnecessary "else" after "return" Warning

Unnecessary "else" after "return"

Check warning

Code scanning / Prospector (reported by Codacy)

Unnecessary "else" after "return" (no-else-return) Warning

Unnecessary "else" after "return" (no-else-return)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check warning

Code scanning / Pylint (reported by Codacy)

Unnecessary "else" after "return" Warning

Unnecessary "else" after "return"

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
return _create_response(
status.HTTP_200_OK,
"Login successful",
idToken=response_data["idToken"],

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
)
else:

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
error_msg = response_data.get("error", {}).get("message", "Login failed")

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12
return _create_response(status.HTTP_401_UNAUTHORIZED, error_msg)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

except Exception as e:
return _create_response(status.HTTP_401_UNAUTHORIZED, str(e))
return _create_response(status.HTTP_500_INTERNAL_SERVER_ERROR, str(e))

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

async def verify_staff_access(token: str):
try:
Expand Down
14 changes: 0 additions & 14 deletions app/firebase_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@
import os
import firebase_admin
from firebase_admin import credentials, firestore
import pyrebase
from dotenv import load_dotenv

load_dotenv()

IS_CI = os.environ.get("CI") == "true"

firebaseConfig = {
"apiKey": os.getenv("FIREBASE_API_KEY"),
"authDomain": os.getenv("FIREBASE_AUTH_DOMAIN"),
"databaseURL": os.getenv("FIREBASE_DATABASE_URL"),
"projectId": os.getenv("FIREBASE_PROJECT_ID"),
"storageBucket": os.getenv("FIREBASE_STORAGE_BUCKET"),
"messagingSenderId": os.getenv("FIREBASE_MESSAGING_SENDER_ID"),
"appId": os.getenv("FIREBASE_APP_ID"),
"measurementId": os.getenv("FIREBASE_MEASUREMENT_ID")
}

firebase = pyrebase.initialize_app(firebaseConfig)

firebase_credentials = os.environ.get("FIREBASE_SERVICE_ACCOUNT")

if not firebase_credentials and not IS_CI:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pydantic==2.12.5
pydantic_core==2.41.5
PyJWT==2.10.1
pyparsing==3.2.5
Pyrebase4==4.8.0
python-dotenv==1.2.1
python-jwt==4.1.0
python-multipart==0.0.21
Expand Down
Loading