2020-01-07 20:08:18 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-01-10 14:21:03 +00:00
|
|
|
#include <helpers/accounthelper.h>
|
|
|
|
|
2020-01-07 20:53:27 +00:00
|
|
|
#include "api_request.h"
|
2020-01-08 16:43:04 +00:00
|
|
|
#include "loginscreen.h"
|
|
|
|
|
2020-01-07 20:08:18 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2020-01-10 14:21:03 +00:00
|
|
|
int main(int argc, char **argv)
|
2020-01-07 20:08:18 +00:00
|
|
|
{
|
|
|
|
cout << "Comunic Term (c) Pierre HUBERT" << endl;
|
2020-01-07 20:53:27 +00:00
|
|
|
|
2020-01-10 14:21:03 +00:00
|
|
|
bool onlyGetTokens = false;
|
|
|
|
|
|
|
|
if(argc > 1) {
|
|
|
|
string arg = argv[1];
|
|
|
|
|
|
|
|
// Show help
|
|
|
|
if(arg == "help") {
|
|
|
|
cout << "Usage: " << endl;
|
|
|
|
cout << "* help : Show this help" << endl;
|
|
|
|
cout << "* getTokens : Get login token ONLY" << endl;
|
2020-01-10 14:31:07 +00:00
|
|
|
cout << "* useTokens : Input login tokens (do not show login form)" << endl;
|
2020-01-10 14:21:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get login tokens
|
2020-01-10 14:31:07 +00:00
|
|
|
else if(arg == "getTokens") {
|
2020-01-10 14:21:03 +00:00
|
|
|
cout << "Getting only login tokens..." << endl;
|
|
|
|
onlyGetTokens = true;
|
|
|
|
}
|
|
|
|
|
2020-01-10 14:31:07 +00:00
|
|
|
// Use existing login tokens
|
|
|
|
else if(arg == "useTokens") {
|
|
|
|
if(argc != 4) {
|
|
|
|
cerr << "Need to specify tokens!" << endl;
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set tokens
|
|
|
|
vector<std::string> tokens;
|
|
|
|
tokens.push_back(argv[2]);
|
|
|
|
tokens.push_back(argv[3]);
|
|
|
|
AccountHelper::setLoginTokens(tokens);
|
|
|
|
|
|
|
|
// Validate them
|
|
|
|
if(!AccountHelper::refreshUserID()) {
|
|
|
|
cerr << "Could not use login tokens!" << endl;
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start directly main main menu
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
cerr << "Unrecognized argument!" << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-10 14:21:03 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 16:43:04 +00:00
|
|
|
// First, we need to sign in user
|
2020-01-10 14:31:07 +00:00
|
|
|
if(!AccountHelper::signedIn() && !LoginScreen().exec(!onlyGetTokens)) {
|
2020-01-08 16:43:04 +00:00
|
|
|
cerr << "Could not sign in user!" << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
2020-01-07 20:53:27 +00:00
|
|
|
|
2020-01-10 14:21:03 +00:00
|
|
|
if(onlyGetTokens) {
|
|
|
|
const auto tokens = AccountHelper::loginTokens();
|
|
|
|
cout << "Token 1: " << tokens[0] << endl;
|
|
|
|
cout << "Token 2: " << tokens[1] << endl;
|
|
|
|
}
|
|
|
|
|
2020-01-07 20:08:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|