From 815bb5d592b77e94d172c1a51254ce15cd470581 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Wed, 16 Sep 2020 22:36:43 +0200 Subject: [PATCH] Prepare two-step authentication --- qml/pages/InitializationPage.qml | 64 ++++++++++++++++++++++++++++++++ qml/pages/OverviewPage.qml | 4 ++ src/tdlibwrapper.cpp | 9 +++++ src/tdlibwrapper.h | 1 + 4 files changed, 78 insertions(+) diff --git a/qml/pages/InitializationPage.qml b/qml/pages/InitializationPage.qml index d52f912..ef609de 100644 --- a/qml/pages/InitializationPage.qml +++ b/qml/pages/InitializationPage.qml @@ -39,6 +39,12 @@ Page { if (initializationPage.authorizationState === TelegramAPI.WaitCode) { welcomeFlickable.visible = false; enterPinColumn.visible = true; + enterPasswordColumn.visible = false; + } + if (initializationPage.authorizationState === TelegramAPI.WaitPassword) { + welcomeFlickable.visible = false; + enterPinColumn.visible = false; + enterPasswordColumn.visible = true; } } @@ -49,6 +55,12 @@ Page { case TelegramAPI.WaitCode: initializationPage.loading = false; enterPinColumn.visible = true; + enterPasswordColumn.visible = false; + break; + case TelegramAPI.WaitPassword: + initializationPage.loading = false; + enterPinColumn.visible = false; + enterPasswordColumn.visible = true; break; case TelegramAPI.AuthorizationReady: initializationPage.loading = false; @@ -102,6 +114,58 @@ Page { } } + Column { + y: ( parent.height - ( fernschreiberPasswordImage.height + enterPasswordLabel.height + enterPasswordField.height + enterPasswordButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2 + width: parent.width + id: enterPasswordColumn + spacing: Theme.paddingSmall + + Behavior on opacity { NumberAnimation {} } + opacity: visible ? true : false + visible: false + + Image { + id: fernschreiberPasswordImage + source: "../../images/fernschreiber.png" + anchors { + horizontalCenter: parent.horizontalCenter + } + + fillMode: Image.PreserveAspectFit + asynchronous: true + width: 1/2 * parent.width + } + + InfoLabel { + id: enterPasswordLabel + font.pixelSize: Theme.fontSizeLarge + text: qsTr("Please enter your password:") + } + + TextField { + id: enterPasswordField + anchors { + horizontalCenter: parent.horizontalCenter + } + font.pixelSize: Theme.fontSizeLarge + width: parent.width - 2 * Theme.horizontalPageMargin + horizontalAlignment: TextInput.AlignHCenter + } + + Button { + id: enterPasswordButton + text: qsTr("OK") + anchors { + horizontalCenter: parent.horizontalCenter + } + onClicked: { + initializationPage.loading = true; + enterPasswordColumn.visible = false; + tdLibWrapper.setAuthenticationPassword(enterPasswordField.text); + } + } + } + Column { y: ( parent.height - ( fernschreiberPinImage.height + enterPinLabel.height + enterPinField.height + enterPinButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2 width: parent.width diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index f866ec7..9a86433 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -113,6 +113,10 @@ Page { overviewPage.loading = false; pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); break; + case TelegramAPI.WaitPassword: + overviewPage.loading = false; + pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); + break; case TelegramAPI.AuthorizationReady: overviewPage.loading = false; overviewPage.initializationCompleted = true; diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index d20e64e..70ce3fd 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -132,6 +132,15 @@ void TDLibWrapper::setAuthenticationCode(const QString &authenticationCode) this->sendRequest(requestObject); } +void TDLibWrapper::setAuthenticationPassword(const QString &authenticationPassword) +{ + qDebug() << "[TDLibWrapper] Set authentication password " << authenticationPassword; + QVariantMap requestObject; + requestObject.insert("@type", "checkAuthenticationPassword"); + requestObject.insert("password", authenticationPassword); + this->sendRequest(requestObject); +} + void TDLibWrapper::getChats() { qDebug() << "[TDLibWrapper] Getting chats"; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index c58e65a..42302bd 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -83,6 +83,7 @@ public: Q_INVOKABLE void sendRequest(const QVariantMap &requestObject); Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber); Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); + Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword); Q_INVOKABLE void getChats(); Q_INVOKABLE void downloadFile(const QString &fileId); Q_INVOKABLE void openChat(const QString &chatId);