login working
This commit is contained in:
parent
5101a426c0
commit
7dbf05e2e1
5 changed files with 27 additions and 13 deletions
|
@ -5,9 +5,9 @@ Rectangle {
|
|||
color: "white"
|
||||
anchors.fill: parent
|
||||
|
||||
property string serverUrl: serverUrl.getText()
|
||||
property string userName: userName.getText()
|
||||
property string password: password.getText()
|
||||
property string serverUrl: serverUrl.text
|
||||
property string userName: userName.text
|
||||
property string password: password.text
|
||||
|
||||
Column {
|
||||
width: parent.width
|
||||
|
|
2
main.qml
2
main.qml
|
@ -30,7 +30,7 @@ ApplicationWindow {
|
|||
id: serverLogin
|
||||
onSessionIdChanged: {
|
||||
login.visible = false;
|
||||
server.initialize(serverUrl. sessionId);
|
||||
server.initialize(serverUrl, sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,18 @@ void TinyTinyRSS::initialize(const QString serverUrl, const QString sessionId)
|
|||
mSessionId = sessionId;
|
||||
}
|
||||
|
||||
void TinyTinyRSS::reload()
|
||||
{
|
||||
QVariantMap opts;
|
||||
opts.insert("show_excerpt", false);
|
||||
opts.insert("view_mode", "unread");
|
||||
opts.insert("show_content", true);
|
||||
opts.insert("feed_id", -4);
|
||||
opts.insert("skip", 0);
|
||||
|
||||
doOperation("getHeadlines", opts);
|
||||
}
|
||||
|
||||
TinyTinyRSS::~TinyTinyRSS()
|
||||
{
|
||||
delete mNetworkManager;
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
class TinyTinyRSS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QList<Post> posts READ posts NOTIFY postsChanged)
|
||||
Q_PROPERTY(QList<Post*> posts READ posts NOTIFY postsChanged)
|
||||
|
||||
public:
|
||||
TinyTinyRSS(QObject *parent = 0);
|
||||
~TinyTinyRSS();
|
||||
QList<Post> posts() const;
|
||||
QList<Post *> posts() const { return mPosts; }
|
||||
|
||||
Q_INVOKABLE void initialize(const QString serverUrl, const QString sessionId);
|
||||
Q_INVOKABLE void reload();
|
||||
|
||||
signals:
|
||||
void postsChanged(QList<Post>);
|
||||
void postsChanged(QList<Post*>);
|
||||
|
||||
private slots:
|
||||
void reply();
|
||||
|
@ -32,7 +32,7 @@ private:
|
|||
|
||||
QString mServerUrl;
|
||||
QString mSessionId;
|
||||
QList<Post> mPosts;
|
||||
QList<Post*> mPosts;
|
||||
QNetworkAccessManager *mNetworkManager;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ void TinyTinyRSSLogin::login(const QString serverUrl, const QString user, const
|
|||
QJsonDocument json = QJsonDocument(jsonobj);
|
||||
|
||||
QNetworkRequest request(mServerUrl);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
QNetworkReply *reply = mNetworkManager->post(request, json.toBinaryData());
|
||||
QNetworkReply *reply = mNetworkManager->post(request, json.toJson());
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(reply()));
|
||||
}
|
||||
|
||||
|
@ -39,13 +39,15 @@ void TinyTinyRSSLogin::reply()
|
|||
|
||||
if (reply) {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
QJsonDocument json = QJsonDocument::fromBinaryData(reply->readAll());
|
||||
mSessionId = json.toVariant().toMap().value("session_id").toString();
|
||||
QJsonDocument jdoc = QJsonDocument::fromBinaryData(reply->readAll());
|
||||
qDebug() << jdoc;
|
||||
//mSessionId = json.toVariant().toMap().value("session_id").toString();
|
||||
//qDebug() << "sessionId: " << mSessionId;
|
||||
emit sessionIdChanged(mSessionId);
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
//do some error management
|
||||
qWarning() << "HTTP error: " << httpStatus;
|
||||
qWarning() << "HTTP error: " << httpStatus << " :: " << reply->error();
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue