omni / auth.py
yash184's picture
Create auth.py
ec09ba4 verified
Raw
History Blame Contribute Delete
1.2 kB
from session_manager import SessionManager
from config import settings
class AuthManager:
def __init__(self):
self.session_manager = SessionManager()
def login(self):
"""Guides the user through the initial Telethon login flow."""
print("\n--- Telegram Authentication Flow ---")
# Connect attempts to start the flow if the session is missing
success = self.session_manager.connect()
if success:
print("\nAuthentication successful. Client is ready.")
return True
else:
print("\nAuthentication failed.")
return False
def logout(self):
"""Disconnects the Telethon session."""
self.session_manager.disconnect()
return True
def check_session(self):
"""Checks if the session is currently valid (by attempting a lightweight check)."""
if self.session_manager.is_connected:
print("Session status: ✅ Active.")
return True
else:
print("Session status: ❌ Inactive. Reconnecting...")
self.session_manager.connect()
return self.session_manager.is_connected