First successful authentication, yeah! :)

This commit is contained in:
Sebastian J. Wolf 2020-08-13 15:35:43 +02:00
parent bd59896896
commit 6b68d8a276
6 changed files with 119 additions and 64 deletions

View file

@ -18,11 +18,48 @@
*/
import QtQuick 2.2
import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0
Page {
id: initializationPage
allowedOrientations: Orientation.All
property bool loading: true
property int authorizationState: TelegramAPI.Closed
BusyLabel {
text: qsTr("Loading...")
running: initializationPage.loading
}
Component.onCompleted: {
initializationPage.authorizationState = tdLibWrapper.getAuthorizationState();
initializationPage.loading = false;
if (initializationPage.authorizationState === TelegramAPI.WaitCode) {
welcomeFlickable.visible = false;
enterPinColumn.visible = true;
}
}
Connections {
target: tdLibWrapper
onAuthorizationStateChanged: {
switch (authorizationState) {
case TelegramAPI.WaitCode:
initializationPage.loading = false;
enterPinColumn.visible = true;
break;
case TelegramAPI.AuthorizationReady:
overviewPage.loading = false;
pageStack.clear();
pageStack.push(Qt.resolvedUrl("../pages/OverviewPage.qml"));
break;
default:
// Nothing ;)
}
}
}
Column {
y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
@ -87,7 +124,7 @@ Page {
InfoLabel {
id: enterPinLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter the PIN that you received:")
text: qsTr("Please enter the code that you received:")
}
TextField {
@ -108,8 +145,9 @@ Page {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
//accountModel.enterPin(enterPinField.text)
initializationPage.loading = true;
enterPinColumn.visible = false;
tdLibWrapper.setAuthenticationCode(enterPinField.text);
}
}
}
@ -138,12 +176,12 @@ Page {
InfoLabel {
id: linkingErrorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Unable to authenticate you with the entered PIN.")
text: qsTr("Unable to authenticate you with the entered code.")
}
Button {
id: enterPinAgainButton
text: qsTr("Enter PIN again")
text: qsTr("Enter code again")
anchors {
horizontalCenter: parent.horizontalCenter
}
@ -169,38 +207,12 @@ Page {
SilicaFlickable {
id: welcomeFlickable
anchors.fill: parent
contentHeight: column.height
contentHeight: welcomeColumn.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
id: welcomeColumn
width: parent.width
spacing: Theme.paddingLarge
@ -246,6 +258,8 @@ Page {
}
enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g)
onClicked: {
initializationPage.loading = true;
welcomeFlickable.visible = false;
tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text);
}
}

View file

@ -29,6 +29,8 @@ Page {
allowedOrientations: Orientation.All
property bool loading: true;
property int authorizationState: TelegramAPI.Closed
property int connectionState: TelegramAPI.WaitingForNetwork
BusyLabel {
text: qsTr("Loading...")
@ -44,10 +46,31 @@ Page {
pageStack.clear();
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.WaitCode:
overviewPage.loading = false;
pageStack.clear();
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.AuthorizationReady:
overviewPage.loading = false;
break;
default:
// Nothing ;)
}
overviewPage.authorizationState = authorizationState;
}
onConnectionStateChanged: {
overviewPage.connectionState = connectionState;
}
}
Component.onCompleted: {
overviewPage.authorizationState = tdLibWrapper.getAuthorizationState();
if (overviewPage.authorizationState === TelegramAPI.AuthorizationReady) {
overviewPage.loading = false;
}
overviewPage.connectionState = tdLibWrapper.getConnectionState();
}
SilicaFlickable {

View file

@ -89,6 +89,15 @@ void TDLibWrapper::setAuthenticationPhoneNumber(const QString &phoneNumber)
this->sendRequest(requestObject);
}
void TDLibWrapper::setAuthenticationCode(const QString &authenticationCode)
{
qDebug() << "[TDLibWrapper] Set authentication code " << authenticationCode;
QVariantMap requestObject;
requestObject.insert("@type", "checkAuthenticationCode");
requestObject.insert("code", authenticationCode);
this->sendRequest(requestObject);
}
void TDLibWrapper::handleVersionDetected(const QString &version)
{
this->version = version;

View file

@ -63,6 +63,7 @@ public:
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
signals:
void versionDetected(const QString &version);

View file

@ -66,22 +66,6 @@
<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>
@ -94,6 +78,26 @@
<source>Continue</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter the code that you received:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to authenticate you with the entered code.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter code again</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Restart authentication</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>

View file

@ -66,22 +66,6 @@
<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>
@ -94,6 +78,26 @@
<source>Continue</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter the code that you received:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to authenticate you with the entered code.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter code again</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Restart authentication</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OverviewPage</name>