Asking Telegram for an authentication code

This commit is contained in:
Sebastian J. Wolf 2020-08-13 10:15:26 +02:00
parent 6c4cb405b1
commit bd59896896
10 changed files with 445 additions and 4 deletions

View file

@ -20,6 +20,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
DISTFILES += qml/harbour-fernschreiber.qml \
qml/pages/CoverPage.qml \
qml/pages/InitializationPage.qml \
qml/pages/OverviewPage.qml \
qml/pages/AboutPage.qml \
rpm/harbour-fernschreiber.changes.in \

View file

@ -0,0 +1,267 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import Sailfish.Silica 1.0
Page {
id: initializationPage
allowedOrientations: Orientation.All
Column {
y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: pinErrorColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1 : 0
visible: false
Image {
id: fernschreiberErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
width: 1/2 * parent.width
}
InfoLabel {
id: errorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: ""
}
Button {
id: errorOkButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
pinErrorColumn.visible = false;
welcomeFlickable.visible = true;
}
}
}
Column {
y: ( parent.height - ( fernschreiberPinImage.height + enterPinLabel.height + enterPinField.height + enterPinButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: enterPinColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? true : false
visible: false
Image {
id: fernschreiberPinImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
width: 1/2 * parent.width
}
InfoLabel {
id: enterPinLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter the PIN that you received:")
}
TextField {
id: enterPinField
anchors {
horizontalCenter: parent.horizontalCenter
}
inputMethodHints: Qt.ImhDigitsOnly
font.pixelSize: Theme.fontSizeExtraLarge
width: parent.width - 4 * Theme.paddingLarge
horizontalAlignment: TextInput.AlignHCenter
}
Button {
id: enterPinButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
//accountModel.enterPin(enterPinField.text)
enterPinColumn.visible = false;
}
}
}
Column {
y: ( parent.height - ( fernschreiberLinkingErrorImage.height + linkingErrorInfoLabel.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: linkingErrorColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? true : false
visible: false
Image {
id: fernschreiberLinkingErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
width: 1/2 * parent.width
}
InfoLabel {
id: linkingErrorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Unable to authenticate you with the entered PIN.")
}
Button {
id: enterPinAgainButton
text: qsTr("Enter PIN again")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
enterPinColumn.visible = true;
}
}
Button {
id: restartAuthenticationButton
text: qsTr("Restart authentication")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
welcomeFlickable.visible = true;
}
}
}
SilicaFlickable {
id: welcomeFlickable
anchors.fill: parent
contentHeight: column.height
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1 : 0
// Connections {
// target: accountModel
// onPinRequestSuccessful: {
// console.log("URL: " + url)
// Qt.openUrlExternally(url)
// welcomeFlickable.visible = false
// enterPinColumn.visible = true
// }
// onPinRequestError: {
// errorInfoLabel.text = errorMessage
// welcomeFlickable.visible = false
// pinErrorColumn.visible = true
// console.log("Error Message: " + errorMessage)
// }
// onLinkingSuccessful: {
// console.log("Linking successful, moving on to my tweets...")
// pageStack.clear()
// pageStack.push(overviewPage)
// }
// onLinkingFailed: {
// enterPinColumn.visible = false
// linkingErrorColumn.visible = true
// console.log("Linking error, proceeding to error page!")
// }
// }
Column {
id: column
width: parent.width
spacing: Theme.paddingLarge
PageHeader {
title: qsTr("Welcome to Fernschreiber!")
}
Image {
id: fernschreiberImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
width: 1/2 * parent.width
}
Label {
wrapMode: Text.Wrap
x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin )
horizontalAlignment: Text.AlignHCenter
text: qsTr("Please enter your phone number to continue.")
font.pixelSize: Theme.fontSizeMedium
anchors {
horizontalCenter: parent.horizontalCenter
}
}
TextField {
id: phoneNumberTextField
placeholderText: "Use the international format, e.g. +4912342424242"
inputMethodHints: Qt.ImhDialableCharactersOnly
labelVisible: false
width: parent.width
}
Button {
text: qsTr("Continue")
anchors {
horizontalCenter: parent.horizontalCenter
}
enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g)
onClicked: {
tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text);
}
}
Label {
id: separatorLabelPhoneNumber
x: Theme.horizontalPageMargin
width: parent.width - ( 2 * Theme.horizontalPageMargin )
font.pixelSize: Theme.fontSizeExtraSmall
anchors {
horizontalCenter: parent.horizontalCenter
}
}
}
}
}

