Изменил способ авторизации
This commit is contained in:
parent
ba3ed4d422
commit
e06040b82b
2 changed files with 9 additions and 30 deletions
|
@ -25,6 +25,7 @@ from app.users.schemas import (
|
|||
SUser,
|
||||
SUserChangeData,
|
||||
SUserSendConfirmationCode,
|
||||
STokenLogin,
|
||||
)
|
||||
from app.tasks.tasks import (
|
||||
send_registration_confirmation_email,
|
||||
|
@ -72,9 +73,9 @@ async def check_existing_email(email: SEmail, uow=Depends(UnitOfWork)):
|
|||
@router.post(
|
||||
"/register",
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
response_model=None,
|
||||
response_model=STokenLogin,
|
||||
)
|
||||
async def register_user(response: Response, user_data: SUserRegister, uow=Depends(UnitOfWork)):
|
||||
async def register_user(user_data: SUserRegister, uow=Depends(UnitOfWork)):
|
||||
if user_data.password != user_data.password2:
|
||||
raise PasswordsMismatchException
|
||||
await AuthService.check_existing_user(uow, user_data)
|
||||
|
@ -97,7 +98,7 @@ async def register_user(response: Response, user_data: SUserRegister, uow=Depend
|
|||
await RedisService.set_verification_code(redis=redis_session, user_id=user_id, verification_code=user_code)
|
||||
user = await AuthService.authenticate_user_by_email(uow, user_data.email, user_data.password)
|
||||
access_token = create_access_token({"sub": str(user.id)})
|
||||
response.headers["Authorization"] = f"Bearer {access_token}"
|
||||
return {"authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
@router.get(
|
||||
|
@ -124,12 +125,12 @@ async def email_verification(user_code: str, uow=Depends(UnitOfWork)):
|
|||
@router.post(
|
||||
"/login",
|
||||
status_code=status.HTTP_200_OK,
|
||||
response_model=None,
|
||||
response_model=STokenLogin,
|
||||
)
|
||||
async def login_user(response: Response, user_data: SUserLogin, uow=Depends(UnitOfWork)):
|
||||
async def login_user(user_data: SUserLogin, uow=Depends(UnitOfWork)):
|
||||
user = await AuthService.authenticate_user(uow, user_data.email_or_username, user_data.password)
|
||||
access_token = create_access_token({"sub": str(user.id)})
|
||||
response.headers["Authorization"] = f"Bearer {access_token}"
|
||||
return {"authorization": f"Bearer {access_token}"}
|
||||
|
||||
|
||||
@router.post(
|
||||
|
|
|
@ -59,20 +59,6 @@ class SUser(BaseModel):
|
|||
date_of_registration: date
|
||||
|
||||
|
||||
class SUserPasswordRecover(BaseModel):
|
||||
email: EmailStr
|
||||
|
||||
|
||||
class SUserCode(BaseModel):
|
||||
user_code: str
|
||||
|
||||
|
||||
class SUserPasswordChange(BaseModel):
|
||||
user_id: int
|
||||
password1: str = Query(None, min_length=8)
|
||||
password2: str = Query(None, min_length=8)
|
||||
|
||||
|
||||
class SUserSendConfirmationCode(BaseModel):
|
||||
email: EmailStr
|
||||
current_password: str = Query(None, min_length=8)
|
||||
|
@ -86,22 +72,14 @@ class SUserChangeData(BaseModel):
|
|||
avatar_url: HttpUrl
|
||||
|
||||
|
||||
class SRecoverEmailSent(BaseModel):
|
||||
recover_email_sent: bool
|
||||
class STokenLogin(BaseModel):
|
||||
authorization: str
|
||||
|
||||
|
||||
class SEmailVerification(BaseModel):
|
||||
email_verification: bool
|
||||
|
||||
|
||||
class SConfirmPasswordRecovery(BaseModel):
|
||||
user_id: int
|
||||
|
||||
|
||||
class SPasswordRecovered(BaseModel):
|
||||
username: str
|
||||
|
||||
|
||||
class SCreateInvitationLink(BaseModel):
|
||||
invitation_link: HttpUrl
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue