diff --git a/providers/ghprovider/ghdialog.h b/providers/ghprovider/ghdialog.h --- a/providers/ghprovider/ghdialog.h +++ b/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(); diff --git a/providers/ghprovider/ghdialog.cpp b/providers/ghprovider/ghdialog.cpp --- a/providers/ghprovider/ghdialog.cpp +++ b/providers/ghprovider/ghdialog.cpp @@ -31,13 +31,13 @@ #include #include -#define VALID_ACCOUNT "You're logged in as %1. You can check the " \ - "authorization for this application and others " \ - "here." +#define VALID_ACCOUNT "" #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 { @@ -54,8 +54,8 @@ auto buttonBox = new QDialogButtonBox(); if (m_account->validAccount()) { - QString str = QString(VALID_ACCOUNT).arg(m_account->name()); - m_text = new QLabel(i18n(str.toUtf8()), this); + m_text = new QLabel(i18n("You're logged in as %1.
", + m_account->name()) + i18n(TOKEN_LINK_STATEMENT), this); auto logOutButton = new QPushButton; logOutButton->setText(i18n("Log out")); @@ -124,11 +124,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\n" + "Couldn't create token: \"%1\"\n", tokenName) + + i18n(TOKEN_LINK_STATEMENT), + i18n("Github Authorization Failed")); return; } - + else{ + KMessageBox::information(this, i18n("Authentication succeeded!\n\n" + "Created token: \"") + tokenName + "\"\n" + + i18n(TOKEN_LINK_STATEMENT), + i18n("Github Account Authorized")); + } m_account->saveToken(id, token); syncUser(); } diff --git a/providers/ghprovider/ghresource.h b/providers/ghprovider/ghresource.h --- a/providers/ghprovider/ghresource.h +++ b/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; }; diff --git a/providers/ghprovider/ghresource.cpp b/providers/ghprovider/ghresource.cpp --- a/providers/ghprovider/ghresource.cpp +++ b/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)