Compare commits

..

2 Commits

Author SHA1 Message Date
fee8dfb7ec Добавила логотип 2025-02-09 18:32:49 +05:00
6ef7c0c9e9 Добавила логотип 2025-02-09 18:27:30 +05:00
32 changed files with 24 additions and 44 deletions

View File

@ -13,9 +13,6 @@ class UsersRepository:
def get_by_id(self, user_id: int): def get_by_id(self, user_id: int):
return self.db.query(User).filter(User.id == user_id).first() return self.db.query(User).filter(User.id == user_id).first()
def get_by_id_with_role(self, user_id: int):
return self.db.query(User).filter(User.id == user_id).join(User.role).first()
def get_by_login(self, login: str): def get_by_login(self, login: str):
return self.db.query(User).filter(User.login == login).first() return self.db.query(User).filter(User.login == login).first()

View File

@ -6,7 +6,7 @@ from sqlalchemy.orm import Session
from app.application.answer_files_repository import AnswerFilesRepository from app.application.answer_files_repository import AnswerFilesRepository
from app.database.dependencies import get_db from app.database.dependencies import get_db
from app.domain.entities.answer_files_entitity import AnswerFileEntity from app.domain.entities.answer_files_entitity import AnswerFileEntity
from app.infrastructure.dependencies import require_admin from app.infrastructure.dependencies import get_current_user
router = APIRouter() router = APIRouter()
@ -14,7 +14,8 @@ router = APIRouter()
@router.get("/answer_files/", response_model=List[AnswerFileEntity]) @router.get("/answer_files/", response_model=List[AnswerFileEntity])
def get_answer_files( def get_answer_files(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user=Depends(require_admin), user=Depends(get_current_user),
): ):
answer_files_service = AnswerFilesRepository(db) answer_files_service = AnswerFilesRepository(db)
return answer_files_service.get_all() return answer_files_service.get_all()

View File

@ -4,13 +4,12 @@ from sqlalchemy.orm import Session
from app.database.dependencies import get_db from app.database.dependencies import get_db
from app.domain.entities.auth_entity import AuthEntity from app.domain.entities.auth_entity import AuthEntity
from app.domain.entities.token_entity import TokenEntity
from app.infrastructure.auth_service import AuthService from app.infrastructure.auth_service import AuthService
router = APIRouter() router = APIRouter()
@router.post("/login/", response_model=TokenEntity) @router.get("/login/", response_model=dict)
def login( def login(
auth_data: AuthEntity, auth_data: AuthEntity,
db: Session = Depends(get_db) db: Session = Depends(get_db)

View File

@ -1,11 +0,0 @@
from typing import Optional
from pydantic import BaseModel
class TokenEntity(BaseModel):
access_token: str
user_id: int
class Config:
from_attributes = True

View File

@ -1,12 +1,11 @@
import jwt
from fastapi import Depends, HTTPException, Security from fastapi import Depends, HTTPException, Security
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
import jwt from sqlalchemy.orm import Session
from app.domain.models.users import User
from app.settings import get_auth_data
from app.application.users_repository import UsersRepository from app.application.users_repository import UsersRepository
from app.database.dependencies import get_db from app.database.dependencies import get_db
from sqlalchemy.orm import Session from app.settings import get_auth_data
security = HTTPBearer() security = HTTPBearer()
@ -15,28 +14,23 @@ def get_current_user(
credentials: HTTPAuthorizationCredentials = Security(security), credentials: HTTPAuthorizationCredentials = Security(security),
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
token = credentials.credentials
auth_data = get_auth_data() auth_data = get_auth_data()
try: try:
payload = jwt.decode(credentials.credentials, auth_data["secret_key"], algorithms=[auth_data["algorithm"]]) payload = jwt.decode(token, auth_data["secret_key"], algorithms=[auth_data["algorithm"]])
except jwt.ExpiredSignatureError:
raise HTTPException(status_code=401, detail="Token has expired")
except jwt.InvalidTokenError:
raise HTTPException(status_code=401, detail="Invalid token")
user_id = payload.get("user_id") user_id = payload.get("user_id")
if user_id is None: if user_id is None:
raise HTTPException(status_code=401, detail="Invalid token") raise HTTPException(status_code=401, detail="Invalid token")
user = UsersRepository(db).get_by_id_with_role(user_id) user = UsersRepository(db).get_by_id(user_id)
if user is None: if user is None:
raise HTTPException(status_code=401, detail="User not found") raise HTTPException(status_code=401, detail="User not found")
return user return user
except jwt.ExpiredSignatureError:
def require_admin(user: User = Depends(get_current_user)): raise HTTPException(status_code=401, detail="Token expired")
if user.role.title != "Администратор": except jwt.InvalidTokenError:
raise HTTPException(status_code=403, detail="Access denied") raise HTTPException(status_code=401, detail="Invalid token")
return user

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" /> <background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground" /> <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_foreground" /> <monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
</adaptive-icon> </adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB