diff --git a/backend/app/views/auth/api.py b/backend/app/views/auth/api.py index fd7a08e..7f51807 100644 --- a/backend/app/views/auth/api.py +++ b/backend/app/views/auth/api.py @@ -43,22 +43,23 @@ async def login_for_access_token( @router.post("/register") async def register( - user_data: Annotated[schemas.UserRegister, Depends()], + user_data: schemas.UserRegister, db: Annotated[Session, Depends(get_db)], ) -> schemas.User: user = services.get_user_by_username(db, user_data.username) if user: raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, + status_code=status.HTTP_400_BAD_REQUEST, detail="User with this username already exists", headers={"WWW-Authenticate": "Bearer"}, ) - user = services.create_user( - db=db, - username=user_data.username, - plain_password=user_data.password, - name=user_data.name, - ) + if user_data.password != user_data.password2: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Passwords do not match", + headers={"WWW-Authenticate": "Bearer"}, + ) + user = services.create_user(db=db, user_data=user_data) return user diff --git a/backend/app/views/auth/schemas.py b/backend/app/views/auth/schemas.py index f81374a..1497421 100644 --- a/backend/app/views/auth/schemas.py +++ b/backend/app/views/auth/schemas.py @@ -15,7 +15,8 @@ class UserInDB(User): class UserRegister(User): - plain_password: str + password: str + password2: str class Token(BaseModel): diff --git a/backend/app/views/auth/services.py b/backend/app/views/auth/services.py index bcb108d..ce5f467 100644 --- a/backend/app/views/auth/services.py +++ b/backend/app/views/auth/services.py @@ -53,17 +53,17 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None return encoded_jwt -def create_user( - db: Session, username: str, plain_password: str, name: Union[str, None] = None -) -> schemas.User: +def create_user(db: Session, user_data: schemas.UserRegister) -> schemas.UserInDB: user = models.User( - username=username, - name=name, - hashed_password=get_password_hash(plain_password), + username=user_data.username, + name=user_data.name, + hashed_password=get_password_hash(user_data.password), ) db.add(user) db.commit() - return schemas.User(user) + return schemas.UserInDB( + username=user.username, name=user.name, hashed_password=user.hashed_password + ) async def get_current_user( diff --git a/backend/requirements.txt b/backend/requirements.txt index 0ac6f0c..126e36c 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -4,4 +4,4 @@ pydantic sqlalchemy psycopg2-binary python-jose[cryptography] -passlib[bcrypt] \ No newline at end of file +passlib[all] \ No newline at end of file diff --git a/dev.yml b/dev.yml index 6f7725c..f793d30 100644 --- a/dev.yml +++ b/dev.yml @@ -2,6 +2,7 @@ services: backend: build: context: backend + restart: unless-stopped ports: - "8000" env_file: @@ -15,6 +16,7 @@ services: frontend: build: context: frontend + restart: unless-stopped ports: - "3000" env_file: @@ -24,6 +26,7 @@ services: - ./frontend/app:/app:z nginx: image: nginx:1.25.4-alpine + restart: unless-stopped volumes: - ./nginx/dev.conf:/etc/nginx/conf.d/default.conf:ro - ./static:/static @@ -34,14 +37,17 @@ services: - "80:80" postgres: image: postgres:16.2-alpine - restart: always + restart: unless-stopped + ports: + - "5432:5432" volumes: - ./postgres_data:/var/lib/postgresql/data/ env_file: - path: ./env/postgres.env required: true healthcheck: - test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DB} --user ${POSTGRES_USER}"] + test: + ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} --user $${POSTGRES_USER}"] interval: 2s timeout: 2s retries: 5