Add Banned role
This commit is contained in:
@@ -123,7 +123,13 @@ def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(securit
|
||||
if username not in users:
|
||||
raise HTTPException(status_code=401, detail="Пользователь не найден")
|
||||
|
||||
return users[username]
|
||||
user = users[username]
|
||||
|
||||
# Проверка на бан
|
||||
if user.get("role") == "banned":
|
||||
raise HTTPException(status_code=403, detail="Ваш аккаунт заблокирован")
|
||||
|
||||
return user
|
||||
except JWTError:
|
||||
raise HTTPException(status_code=401, detail="Неверный токен")
|
||||
|
||||
@@ -266,7 +272,7 @@ async def update_user_role(username: str, data: dict, user: dict = Depends(get_c
|
||||
raise HTTPException(404, "Пользователь не найден")
|
||||
|
||||
new_role = data.get("role")
|
||||
if new_role not in ["admin", "user", "support"]:
|
||||
if new_role not in ["admin", "user", "support", "banned"]:
|
||||
raise HTTPException(400, "Неверная роль")
|
||||
|
||||
users[username]["role"] = new_role
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"arkonsad": {
|
||||
"username": "arkonsad",
|
||||
"password": "$2b$12$z.AYkfa/MlTYFd9rLNfBmu9JHOFKUe8YdddnqCmRqAxc7vGQeo392",
|
||||
"role": "user",
|
||||
"role": "banned",
|
||||
"servers": [
|
||||
"123"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user