void LoginManager::onGetUserReply(QNetworkReply* reply, int code, const QJsonObject& user) { // qDebug() << "onGetUserReply" << code << reply->errorString(); if (code == HTTP_OK) { if (user.value("name") != QJsonValue::Undefined) { _userName = user.value("name").toString(); _uid = user.value("id").toString().toInt(); emit getUserSuccess(); } else emit getUserError(tr("Wrong response from the server")); } else emit getUserError(tr("Error while getting user info: %1").arg(getErrorString(reply, user))); }
void LoginManager::tryLogin() { disconnect(this, SIGNAL(loginSuccess()), this, SLOT(tryLogin())); connect(this, SIGNAL(getUserSuccess()), this, SLOT(onTryLoginSuccess())); connect(this, SIGNAL(getUserError(QString)), this, SLOT(onTryLoginError(QString))); getUser(); }
void LoginManager::onTryLoginError(const QString& error) { Q_UNUSED(error); disconnect(this, SIGNAL(getUserSuccess()), this, SLOT(onTryLoginSuccess())); disconnect(this, SIGNAL(getUserError(QString)), this, SLOT(onTryLoginError(QString))); connect(this, SIGNAL(loginSuccess()), this, SLOT(tryLogin())); logout(); mscore->showLoginDialog(); }
void LoginManager::onTryLoginError(const QString& error) { Q_UNUSED(error); disconnect(this, SIGNAL(getUserSuccess()), this, SLOT(onTryLoginSuccess())); disconnect(this, SIGNAL(getUserError(QString)), this, SLOT(onTryLoginError(QString))); connect(this, SIGNAL(loginSuccess()), this, SLOT(tryLogin())); logout(); #ifdef USE_WEBENGINE loginInteractive(); #else mscore->showLoginDialog(); #endif }
void LoginManager::onGetUserRequestReady(QByteArray ba) { //qDebug() << "onGetUserRequestReady" << ba; disconnect(_oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onGetUserRequestReady(QByteArray))); if (_oauthManager->lastError() == KQOAuthManager::NoError) { QJsonDocument jsonResponse = QJsonDocument::fromJson(ba); QJsonObject user = jsonResponse.object(); if (user.value("name") != QJsonValue::Undefined) { _userName = user.value("name").toString(); _uid = user.value("id").toString().toInt(); emit getUserSuccess(); } else { emit getUserError(tr("Error while getting user info. Please try again")); } } else if (_oauthManager->lastError() != KQOAuthManager::NetworkError) { emit getUserError(tr("Error while getting user info: %1").arg(_oauthManager->lastError())); } }
void LoginManager::getUser() { if (_accessToken.isEmpty() || _refreshToken.isEmpty()) { emit getUserError("getUser - No token"); return; } ApiRequest r = ApiRequestBuilder() .setPath("/user/me") .setToken(_accessToken) .build(); QNetworkReply* reply = _networkManager->get(r.request); connect(reply, &QNetworkReply::finished, this, [this, reply] { onReplyFinished(reply, RequestType::GET_USER_INFO); }); }
void LoginManager::getUser() { //qDebug() << "getUser"; if (_accessToken.isEmpty() || _accessTokenSecret.isEmpty()) { emit getUserError("getUser - No token"); return; } KQOAuthRequest * oauthRequest = new KQOAuthRequest(); oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, QUrl("https://api.musescore.com/services/rest/me.json")); oauthRequest->setHttpMethod(KQOAuthRequest::GET); oauthRequest->setConsumerKey(_consumerKey); oauthRequest->setConsumerSecretKey(_consumerSecret); oauthRequest->setToken(_accessToken); oauthRequest->setTokenSecret(_accessTokenSecret); connect(_oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onGetUserRequestReady(QByteArray))); _oauthManager->executeRequest(oauthRequest); }
void LoginManager::onTryLoginSuccess() { disconnect(this, SIGNAL(getUserSuccess()), this, SLOT(onTryLoginSuccess())); disconnect(this, SIGNAL(getUserError(QString)), this, SLOT(onTryLoginError(QString))); emit tryLoginSuccess(); }