Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fee8dfb7ec | |||
| 6ef7c0c9e9 |
@ -13,9 +13,6 @@ class UsersRepository:
|
||||
def get_by_id(self, user_id: int):
|
||||
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):
|
||||
return self.db.query(User).filter(User.login == login).first()
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ from sqlalchemy.orm import Session
|
||||
from app.application.answer_files_repository import AnswerFilesRepository
|
||||
from app.database.dependencies import get_db
|
||||
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()
|
||||
|
||||
@ -14,7 +14,8 @@ router = APIRouter()
|
||||
@router.get("/answer_files/", response_model=List[AnswerFileEntity])
|
||||
def get_answer_files(
|
||||
db: Session = Depends(get_db),
|
||||
user=Depends(require_admin),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
answer_files_service = AnswerFilesRepository(db)
|
||||
return answer_files_service.get_all()
|
||||
|
||||
|
||||
@ -4,13 +4,12 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.database.dependencies import get_db
|
||||
from app.domain.entities.auth_entity import AuthEntity
|
||||
from app.domain.entities.token_entity import TokenEntity
|
||||
from app.infrastructure.auth_service import AuthService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/login/", response_model=TokenEntity)
|
||||
@router.get("/login/", response_model=dict)
|
||||
def login(
|
||||
auth_data: AuthEntity,
|
||||
db: Session = Depends(get_db)
|
||||
|
||||
@ -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
|
||||
@ -1,12 +1,11 @@
|
||||
import jwt
|
||||
from fastapi import Depends, HTTPException, Security
|
||||
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.database.dependencies import get_db
|
||||
from sqlalchemy.orm import Session
|
||||
from app.settings import get_auth_data
|
||||
|
||||
security = HTTPBearer()
|
||||
|
||||
@ -15,28 +14,23 @@ def get_current_user(
|
||||
credentials: HTTPAuthorizationCredentials = Security(security),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
token = credentials.credentials
|
||||
auth_data = get_auth_data()
|
||||
|
||||
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"]])
|
||||
user_id = payload.get("user_id")
|
||||
|
||||
if user_id is None:
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
||||
user = UsersRepository(db).get_by_id(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="User not found")
|
||||
|
||||
return user
|
||||
|
||||
except jwt.ExpiredSignatureError:
|
||||
raise HTTPException(status_code=401, detail="Token has expired")
|
||||
raise HTTPException(status_code=401, detail="Token expired")
|
||||
except jwt.InvalidTokenError:
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
||||
user_id = payload.get("user_id")
|
||||
if user_id is None:
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
||||
user = UsersRepository(db).get_by_id_with_role(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="User not found")
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def require_admin(user: User = Depends(get_current_user)):
|
||||
if user.role.title != "Администратор":
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
|
||||
return user
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<background android:drawable="@mipmap/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
|
||||
</adaptive-icon>
|
||||
BIN
Mobile/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
BIN
Mobile/app/src/main/res/mipmap-hdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 854 B |
BIN
Mobile/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
Mobile/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
Mobile/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 982 B |
BIN
Mobile/app/src/main/res/mipmap-mdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 462 B |
BIN
Mobile/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
Mobile/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
Mobile/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
BIN
Mobile/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
Mobile/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
Mobile/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Mobile/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
BIN
Mobile/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
Mobile/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
Mobile/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
Mobile/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 12 KiB |