Spaces:
Runtime error
Runtime error
Commit ·
d697ce3
1
Parent(s): fcfe4b3
refactor authentication flow by removing unused middleware and simplifying user sign-in response
Browse files- src/app.py +0 -1
- src/controllers/_auth_controller.py +2 -1
- src/services/_auth_service.py +0 -42
- src/services/_meeting_service.py +1 -0
src/app.py
CHANGED
|
@@ -39,7 +39,6 @@ app.add_middleware(
|
|
| 39 |
allow_headers=["*"],
|
| 40 |
)
|
| 41 |
|
| 42 |
-
app.add_middleware(AuthenticationMiddleware)
|
| 43 |
|
| 44 |
|
| 45 |
@app.get("/")
|
|
|
|
| 39 |
allow_headers=["*"],
|
| 40 |
)
|
| 41 |
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
@app.get("/")
|
src/controllers/_auth_controller.py
CHANGED
|
@@ -18,7 +18,8 @@ class AuthController:
|
|
| 18 |
async def _signin(self, user: UserSignInSchema):
|
| 19 |
try:
|
| 20 |
user = await self._auth_service.sign_in(user)
|
| 21 |
-
|
|
|
|
| 22 |
except HTTPException as e:
|
| 23 |
raise
|
| 24 |
except Exception as e:
|
|
|
|
| 18 |
async def _signin(self, user: UserSignInSchema):
|
| 19 |
try:
|
| 20 |
user = await self._auth_service.sign_in(user)
|
| 21 |
+
|
| 22 |
+
return UserSignInResponse(user_id=str(user["user_id"]))
|
| 23 |
except HTTPException as e:
|
| 24 |
raise
|
| 25 |
except Exception as e:
|
src/services/_auth_service.py
CHANGED
|
@@ -33,45 +33,3 @@ class AuthService:
|
|
| 33 |
"user_id": str(existing_user[0].id),
|
| 34 |
}
|
| 35 |
|
| 36 |
-
async def sign_in(self, user: UserSignInSchema, device_ipv4_address: str):
|
| 37 |
-
existing_user = await self._user_service.list_users(
|
| 38 |
-
filter_by={"email": user.email}
|
| 39 |
-
)
|
| 40 |
-
if not existing_user:
|
| 41 |
-
raise HTTPException(404, "Invalid credentials")
|
| 42 |
-
|
| 43 |
-
if not BcryptUtil.compare_password(
|
| 44 |
-
existing_user[0].hashed_password, user.password
|
| 45 |
-
):
|
| 46 |
-
raise HTTPException(404, "Invalid credentials")
|
| 47 |
-
|
| 48 |
-
token_payload = {
|
| 49 |
-
"user_id": str(existing_user[0].id),
|
| 50 |
-
"email": existing_user[0].email,
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
expiration_minutes = 60
|
| 54 |
-
|
| 55 |
-
token = self._jwt_util.generate_jwt(token_payload, expiration_minutes)
|
| 56 |
-
|
| 57 |
-
await self._session_service.create_session(
|
| 58 |
-
SessionCreateSchema(
|
| 59 |
-
user_id=existing_user[0],
|
| 60 |
-
token=token,
|
| 61 |
-
device_ipv4_address=device_ipv4_address,
|
| 62 |
-
expired_at=datetime.now() + timedelta(minutes=expiration_minutes),
|
| 63 |
-
)
|
| 64 |
-
)
|
| 65 |
-
return token
|
| 66 |
-
|
| 67 |
-
async def sign_out(self, token: str):
|
| 68 |
-
session = await self._session_service.get_session_by_token(token)
|
| 69 |
-
|
| 70 |
-
expired_session = SessionCreateSchema(
|
| 71 |
-
user_id=session.user_id,
|
| 72 |
-
token=session.token,
|
| 73 |
-
device_ipv4_address=session.device_ipv4_address,
|
| 74 |
-
expired_at=datetime.now(),
|
| 75 |
-
)
|
| 76 |
-
|
| 77 |
-
await self._session_service.update_session(session.id, expired_session)
|
|
|
|
| 33 |
"user_id": str(existing_user[0].id),
|
| 34 |
}
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/services/_meeting_service.py
CHANGED
|
@@ -133,6 +133,7 @@ class MeetingService:
|
|
| 133 |
data = {
|
| 134 |
"slug": salesperson_meeting_id,
|
| 135 |
"firstName": user_name,
|
|
|
|
| 136 |
"email": user_email,
|
| 137 |
"startTime": preferred_start_time,
|
| 138 |
"duration": duration_ms,
|
|
|
|
| 133 |
data = {
|
| 134 |
"slug": salesperson_meeting_id,
|
| 135 |
"firstName": user_name,
|
| 136 |
+
"lastName": "",
|
| 137 |
"email": user_email,
|
| 138 |
"startTime": preferred_start_time,
|
| 139 |
"duration": duration_ms,
|