Skip to content

Commit

Permalink
Nolio version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasPlazas authored and liversedge committed Feb 18, 2022
1 parent 4d7b56a commit 67294a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
37 changes: 22 additions & 15 deletions src/Cloud/Nolio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ void Nolio::onSslErrors(QNetworkReply *reply, const QList<QSslError>&){
bool Nolio::open(QStringList &errors){
printd("Nolio::open\n");

QString refresh_token = getSetting(GC_NOLIO_REFRESH_TOKEN, "").toString();
QString refresh_token = appsettings->value(NULL, GC_NOLIO_REFRESH_TOKEN, "").toString();
if (refresh_token == "") {
return false;
}

QString last_refresh_str = getSetting(GC_NOLIO_LAST_REFRESH, "0").toString();
QString last_refresh_str = appsettings->value(NULL, GC_NOLIO_LAST_REFRESH, "0").toString();
QDateTime last_refresh = QDateTime::fromString(last_refresh_str);
last_refresh = last_refresh.addSecs(86400); // nolio tokens are valid for one day
QDateTime now = QDateTime::currentDateTime();
Expand All @@ -95,7 +95,7 @@ bool Nolio::open(QStringList &errors){
}

// get new credentials using refresh_token
QNetworkRequest request(QUrl("https://nolio2.eu.ngrok.io/api/token/"));
QNetworkRequest request(QUrl("https://www.nolio.io/api/token/"));
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");

QString authheader = QString("%1:%2").arg(GC_NOLIO_CLIENT_ID).arg(GC_NOLIO_CLIENT_SECRET);
Expand Down Expand Up @@ -130,9 +130,9 @@ bool Nolio::open(QStringList &errors){

QString new_access_token = document.object()["access_token"].toString();
QString new_refresh_token = document.object()["refresh_token"].toString();
if (new_access_token != "") setSetting(GC_NOLIO_ACCESS_TOKEN, new_access_token);
if (new_refresh_token != "") setSetting(GC_NOLIO_REFRESH_TOKEN, new_refresh_token);
setSetting(GC_NOLIO_LAST_REFRESH, now.toString());
if (new_access_token != "") appsettings->setValue(GC_NOLIO_ACCESS_TOKEN, new_access_token);
if (new_refresh_token != "") appsettings->setValue(GC_NOLIO_REFRESH_TOKEN, new_refresh_token);
appsettings->setValue(GC_NOLIO_LAST_REFRESH, now.toString());
CloudServiceFactory::instance().saveSettings(this, context);
return true;
}
Expand All @@ -142,15 +142,15 @@ QList<CloudServiceEntry*> Nolio::readdir(QString path, QStringList &errors, QDat
QList<CloudServiceEntry*> returning;

// do we have a token
QString access_token = getSetting(GC_NOLIO_ACCESS_TOKEN, "").toString();
QString access_token = appsettings->value(NULL, GC_NOLIO_ACCESS_TOKEN, "").toString();
if (access_token == "") {
errors << "You must authorise with Nolio first";
return returning;
}

QString user_id = getSetting(GC_NOLIO_ATHLETE_ID, "").toString();

QString urlstr = "https://nolio2.eu.ngrok.io/api/get/training/?";
// prepare the request
QString urlstr = "https://www.nolio.io/api/get/training/?";
QUrlQuery params;
params.addQueryItem("from", from.toString("yyyy-MM-dd"));
params.addQueryItem("to", to.toString("yyyy-MM-dd"));
Expand Down Expand Up @@ -190,7 +190,11 @@ QList<CloudServiceEntry*> Nolio::readdir(QString path, QStringList &errors, QDat
add->isDir = false;
add->distance = each["distance"].toDouble();
add->duration = each["duration"].toInt();
add->name = QDateTime::fromString(each["date_start"].toString(), Qt::ISODate).toString("yyyy_MM_dd_HH_mm_ss")+".json";
if(each["hour_start"].toString().size() > 0){
QString full_date = QString("%1T%2Z").arg(each["date_start"].toString(), each["hour_start"].toString());
add->name = QDateTime::fromString(full_date, Qt::ISODate).toString("yyyy_MM_dd_HH_mm_ss")+".json";
}
else add->name = QDateTime::fromString(each["date_start"].toString(), Qt::ISODate).toString("yyyy_MM_dd_HH_mm_ss")+".json";
returning << add;
}
}
Expand All @@ -202,12 +206,13 @@ bool Nolio::readFile(QByteArray *data, QString remotename, QString remoteid){
printd("Nolio::readFile\n");

// do we have a token
QString access_token = getSetting(GC_NOLIO_ACCESS_TOKEN, "").toString();
QString access_token = appsettings->value(NULL, GC_NOLIO_ACCESS_TOKEN, "").toString();
if (access_token == "") {
return false;
}

QString urlstr = "https://nolio2.eu.ngrok.io/api/get/training/info/?";
// prepare the request
QString urlstr = "https://www.nolio.io/api/get/training/info/?";
QUrlQuery params;
params.addQueryItem("id", remoteid);
QUrl url = QUrl(urlstr + params.toString());
Expand Down Expand Up @@ -341,12 +346,14 @@ QList<CloudServiceAthlete> Nolio::listAthletes(){
printd("Nolio::listAthletes\n");
QList<CloudServiceAthlete> returning;

QString access_token = getSetting(GC_NOLIO_ACCESS_TOKEN, "").toString();
QString access_token = appsettings->value(NULL, GC_NOLIO_ACCESS_TOKEN, "").toString();
if (access_token == "") {
return returning;
}
QString urlstr = "https://nolio2.eu.ngrok.io/api/get/athletes/";
QUrl url = QUrl(urlstr);
QString urlstr = "https://www.nolio.io/api/get/athletes/?";
QUrlQuery params;
params.addQueryItem("wants_coach", "true");
QUrl url = QUrl(urlstr + params.toString());
QNetworkRequest request(url);
request.setRawHeader("Authorization", (QString("Bearer %1").arg(access_token)).toLatin1());
QNetworkReply *reply = nam->get(request);
Expand Down
10 changes: 5 additions & 5 deletions src/Cloud/OAuthDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ OAuthDialog::OAuthDialog(Context *context, OAuthSite site, CloudService *service

} else if(site == NOLIO) {

urlstr = QString("https://nolio2.eu.ngrok.io/api/authorize?");
urlstr = QString("https://www.nolio.io/api/authorize/?");
urlstr.append("client_id=").append(GC_NOLIO_CLIENT_ID).append("&");
urlstr.append("redirect_uri=http://www.goldencheetah.org/&");
urlstr.append("response_type=code");
Expand Down Expand Up @@ -295,7 +295,7 @@ OAuthDialog::urlChanged(const QUrl &url)

} else if (site == NOLIO) {

urlstr = QString("https://nolio2.eu.ngrok.io/api/token/?");
urlstr = QString("https://www.nolio.io/api/token/?");
params.addQueryItem("grant_type", "authorization_code");
params.addQueryItem("redirect_uri", "http://www.goldencheetah.org/");
#if (defined GC_NOLIO_CLIENT_ID) && (defined GC_NOLIO_CLIENT_SECRET)
Expand Down Expand Up @@ -626,9 +626,9 @@ OAuthDialog::networkRequestFinished(QNetworkReply *reply)
information.exec();

} else if (site == NOLIO) {
service->setSetting(GC_NOLIO_ACCESS_TOKEN, access_token);
service->setSetting(GC_NOLIO_REFRESH_TOKEN, refresh_token);
service->setSetting(GC_NOLIO_LAST_REFRESH, QDateTime::currentDateTime());
appsettings->setValue(GC_NOLIO_ACCESS_TOKEN, access_token);
appsettings->setValue(GC_NOLIO_REFRESH_TOKEN, refresh_token);
appsettings->setValue(GC_NOLIO_LAST_REFRESH, QDateTime::currentDateTime());
QString info = QString(tr("Nolio authorization was successful."));
QMessageBox information(QMessageBox::Information, tr("Information"), info);
information.exec();
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@
#define GC_XERT_TOKEN "<athlete-private>xert/xert_token"
#define GC_XERT_REFRESH_TOKEN "<athlete-private>xert/refresh_token"
#define GC_XERT_LAST_REFRESH "<athlete-private>xert/last_refresh"
//Nolio
#define GC_NOLIO_ACCESS_TOKEN "<athlete-private>nolio_access_token"
#define GC_NOLIO_REFRESH_TOKEN "<athlete-private>nolio_refresh_token"
#define GC_NOLIO_LAST_REFRESH "<athlete-private>nolio_last_refresh"
// Nolio
#define GC_NOLIO_ACCESS_TOKEN "<global-general>nolio_access_token"
#define GC_NOLIO_REFRESH_TOKEN "<global-general>nolio_refresh_token"
#define GC_NOLIO_LAST_REFRESH "<global-general>nolio_last_refresh"
#define GC_NOLIO_URL "<athlete-private>nolio_url"
#define GC_NOLIO_ATHLETE_ID "<athlete-private>nolio_athlete_id"
#define GC_NOLIO_ATHLETE_NAME "<athlete-private>nolio_athlete_name"
Expand Down

0 comments on commit 67294a6

Please sign in to comment.