Index: providers/ghprovider/ghdialog.h
===================================================================
--- providers/ghprovider/ghdialog.h
+++ providers/ghprovider/ghdialog.h
@@ -72,7 +72,7 @@
* @param id The id of the authorization.
* @param token The authorization token.
*/
- void authorizeResponse(const QByteArray &id, const QByteArray &token);
+ void authorizeResponse(const QByteArray &id, const QByteArray &token, const QString &tokenName);
/// Sync the user's groups.
void syncUser();
Index: providers/ghprovider/ghdialog.cpp
===================================================================
--- providers/ghprovider/ghdialog.cpp
+++ providers/ghprovider/ghdialog.cpp
@@ -33,11 +34,13 @@
#define VALID_ACCOUNT "You're logged in as %1. You can check the " \
"authorization for this application and others " \
- "here."
+ "here."
#define INVALID_ACCOUNT "You haven't authorized KDevelop to use your Github " \
"account. If you authorize KDevelop, you will be able to fetch your " \
"public/private repositories and the repositories from your organizations."
-
+#define TOKEN_LINK_STATEMENT "You can check the " \
+ "authorization for this application and others " \
+ "at https://github.com/settings/tokens"
namespace gh
{
@@ -112,7 +115,7 @@
this, &Dialog::authorizeResponse);
}
-void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token)
+void Dialog::authorizeResponse(const QByteArray &id, const QByteArray &token, const QString &tokenName)
{
Resource *rs = m_account->resource();
disconnect(rs, &Resource::authenticated,
@@ -122,11 +125,18 @@
m_text->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_text->setText(i18n(INVALID_ACCOUNT));
m_account->setName(QString());
- KMessageBox::sorry(this, i18n("Authentication failed! Please, "
- "try again"));
+ KMessageBox::sorry(this, i18n("Authentication failed! Please Try Again.\n "
+ "Couldn't create token: \"") + tokenName + "\"\n" +
+ i18n(TOKEN_LINK_STATEMENT),
+ i18n("Github Authorization Failed"));
return;
}
-
+ else{
+ KMessageBox::information(this, i18n("Authentication Succeeded!\n"
+ "created token: \"") + tokenName + "\"\n" +
+ i18n(TOKEN_LINK_STATEMENT),
+ i18n("Github Account Authorized"));
+ }
m_account->saveToken(id, token);
syncUser();
}
Index: providers/ghprovider/ghresource.h
===================================================================
--- providers/ghprovider/ghresource.h
+++ providers/ghprovider/ghresource.h
@@ -126,7 +126,7 @@
* @param id The id of the authorization. Empty if something went wrong.
* @param token The authorization token. Empty if something went wrong.
*/
- void authenticated(const QByteArray &id, const QByteArray &token);
+ void authenticated(const QByteArray &id, const QByteArray &token, const QString &tokenName);
/**
* This signal is emitted when the model containing repos has
@@ -169,6 +169,7 @@
private:
ProviderModel *m_model;
+ QString m_tokenName;
QByteArray m_temp, m_orgTemp;
};
Index: providers/ghprovider/ghresource.cpp
===================================================================
--- providers/ghprovider/ghresource.cpp
+++ providers/ghprovider/ghresource.cpp
@@ -24,6 +24,8 @@
#include
#include
#include
+#include
+#include
#include "debug.h"
#include
@@ -60,7 +62,8 @@
QUrl url = baseUrl;
url = url.adjusted(QUrl::StripTrailingSlash);
url.setPath(url.path() + '/' + "/authorizations");
- QByteArray data = "{ \"scopes\": [\"repo\"], \"note\": \"KDevelop Github Provider\" }";
+ m_tokenName = "KDevelop Github Provider : " + QHostInfo::localHostName() + " - " +
QDateTime::currentDateTimeUtc().toString();
+ QByteArray data = "{ \"scopes\": [\"repo\"], \"note\": \"" + m_tokenName.toUtf8() + "\" }";
KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo);
job->addMetaData("customHTTPHeader", "Authorization: Basic " + QString (name + ':' + password).toUtf8().toBase64());
@@ -133,7 +136,7 @@
void Resource::slotAuthenticate(KJob *job)
{
if (job->error()) {
- emit authenticated("", "");
+ emit authenticated("", "", m_tokenName);
return;
}
@@ -145,9 +148,9 @@
if (error.error == 0) {
QVariantMap map = doc.toVariant().toMap();
emit authenticated(map.value("id").toByteArray(),
- map.value("token").toByteArray());
+ map.value("token").toByteArray(), m_tokenName);
} else
- emit authenticated("", "");
+ emit authenticated("", "", m_tokenName);
}
void Resource::slotRepos(KIO::Job *job, const QByteArray &data)