From 67364cc528af823ce13522c39aac89f86a8bd868 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 1 Oct 2016 11:18:40 -0700 Subject: [PATCH] fixed login and logout --- assets/.assets.index | 4 +++- assets/LoginSheet.qml | 38 ++++++++++++++++++++++++++++++++++++++ assets/RefreshItem.qml | 3 +++ assets/StreamTab.qml | 16 +++++++++++++++- assets/main.qml | 3 ++- buildnum | 2 +- config.pri | 2 ++ src/Pnut.cpp | 29 +++++++++++++++++++++++++---- src/Pnut.h | 2 ++ translations/Goober.ts | 12 ++++++++++-- 10 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 assets/LoginSheet.qml diff --git a/assets/.assets.index b/assets/.assets.index index eecceda..a116554 100644 --- a/assets/.assets.index +++ b/assets/.assets.index @@ -1,5 +1,5 @@ 1 -25 +27 icons/comments.png icons/globe.png icons/ic_add.png @@ -16,8 +16,10 @@ icons/messages.png icons/quote-left.png icons/refresh.png icons/retweet.png +icons/sign-out.png icons/star-o.png icons/star.png +LoginSheet.qml main.qml moment.js NewPostSheet.qml diff --git a/assets/LoginSheet.qml b/assets/LoginSheet.qml new file mode 100644 index 0000000..7aba311 --- /dev/null +++ b/assets/LoginSheet.qml @@ -0,0 +1,38 @@ +import bb.cascades 1.4 + +Sheet { + peekEnabled: false + signal login + + Page { + Container { + verticalAlignment: VerticalAlignment.Fill + horizontalAlignment: HorizontalAlignment.Fill + layout: DockLayout {} + Container { + verticalAlignment: VerticalAlignment.Center + horizontalAlignment: HorizontalAlignment.Center + + Container { + Label { + text: "Goober" + horizontalAlignment: HorizontalAlignment.Center + textStyle.fontSize: FontSize.XXLarge + } + Label { + text: "A short messaging client for the pnut.io network." + multiline: true + bottomMargin: ui.du(6.0) + } + Button { + text: qsTr("Sign In") + onClicked: { + login() + } + horizontalAlignment: HorizontalAlignment.Center + } + } + } + } + } +} \ No newline at end of file diff --git a/assets/RefreshItem.qml b/assets/RefreshItem.qml index 22e45e0..a34ae53 100644 --- a/assets/RefreshItem.qml +++ b/assets/RefreshItem.qml @@ -2,6 +2,9 @@ import bb.cascades 1.4 Container { signal refresh + + property variant theme : Application.themeSupport.theme.colorTheme.style + Label { id: label_refresh text: qsTr("Load Newer") diff --git a/assets/StreamTab.qml b/assets/StreamTab.qml index 1199628..38748e9 100644 --- a/assets/StreamTab.qml +++ b/assets/StreamTab.qml @@ -124,6 +124,12 @@ NavigationPane { pnut.sendPost(text); } }, + LoginSheet { + id: loginSheet + onLogin: { + pnut.authorize(); + } + }, QTimer { id: timer interval: 30000 @@ -149,7 +155,12 @@ NavigationPane { pnut.sinceId = postModel.value(0).id; } + onAuthorizationRequired: { + loginSheet.open(); + } + onAuthorizationReceived: { + loginSheet.close(); pnut.getStream(endpoint, Pnut.STREAM_OLDER); timer.start(); } @@ -173,7 +184,10 @@ NavigationPane { pnut.getStream(endpoint, Pnut.STREAM_OLDER); timer.start(); } else { - pnut.authorize(); + loginSheet.open(); } } + function logout() { + pnut.logout(); + } } diff --git a/assets/main.qml b/assets/main.qml index 61a1279..5e713de 100644 --- a/assets/main.qml +++ b/assets/main.qml @@ -33,7 +33,7 @@ TabbedPane { title: qsTr("Logout") imageSource: "asset:///icons/sign-out.png" onTriggered: { - // + activePane.logout(); } } ] @@ -44,6 +44,7 @@ TabbedPane { title: qsTr("Global") delegate: Delegate { StreamTab { + id: globalTab stream_type: "Global" } } diff --git a/buildnum b/buildnum index 2fb681e..24af08a 100644 --- a/buildnum +++ b/buildnum @@ -1 +1 @@ -71 \ No newline at end of file +83 \ No newline at end of file diff --git a/config.pri b/config.pri index 6cc9595..5d032b9 100644 --- a/config.pri +++ b/config.pri @@ -66,6 +66,7 @@ simulator { config_pri_assets { OTHER_FILES += \ + $$quote($$BASEDIR/assets/LoginSheet.qml) \ $$quote($$BASEDIR/assets/NewPostSheet.qml) \ $$quote($$BASEDIR/assets/PostItem.qml) \ $$quote($$BASEDIR/assets/RefreshItem.qml) \ @@ -87,6 +88,7 @@ config_pri_assets { $$quote($$BASEDIR/assets/icons/quote-left.png) \ $$quote($$BASEDIR/assets/icons/refresh.png) \ $$quote($$BASEDIR/assets/icons/retweet.png) \ + $$quote($$BASEDIR/assets/icons/sign-out.png) \ $$quote($$BASEDIR/assets/icons/star-o.png) \ $$quote($$BASEDIR/assets/icons/star.png) \ $$quote($$BASEDIR/assets/main.qml) \ diff --git a/src/Pnut.cpp b/src/Pnut.cpp index 6e59c8f..a4671e2 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -165,12 +165,15 @@ void Pnut::onRequestReady(QByteArray data) qDebug() << "- onRequestReady -"; switch (oauthManager->lastError()) { + case KQOAuthManager::RequestUnauthorized: + qDebug() << "- Unauthorized -"; + m_appSettings->remove("access_token"); + m_appSettings->remove("username"); + emit authorizationRequired(); + break; case KQOAuthManager::NetworkError: qDebug() << "- NetworkError -"; - qDebug() << data; -// m_appSettings->remove("access_token"); -// m_appSettings->remove("username"); -// authorize(); + getUserInfo(); break; } } @@ -210,6 +213,11 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id) emit threadReceived(variant.toMap()["data"].toList()); req_map.remove(id); } + else if (endpoint == ":logout") + { + qDebug() << "Logout successful!"; + req_map.remove(id); + } break; } case Pnut::CREATED: @@ -219,6 +227,11 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id) qDebug() << "Success!"; req_map.remove(id); } + else + { + qDebug() << "Good but not sure what"; + req_map.remove(id); + } break; } default: @@ -332,3 +345,11 @@ void Pnut::deleteRepost(QString pid) req_map[++req_id] = ":repost"; deleteRequest(url, parameters, req_id); } + +void Pnut::logout() +{ + QUrl url(PNUT_API_ROOT + "/token"); + KQOAuthParameters parameters; + req_map[++req_id] = ":logout"; + deleteRequest(url, parameters, req_id); +} diff --git a/src/Pnut.h b/src/Pnut.h index 3a5336b..e856cc5 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -76,6 +76,7 @@ public: Q_INVOKABLE void deleteBookmark(QString pid); Q_INVOKABLE void repost(QString pid); Q_INVOKABLE void deleteRepost(QString pid); + Q_INVOKABLE void logout(); public slots: void onRequestReady(QByteArray data); @@ -83,6 +84,7 @@ public slots: void onAuthorizationReceived(QString token, QString verifier); Q_SIGNALS: + void authorizationRequired(); void authorizationReceived(); void streamReceived(QVariantList stream, Pnut::RequestType rtype); void threadReceived(QVariantList thread); diff --git a/translations/Goober.ts b/translations/Goober.ts index 368bd8e..ddbb1f1 100644 --- a/translations/Goober.ts +++ b/translations/Goober.ts @@ -1,6 +1,14 @@ + + LoginSheet + + + Sign In + + + NewPostSheet @@ -60,7 +68,7 @@ RefreshItem - + Load Newer @@ -96,7 +104,7 @@ - + Global