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
|
1
|
||||||
25
|
27
|
||||||
icons/comments.png
|
icons/comments.png
|
||||||
icons/globe.png
|
icons/globe.png
|
||||||
icons/ic_add.png
|
icons/ic_add.png
|
||||||
|
@ -16,8 +16,10 @@ icons/messages.png
|
||||||
icons/quote-left.png
|
icons/quote-left.png
|
||||||
icons/refresh.png
|
icons/refresh.png
|
||||||
icons/retweet.png
|
icons/retweet.png
|
||||||
|
icons/sign-out.png
|
||||||
icons/star-o.png
|
icons/star-o.png
|
||||||
icons/star.png
|
icons/star.png
|
||||||
|
LoginSheet.qml
|
||||||
main.qml
|
main.qml
|
||||||
moment.js
|
moment.js
|
||||||
NewPostSheet.qml
|
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 {
|
Container {
|
||||||
signal refresh
|
signal refresh
|
||||||
|
|
||||||
|
property variant theme : Application.themeSupport.theme.colorTheme.style
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: label_refresh
|
id: label_refresh
|
||||||
text: qsTr("Load Newer")
|
text: qsTr("Load Newer")
|
||||||
|
|
|
@ -124,6 +124,12 @@ NavigationPane {
|
||||||
pnut.sendPost(text);
|
pnut.sendPost(text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
LoginSheet {
|
||||||
|
id: loginSheet
|
||||||
|
onLogin: {
|
||||||
|
pnut.authorize();
|
||||||
|
}
|
||||||
|
},
|
||||||
QTimer {
|
QTimer {
|
||||||
id: timer
|
id: timer
|
||||||
interval: 30000
|
interval: 30000
|
||||||
|
@ -149,7 +155,12 @@ NavigationPane {
|
||||||
pnut.sinceId = postModel.value(0).id;
|
pnut.sinceId = postModel.value(0).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAuthorizationRequired: {
|
||||||
|
loginSheet.open();
|
||||||
|
}
|
||||||
|
|
||||||
onAuthorizationReceived: {
|
onAuthorizationReceived: {
|
||||||
|
loginSheet.close();
|
||||||
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +184,10 @@ NavigationPane {
|
||||||
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
||||||
timer.start();
|
timer.start();
|
||||||
} else {
|
} else {
|
||||||
pnut.authorize();
|
loginSheet.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function logout() {
|
||||||
|
pnut.logout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ TabbedPane {
|
||||||
title: qsTr("Logout")
|
title: qsTr("Logout")
|
||||||
imageSource: "asset:///icons/sign-out.png"
|
imageSource: "asset:///icons/sign-out.png"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
//
|
activePane.logout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -44,6 +44,7 @@ TabbedPane {
|
||||||
title: qsTr("Global")
|
title: qsTr("Global")
|
||||||
delegate: Delegate {
|
delegate: Delegate {
|
||||||
StreamTab {
|
StreamTab {
|
||||||
|
id: globalTab
|
||||||
stream_type: "Global"
|
stream_type: "Global"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
buildnum
2
buildnum
|
@ -1 +1 @@
|
||||||
71
|
83
|
|
@ -66,6 +66,7 @@ simulator {
|
||||||
|
|
||||||
config_pri_assets {
|
config_pri_assets {
|
||||||
OTHER_FILES += \
|
OTHER_FILES += \
|
||||||
|
$$quote($$BASEDIR/assets/LoginSheet.qml) \
|
||||||
$$quote($$BASEDIR/assets/NewPostSheet.qml) \
|
$$quote($$BASEDIR/assets/NewPostSheet.qml) \
|
||||||
$$quote($$BASEDIR/assets/PostItem.qml) \
|
$$quote($$BASEDIR/assets/PostItem.qml) \
|
||||||
$$quote($$BASEDIR/assets/RefreshItem.qml) \
|
$$quote($$BASEDIR/assets/RefreshItem.qml) \
|
||||||
|
@ -87,6 +88,7 @@ config_pri_assets {
|
||||||
$$quote($$BASEDIR/assets/icons/quote-left.png) \
|
$$quote($$BASEDIR/assets/icons/quote-left.png) \
|
||||||
$$quote($$BASEDIR/assets/icons/refresh.png) \
|
$$quote($$BASEDIR/assets/icons/refresh.png) \
|
||||||
$$quote($$BASEDIR/assets/icons/retweet.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-o.png) \
|
||||||
$$quote($$BASEDIR/assets/icons/star.png) \
|
$$quote($$BASEDIR/assets/icons/star.png) \
|
||||||
$$quote($$BASEDIR/assets/main.qml) \
|
$$quote($$BASEDIR/assets/main.qml) \
|
||||||
|
|
29
src/Pnut.cpp
29
src/Pnut.cpp
|
@ -165,12 +165,15 @@ void Pnut::onRequestReady(QByteArray data)
|
||||||
qDebug() << "- onRequestReady -";
|
qDebug() << "- onRequestReady -";
|
||||||
switch (oauthManager->lastError())
|
switch (oauthManager->lastError())
|
||||||
{
|
{
|
||||||
|
case KQOAuthManager::RequestUnauthorized:
|
||||||
|
qDebug() << "- Unauthorized -";
|
||||||
|
m_appSettings->remove("access_token");
|
||||||
|
m_appSettings->remove("username");
|
||||||
|
emit authorizationRequired();
|
||||||
|
break;
|
||||||
case KQOAuthManager::NetworkError:
|
case KQOAuthManager::NetworkError:
|
||||||
qDebug() << "- NetworkError -";
|
qDebug() << "- NetworkError -";
|
||||||
qDebug() << data;
|
getUserInfo();
|
||||||
// m_appSettings->remove("access_token");
|
|
||||||
// m_appSettings->remove("username");
|
|
||||||
// authorize();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,6 +213,11 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
|
||||||
emit threadReceived(variant.toMap()["data"].toList());
|
emit threadReceived(variant.toMap()["data"].toList());
|
||||||
req_map.remove(id);
|
req_map.remove(id);
|
||||||
}
|
}
|
||||||
|
else if (endpoint == ":logout")
|
||||||
|
{
|
||||||
|
qDebug() << "Logout successful!";
|
||||||
|
req_map.remove(id);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Pnut::CREATED:
|
case Pnut::CREATED:
|
||||||
|
@ -219,6 +227,11 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
|
||||||
qDebug() << "Success!";
|
qDebug() << "Success!";
|
||||||
req_map.remove(id);
|
req_map.remove(id);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Good but not sure what";
|
||||||
|
req_map.remove(id);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -332,3 +345,11 @@ void Pnut::deleteRepost(QString pid)
|
||||||
req_map[++req_id] = ":repost";
|
req_map[++req_id] = ":repost";
|
||||||
deleteRequest(url, parameters, req_id);
|
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 deleteBookmark(QString pid);
|
||||||
Q_INVOKABLE void repost(QString pid);
|
Q_INVOKABLE void repost(QString pid);
|
||||||
Q_INVOKABLE void deleteRepost(QString pid);
|
Q_INVOKABLE void deleteRepost(QString pid);
|
||||||
|
Q_INVOKABLE void logout();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onRequestReady(QByteArray data);
|
void onRequestReady(QByteArray data);
|
||||||
|
@ -83,6 +84,7 @@ public slots:
|
||||||
void onAuthorizationReceived(QString token, QString verifier);
|
void onAuthorizationReceived(QString token, QString verifier);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void authorizationRequired();
|
||||||
void authorizationReceived();
|
void authorizationReceived();
|
||||||
void streamReceived(QVariantList stream, Pnut::RequestType rtype);
|
void streamReceived(QVariantList stream, Pnut::RequestType rtype);
|
||||||
void threadReceived(QVariantList thread);
|
void threadReceived(QVariantList thread);
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!DOCTYPE TS>
|
||||||
<TS version="2.0">
|
<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>
|
<context>
|
||||||
<name>NewPostSheet</name>
|
<name>NewPostSheet</name>
|
||||||
<message>
|
<message>
|
||||||
|
@ -60,7 +68,7 @@
|
||||||
<context>
|
<context>
|
||||||
<name>RefreshItem</name>
|
<name>RefreshItem</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../assets/RefreshItem.qml" line="7"/>
|
<location filename="../assets/RefreshItem.qml" line="10"/>
|
||||||
<source>Load Newer</source>
|
<source>Load Newer</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -96,7 +104,7 @@
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../assets/main.qml" line="43"/>
|
<location filename="../assets/main.qml" line="44"/>
|
||||||
<source>Global</source>
|
<source>Global</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
Reference in a new issue