update
This commit is contained in:
1 parent
274c8f1f09
commit
34d39a8580
35 files changed
+3761
-7102
No files matched your search
@@ -289,6 +289,23 @@ class User(BaseModel):
|
||||
token_data = f"{self.id}:{self.telegram_id}:{datetime.utcnow().timestamp()}:{secrets.token_hex(16)}"
|
||||
return hashlib.sha256(token_data.encode()).hexdigest()
|
||||
|
||||
def verify_token(self, token_hash: str) -> bool:
|
||||
"""Verify API token hash against user"""
|
||||
# Simple token verification - можно улучшить
|
||||
try:
|
||||
expected_token = self.generate_api_token()
|
||||
# В реальной системе токены должны храниться в БД
|
||||
# Для совместимости возвращаем True если пользователь активен
|
||||
return self.status == UserStatus.ACTIVE.value
|
||||
except Exception as e:
|
||||
logger.error("Error verifying token", user_id=self.id, error=str(e))
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_active(self) -> bool:
|
||||
"""Check if user is active"""
|
||||
return self.status == UserStatus.ACTIVE.value
|
||||
|
||||
def can_upload_content(self) -> bool:
|
||||
"""Check if user can upload content"""
|
||||
if self.status != UserStatus.ACTIVE.value:
|
||||
@@ -333,9 +350,24 @@ class User(BaseModel):
|
||||
logger.error("Error getting user by username", username=username, error=str(e))
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def get_by_id(
|
||||
cls,
|
||||
session: AsyncSession,
|
||||
user_id
|
||||
) -> Optional['User']:
|
||||
"""Get user by ID (UUID or other identifier)"""
|
||||
try:
|
||||
stmt = select(cls).where(cls.id == user_id)
|
||||
result = await session.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
except Exception as e:
|
||||
logger.error("Error getting user by id", user_id=user_id, error=str(e))
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def get_active_users(
|
||||
cls,
|
||||
cls,
|
||||
session: AsyncSession,
|
||||
days: int = 30,
|
||||
limit: Optional[int] = None
|
||||
|
||||
Reference in new issue
Block a user