+ проверка срока жизни токена

This commit is contained in:
2026-02-11 06:58:55 +03:00
parent 39f0c447c1
commit 47c0c7ed85
4 changed files with 130 additions and 8 deletions
+26 -5
View File
@@ -87,7 +87,13 @@ void TAuth::handleNewConnection()
connect(m_clientSocket, &QTcpSocket::readyRead,
this, &TAuth::readClientData);
connect(m_clientSocket, &QTcpSocket::disconnected,
m_clientSocket, &QTcpSocket::deleteLater);
this, [this]() {
// Удаляем сокет после отключения
if (m_clientSocket) {
m_clientSocket->deleteLater();
m_clientSocket = nullptr;
}
});
}
}
@@ -98,7 +104,6 @@ void TAuth::readClientData()
QByteArray requestData = m_clientSocket->readAll();
QString request = QString::fromUtf8(requestData);
QStringList lines = request.split("\r\n");
if (lines.isEmpty()) return;
@@ -118,7 +123,6 @@ void TAuth::readClientData()
}
}
// Обрабатываем обычный redirect
if (document.startsWith("/redirect")) {
handleRedirectRequest(document, m_clientSocket);
@@ -237,6 +241,13 @@ void TAuth::handleRedirectRequest(const QString &request, QTcpSocket *socket)
"<h2>Authorization Successful!</h2>\n"
"<p>Token received. You can close this window.</p>\n"
"</body>\n</html>";
// Отправляем ответ клиенту
sendResponse(socket, html);
// Останавливаем сервер СРАЗУ
QTimer::singleShot(100, this, &TAuth::stopServer);
return;
}
// Проверяем наличие error_description
else if (params.contains("error_description=")) {
@@ -260,6 +271,13 @@ void TAuth::handleRedirectRequest(const QString &request, QTcpSocket *socket)
"<h2>Authorization Successful!</h2>\n"
"<p>Code received. You can close this window.</p>\n"
"</body>\n</html>";
// Отправляем ответ клиенту
sendResponse(socket, html);
// Останавливаем сервер СРАЗУ
QTimer::singleShot(100, this, &TAuth::stopServer);
return;
}
else {
html =
@@ -269,13 +287,16 @@ void TAuth::handleRedirectRequest(const QString &request, QTcpSocket *socket)
"<p>Try again or check your authorization URL.</p>\n"
"</body>\n</html>";
sendResponse(socket, html);
// Останавливаем сервер через 5 секунд если нет данных
QTimer::singleShot(5000, this, &TAuth::stopServer);
return;
}
sendResponse(socket, html);
// Останавливаем сервер после обработки
QTimer::singleShot(1000, this, &TAuth::stopServer);
// Останавливаем сервер через 5 секунд для других случаев
QTimer::singleShot(5000, this, &TAuth::stopServer);
}
QString TAuth::extractParam(const QString &params, const QString &paramName)