This commit is contained in:
@@ -81,20 +81,20 @@ class Author(Base):
|
||||
"""Проверяет пароль пользователя"""
|
||||
return Password.verify(password, str(self.password)) if self.password else False
|
||||
|
||||
def set_password(self, password: str):
|
||||
def set_password(self, password: str) -> None:
|
||||
"""Устанавливает пароль пользователя"""
|
||||
self.password = Password.encode(password) # type: ignore[assignment]
|
||||
self.password = Password.encode(password)
|
||||
|
||||
def increment_failed_login(self):
|
||||
def increment_failed_login(self) -> None:
|
||||
"""Увеличивает счетчик неудачных попыток входа"""
|
||||
self.failed_login_attempts += 1 # type: ignore[assignment]
|
||||
self.failed_login_attempts += 1
|
||||
if self.failed_login_attempts >= 5:
|
||||
self.account_locked_until = int(time.time()) + 300 # type: ignore[assignment] # 5 минут
|
||||
self.account_locked_until = int(time.time()) + 300 # 5 минут
|
||||
|
||||
def reset_failed_login(self):
|
||||
def reset_failed_login(self) -> None:
|
||||
"""Сбрасывает счетчик неудачных попыток входа"""
|
||||
self.failed_login_attempts = 0 # type: ignore[assignment]
|
||||
self.account_locked_until = None # type: ignore[assignment]
|
||||
self.failed_login_attempts = 0
|
||||
self.account_locked_until = None
|
||||
|
||||
def is_locked(self) -> bool:
|
||||
"""Проверяет, заблокирован ли аккаунт"""
|
||||
@@ -150,7 +150,7 @@ class Author(Base):
|
||||
authors = session.query(cls).where(cls.oauth.isnot(None)).all()
|
||||
for author in authors:
|
||||
if author.oauth and provider in author.oauth:
|
||||
oauth_data = author.oauth[provider] # type: ignore[index]
|
||||
oauth_data = author.oauth[provider]
|
||||
if isinstance(oauth_data, dict) and oauth_data.get("id") == provider_id:
|
||||
return author
|
||||
return None
|
||||
@@ -165,13 +165,13 @@ class Author(Base):
|
||||
email (Optional[str]): Email от провайдера
|
||||
"""
|
||||
if not self.oauth:
|
||||
self.oauth = {} # type: ignore[assignment]
|
||||
self.oauth = {}
|
||||
|
||||
oauth_data: Dict[str, str] = {"id": provider_id}
|
||||
if email:
|
||||
oauth_data["email"] = email
|
||||
|
||||
self.oauth[provider] = oauth_data # type: ignore[index]
|
||||
self.oauth[provider] = oauth_data
|
||||
|
||||
def get_oauth_account(self, provider: str) -> Dict[str, Any] | None:
|
||||
"""
|
||||
|
||||
@@ -227,19 +227,19 @@ class Community(BaseModel):
|
||||
|
||||
members = []
|
||||
for ca in community_authors:
|
||||
member_info = {
|
||||
member_info: dict[str, Any] = {
|
||||
"author_id": ca.author_id,
|
||||
"joined_at": ca.joined_at,
|
||||
}
|
||||
|
||||
if with_roles:
|
||||
member_info["roles"] = ca.role_list # type: ignore[assignment]
|
||||
member_info["roles"] = ca.role_list
|
||||
# Получаем разрешения синхронно
|
||||
try:
|
||||
member_info["permissions"] = asyncio.run(ca.get_permissions()) # type: ignore[assignment]
|
||||
member_info["permissions"] = asyncio.run(ca.get_permissions())
|
||||
except Exception:
|
||||
# Если не удается получить разрешения асинхронно, используем пустой список
|
||||
member_info["permissions"] = [] # type: ignore[assignment]
|
||||
member_info["permissions"] = []
|
||||
|
||||
members.append(member_info)
|
||||
|
||||
@@ -275,9 +275,9 @@ class Community(BaseModel):
|
||||
roles: Список ID ролей для назначения по умолчанию
|
||||
"""
|
||||
if not self.settings:
|
||||
self.settings = {} # type: ignore[assignment]
|
||||
self.settings = {}
|
||||
|
||||
self.settings["default_roles"] = roles # type: ignore[index]
|
||||
self.settings["default_roles"] = roles
|
||||
|
||||
async def initialize_role_permissions(self) -> None:
|
||||
"""
|
||||
@@ -307,13 +307,13 @@ class Community(BaseModel):
|
||||
roles: Список ID ролей, доступных в сообществе
|
||||
"""
|
||||
if not self.settings:
|
||||
self.settings = {} # type: ignore[assignment]
|
||||
self.settings = {}
|
||||
|
||||
self.settings["available_roles"] = roles # type: ignore[index]
|
||||
self.settings["available_roles"] = roles
|
||||
|
||||
def set_slug(self, slug: str) -> None:
|
||||
"""Устанавливает slug сообщества"""
|
||||
self.slug = slug # type: ignore[assignment]
|
||||
self.update({"slug": slug})
|
||||
|
||||
def get_followers(self):
|
||||
"""
|
||||
@@ -420,7 +420,7 @@ class CommunityAuthor(BaseModel):
|
||||
@role_list.setter
|
||||
def role_list(self, value: list[str]) -> None:
|
||||
"""Устанавливает список ролей из списка строк"""
|
||||
self.roles = ",".join(value) if value else None # type: ignore[assignment]
|
||||
self.update({"roles": ",".join(value) if value else None})
|
||||
|
||||
def add_role(self, role: str) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user