-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from tigran-saatchyan/features/26-authenticate…
…-and-authorize [FEATURE] Added authentication and auuthorization - #26
- Loading branch information
Showing
34 changed files
with
927 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# TODO @Tigran_Saatchyan: refactor pattern of this package to | ||
# implements correct versioning of API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from fastapi import FastAPI | ||
from fastapi_users import FastAPIUsers | ||
|
||
from app.models import User | ||
from app.schemas.users import UserCreate, UserRead, UserUpdate | ||
from app.services.managers import get_user_manager | ||
from app.settings.auth import auth_backend | ||
|
||
PREFIX = "/api/v1" | ||
AUTH_TAG = "Authication" | ||
|
||
|
||
fastapi_users = FastAPIUsers[User, int]( | ||
get_user_manager, | ||
[auth_backend], | ||
) | ||
|
||
|
||
def set_up_auth_routes(application: FastAPI): | ||
application.include_router( | ||
fastapi_users.get_auth_router(auth_backend), | ||
prefix=f"{PREFIX}/jwt", | ||
tags=[AUTH_TAG], | ||
) | ||
application.include_router( | ||
fastapi_users.get_register_router(UserRead, UserCreate), | ||
prefix=PREFIX, | ||
tags=[AUTH_TAG], | ||
) | ||
application.include_router( | ||
fastapi_users.get_users_router(UserRead, UserUpdate), | ||
prefix="/users", | ||
tags=["Users"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
from app.api.v1.products import router as product_router | ||
from app.api.v1.users import router as user_router | ||
|
||
all_routers = [ | ||
product_router, | ||
user_router, | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from app.db.db import Base | ||
|
||
__all__ = [ | ||
"Base", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/migrations/versions/1aeee680cc4d_removed_password_salt_field.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""removed password_salt field | ||
Revision ID: 1aeee680cc4d | ||
Revises: 64ad69e55ba4 | ||
Create Date: 2023-11-15 14:43:08.233170+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '1aeee680cc4d' | ||
down_revision: Union[str, None] = '64ad69e55ba4' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.REAL(), | ||
type_=sa.Float(precision=2), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
op.drop_column('users', 'password_salt') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('users', sa.Column('password_salt', postgresql.BYTEA(), autoincrement=False, nullable=False)) | ||
op.alter_column('products', 'price', | ||
existing_type=sa.Float(precision=2), | ||
type_=sa.REAL(), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### |
38 changes: 38 additions & 0 deletions
38
app/migrations/versions/39ccc998471c_updated_last_login.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""updated last_login | ||
Revision ID: 39ccc998471c | ||
Revises: 1aeee680cc4d | ||
Create Date: 2023-11-15 14:56:26.586220+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '39ccc998471c' | ||
down_revision: Union[str, None] = '1aeee680cc4d' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.REAL(), | ||
type_=sa.Float(precision=2), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.Float(precision=2), | ||
type_=sa.REAL(), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### |
46 changes: 46 additions & 0 deletions
46
app/migrations/versions/49af15ac2ace_updated_last_login.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""updated last_login | ||
Revision ID: 49af15ac2ace | ||
Revises: 39ccc998471c | ||
Create Date: 2023-11-15 14:59:34.457751+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '49af15ac2ace' | ||
down_revision: Union[str, None] = '39ccc998471c' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.REAL(), | ||
type_=sa.Float(precision=2), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
op.alter_column('users', 'last_login', | ||
existing_type=postgresql.TIMESTAMP(), | ||
type_=sa.TIMESTAMP(timezone=True), | ||
nullable=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('users', 'last_login', | ||
existing_type=sa.TIMESTAMP(timezone=True), | ||
type_=postgresql.TIMESTAMP(), | ||
nullable=True) | ||
op.alter_column('products', 'price', | ||
existing_type=sa.Float(precision=2), | ||
type_=sa.REAL(), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### |
40 changes: 40 additions & 0 deletions
40
app/migrations/versions/541102dacd00_updated_users_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""updated Users table | ||
Revision ID: 541102dacd00 | ||
Revises: 95adae9f1847 | ||
Create Date: 2023-11-15 13:11:34.194328+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '541102dacd00' | ||
down_revision: Union[str, None] = '95adae9f1847' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.REAL(), | ||
type_=sa.Float(precision=2), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
op.drop_column('users', 'is_staff') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('users', sa.Column('is_staff', sa.BOOLEAN(), autoincrement=False, nullable=False)) | ||
op.alter_column('products', 'price', | ||
existing_type=sa.Float(precision=2), | ||
type_=sa.REAL(), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### |
46 changes: 46 additions & 0 deletions
46
app/migrations/versions/64ad69e55ba4_updated_password_hash_field_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""updated password_hash field type | ||
Revision ID: 64ad69e55ba4 | ||
Revises: 541102dacd00 | ||
Create Date: 2023-11-15 14:42:09.902416+04:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '64ad69e55ba4' | ||
down_revision: Union[str, None] = '541102dacd00' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('products', 'price', | ||
existing_type=sa.REAL(), | ||
type_=sa.Float(precision=2), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
op.alter_column('users', 'hashed_password', | ||
existing_type=postgresql.BYTEA(), | ||
type_=sa.String(length=1024), | ||
existing_nullable=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('users', 'hashed_password', | ||
existing_type=sa.String(length=1024), | ||
type_=postgresql.BYTEA(), | ||
existing_nullable=False) | ||
op.alter_column('products', 'price', | ||
existing_type=sa.Float(precision=2), | ||
type_=sa.REAL(), | ||
existing_nullable=False, | ||
existing_server_default=sa.text("'0'::real")) | ||
# ### end Alembic commands ### |
Oops, something went wrong.