Prepare two-step authentication

This commit is contained in:
Sebastian J. Wolf 2020-09-16 22:36:43 +02:00
parent 4d573f1f43
commit 815bb5d592
4 changed files with 78 additions and 0 deletions

View file

@ -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

View file

@ -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;

View file

@ -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";

View file

@ -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);