Skip to content

fix email conflict bug #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2021
Merged
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
14 changes: 8 additions & 6 deletions app/server/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
from fastapi.security import HTTPBasicCredentials
from passlib.context import CryptContext

from app.server.database.database import admin_collection
from server.database.database import admin_collection
#from app.server.auth.admin import validate_login
from app.server.auth.jwt_handler import signJWT
from app.server.database.database import add_admin
from app.server.models.admin import AdminModel
from server.auth.jwt_handler import signJWT
from server.database.database import add_admin
from server.models.admin import AdminModel

router = APIRouter()

hash_helper = CryptContext(schemes=["bcrypt"])

@router.post("/login")
async def admin_login(admin_credentials: HTTPBasicCredentials = Body(...)):
# NEW CODE
admin_user = await admin_collection.find_one({"email": admin_credentials.username}, {"_id": 0})
if (admin_user):
password = hash_helper.verify(
Expand All @@ -36,9 +37,10 @@ async def admin_login(admin_credentials: HTTPBasicCredentials = Body(...)):

@router.post("/")
async def admin_signup(admin: AdminModel = Body(...)):
admin = admin_collection.find_one({"email": admin.email})
if(admin):
admin_exists = await admin_collection.find_one({"email": admin.email}, {"_id": 0})
if(admin_exists):
return "Email already exists"

admin.password = hash_helper.encrypt(admin.password)
new_admin = await add_admin(jsonable_encoder(admin))
return new_admin