Добавил эндпоинты для проверки наличия ника и почты в бд
This commit is contained in:
parent
e5b6e96e77
commit
040f10a2ed
2 changed files with 23 additions and 3 deletions
|
@ -4,7 +4,7 @@ from fastapi.responses import RedirectResponse
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.exceptions import UsernameAlreadyInUseException, \
|
from app.exceptions import UsernameAlreadyInUseException, \
|
||||||
IncorrectPasswordException, PasswordsMismatchException, WrongCodeException, UserNotFoundException, \
|
IncorrectPasswordException, PasswordsMismatchException, WrongCodeException, UserNotFoundException, \
|
||||||
SomethingWentWrongException
|
SomethingWentWrongException, UserAlreadyExistsException
|
||||||
from app.users.auth import get_password_hash, authenticate_user_by_email, \
|
from app.users.auth import get_password_hash, authenticate_user_by_email, \
|
||||||
create_access_token, verify_password, VERIFICATED_USER, authenticate_user, \
|
create_access_token, verify_password, VERIFICATED_USER, authenticate_user, \
|
||||||
check_existing_user, check_verificated_user_with_exc
|
check_existing_user, check_verificated_user_with_exc
|
||||||
|
@ -13,7 +13,7 @@ from app.users.dependencies import get_current_user
|
||||||
from app.users.models import Users
|
from app.users.models import Users
|
||||||
from app.users.schemas import SUserLogin, SUserRegister, SUser, SUserPassword, SUserRename, SUserAvatar, \
|
from app.users.schemas import SUserLogin, SUserRegister, SUser, SUserPassword, SUserRename, SUserAvatar, \
|
||||||
SUserPasswordRecover, SUserCode, SUserPasswordChange, SRecoverEmailSent, SUserToken, SEmailVerification, SUserName, \
|
SUserPasswordRecover, SUserCode, SUserPasswordChange, SRecoverEmailSent, SUserToken, SEmailVerification, SUserName, \
|
||||||
SNewAvatar, SConfirmPasswordRecovery, SPasswordRecovered, SUserAvatars
|
SNewAvatar, SConfirmPasswordRecovery, SPasswordRecovered, SUserAvatars, SUsername, SEmail
|
||||||
from app.tasks.tasks import send_registration_confirmation_email, send_password_change_email, \
|
from app.tasks.tasks import send_registration_confirmation_email, send_password_change_email, \
|
||||||
send_password_recover_email
|
send_password_recover_email
|
||||||
|
|
||||||
|
@ -34,7 +34,21 @@ async def get_all_users():
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
@router.post("/register", response_model=SUserToken)
|
@router.post("/check_existing_username", status_code=status.HTTP_200_OK)
|
||||||
|
async def check_existing_username(username: SUsername):
|
||||||
|
user = await UserDAO.find_one_or_none(username=username.username)
|
||||||
|
if user:
|
||||||
|
raise UserAlreadyExistsException
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/check_existing_email", status_code=status.HTTP_200_OK)
|
||||||
|
async def check_existing_email(email: SEmail):
|
||||||
|
user = await UserDAO.find_one_or_none(email=email.email)
|
||||||
|
if user:
|
||||||
|
raise UserAlreadyExistsException
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/register", response_model=SUserToken, status_code=status.HTTP_201_CREATED)
|
||||||
async def register_user(response: Response, user_data: SUserRegister):
|
async def register_user(response: Response, user_data: SUserRegister):
|
||||||
await check_existing_user(user_data)
|
await check_existing_user(user_data)
|
||||||
hashed_password = get_password_hash(user_data.password)
|
hashed_password = get_password_hash(user_data.password)
|
||||||
|
|
|
@ -123,3 +123,9 @@ class SUserAvatars(BaseModel):
|
||||||
avatar_image: str
|
avatar_image: str
|
||||||
|
|
||||||
|
|
||||||
|
class SUsername(BaseModel):
|
||||||
|
username: str = Query(None, min_length=2, max_length=30)
|
||||||
|
|
||||||
|
|
||||||
|
class SEmail(BaseModel):
|
||||||
|
email: EmailStr
|
||||||
|
|
Loading…
Add table
Reference in a new issue