File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 3
3
from fastapi .security import HTTPBasicCredentials
4
4
from passlib .context import CryptContext
5
5
6
- from app . server .database .database import admin_collection
6
+ from server .database .database import admin_collection
7
7
#from app.server.auth.admin import validate_login
8
- from app . server .auth .jwt_handler import signJWT
9
- from app . server .database .database import add_admin
10
- from app . server .models .admin import AdminModel
8
+ from server .auth .jwt_handler import signJWT
9
+ from server .database .database import add_admin
10
+ from server .models .admin import AdminModel
11
11
12
12
router = APIRouter ()
13
13
14
14
hash_helper = CryptContext (schemes = ["bcrypt" ])
15
15
16
16
@router .post ("/login" )
17
17
async def admin_login (admin_credentials : HTTPBasicCredentials = Body (...)):
18
+ # NEW CODE
18
19
admin_user = await admin_collection .find_one ({"email" : admin_credentials .username }, {"_id" : 0 })
19
20
if (admin_user ):
20
21
password = hash_helper .verify (
@@ -36,9 +37,10 @@ async def admin_login(admin_credentials: HTTPBasicCredentials = Body(...)):
36
37
37
38
@router .post ("/" )
38
39
async def admin_signup (admin : AdminModel = Body (...)):
39
- admin = admin_collection .find_one ({"email" : admin .email })
40
- if (admin ):
40
+ admin_exists = await admin_collection .find_one ({"email" : admin .email }, { "_id" : 0 })
41
+ if (admin_exists ):
41
42
return "Email already exists"
43
+
42
44
admin .password = hash_helper .encrypt (admin .password )
43
45
new_admin = await add_admin (jsonable_encoder (admin ))
44
46
return new_admin
You can’t perform that action at this time.
0 commit comments