fixed login and logout
This commit is contained in:
parent
b80fafa99c
commit
67364cc528
10 changed files with 101 additions and 10 deletions
|
@ -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
|
||||
|
|
38
assets/LoginSheet.qml
Normal file
38
assets/LoginSheet.qml
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
2
buildnum
2
buildnum
|
@ -1 +1 @@
|
|||
71
|
||||
83
|
|
@ -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) \
|
||||
|
|
29
src/Pnut.cpp
29
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.0">
|
||||
<context>
|
||||
<name>LoginSheet</name>
|
||||
<message>
|
||||
<location filename="../assets/LoginSheet.qml" line="28"/>
|
||||
<source>Sign In</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>NewPostSheet</name>
|
||||
<message>
|
||||
|
@ -60,7 +68,7 @@
|
|||
<context>
|
||||
<name>RefreshItem</name>
|
||||
<message>
|
||||
<location filename="../assets/RefreshItem.qml" line="7"/>
|
||||
<location filename="../assets/RefreshItem.qml" line="10"/>
|
||||
<source>Load Newer</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -96,7 +104,7 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../assets/main.qml" line="43"/>
|
||||
<location filename="../assets/main.qml" line="44"/>
|
||||
<source>Global</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
Reference in a new issue