View file

@ -21,16 +21,40 @@ import QtGraphicalEffects 1.0
import QtMultimedia 5.0
import Sailfish.Silica 1.0
import Nemo.Notifications 1.0
import WerkWolf.Fernschreiber 1.0
Page {
id: overviewPage
allowedOrientations: Orientation.All
property bool loading: true;
BusyLabel {
text: qsTr("Loading...")
running: overviewPage.loading
}
Connections {
target: tdLibWrapper
onAuthorizationStateChanged: {
switch (authorizationState) {
case TelegramAPI.WaitPhoneNumber:
overviewPage.loading = false;
pageStack.clear();
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
default:
// Nothing ;)
}
}
}
SilicaFlickable {
id: aboutContainer
contentHeight: column.height
anchors.fill: parent
visible: !overviewPage.loading
PullDownMenu {
MenuItem {

View file

@ -40,6 +40,7 @@ int main(int argc, char *argv[])
TDLibWrapper tdLibWrapper;
context->setContextProperty("tdLibWrapper", &tdLibWrapper);
qmlRegisterType<TDLibWrapper>("WerkWolf.Fernschreiber", 1, 0, "TelegramAPI");
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
view->show();

View file

@ -1,3 +1,21 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdlibreceiver.h"
TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(parent)

View file

@ -1,3 +1,21 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDLIBRECEIVER_H
#define TDLIBRECEIVER_H

View file

@ -76,6 +76,19 @@ TDLibWrapper::ConnectionState TDLibWrapper::getConnectionState()
return this->connectionState;
}
void TDLibWrapper::setAuthenticationPhoneNumber(const QString &phoneNumber)
{
qDebug() << "[TDLibWrapper] Set authentication phone number " << phoneNumber;
QVariantMap requestObject;
requestObject.insert("@type", "setAuthenticationPhoneNumber");
requestObject.insert("phone_number", phoneNumber);
QVariantMap phoneNumberSettings;
phoneNumberSettings.insert("allow_flash_call", false);
phoneNumberSettings.insert("is_current_phone_number", true);
requestObject.insert("settings", phoneNumberSettings);
this->sendRequest(requestObject);
}
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;
@ -97,7 +110,7 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS
}
if (authorizationState == "authorizationStateReady") {
this->authorizationState = AuthorizationState::Ready;
this->authorizationState = AuthorizationState::AuthorizationReady;
}
if (authorizationState == "authorizationStateWaitCode") {
@ -149,7 +162,7 @@ void TDLibWrapper::handleConnectionStateChanged(const QString &connectionState)
this->connectionState = ConnectionState::ConnectingToProxy;
}
if (connectionState == "connectionStateReady") {
this->connectionState = ConnectionState::IsReady;
this->connectionState = ConnectionState::ConnectionReady;
}
if (connectionState == "connectionStateUpdating") {
this->connectionState = ConnectionState::Updating;

View file

@ -1,3 +1,21 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
This file is part of Fernschreiber.
fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDLIBWRAPPER_H
#define TDLIBWRAPPER_H
@ -20,7 +38,7 @@ public:
Closed,
Closing,
LoggingOut,
Ready,
AuthorizationReady,
WaitCode,
WaitEncryptionKey,
WaitOtherDeviceConfirmation,
@ -29,19 +47,22 @@ public:
WaitRegistration,
WaitTdlibParameters
};
Q_ENUM(AuthorizationState)
enum ConnectionState {
Connecting,
ConnectingToProxy,
IsReady,
ConnectionReady,
Updating,
WaitingForNetwork
};
Q_ENUM(ConnectionState)
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
Q_INVOKABLE QString getVersion();
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
signals:
void versionDetected(const QString &version);

View file

@ -60,6 +60,41 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>InitializationPage</name>
<message>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter the PIN that you received:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to authenticate you with the entered PIN.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter PIN again</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Restart authentication</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Welcome to Fernschreiber!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter your phone number to continue.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Continue</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>
<message>
@ -70,5 +105,9 @@
<source>Welcome to Fernschreiber</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -60,6 +60,41 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>InitializationPage</name>
<message>
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter the PIN that you received:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to authenticate you with the entered PIN.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter PIN again</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Restart authentication</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Welcome to Fernschreiber!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter your phone number to continue.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Continue</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>
<message>
@ -70,5 +105,9 @@
<source>Welcome to Fernschreiber</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>