add a way to login on command-line

This commit is contained in:
Seth Alves 2017-07-04 17:11:53 -07:00
parent a6af6015a4
commit 1192e86494
3 changed files with 41 additions and 5 deletions

View file

@ -14,6 +14,7 @@
#include <QLoggingCategory>
#include <QCommandLineParser>
#include <NetworkLogging.h>
#include <NetworkingConstants.h>
#include <SharedLogging.h>
#include <AddressManager.h>
#include <DependencyManager.h>
@ -33,6 +34,9 @@ ACClientApp::ACClientApp(int argc, char* argv[]) :
const QCommandLineOption verboseOutput("v", "verbose output");
parser.addOption(verboseOutput);
const QCommandLineOption authOption("u", "set usename and pass", "username:password");
parser.addOption(authOption);
const QCommandLineOption domainAddressOption("d", "domain-server address", "127.0.0.1");
parser.addOption(domainAddressOption);
@ -81,6 +85,18 @@ ACClientApp::ACClientApp(int argc, char* argv[]) :
listenPort = parser.value(listenPortOption).toInt();
}
if (parser.isSet(authOption)) {
QStringList pieces = parser.value(authOption).split(":");
if (pieces.size() != 2) {
qDebug() << "-u should be followed by username:password";
parser.showHelp();
Q_UNREACHABLE();
}
_username = pieces[0];
_password = pieces[1];
}
Setting::init();
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
@ -117,6 +133,28 @@ ACClientApp::ACClientApp(int argc, char* argv[]) :
DependencyManager::get<AddressManager>()->handleLookupString(domainServerAddress, false);
auto accountManager = DependencyManager::get<AccountManager>();
accountManager->setIsAgent(true);
accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL);
if (_verbose) {
QString username = accountManager->getAccountInfo().getUsername();
qDebug() << "cached username is" << username << ", isLoggedIn =" << accountManager->isLoggedIn();
}
if (!_username.isEmpty()) {
connect(accountManager.data(), &AccountManager::loginComplete, this, [&](){
if (_verbose) {
qDebug() << "login successful";
}
});
connect(accountManager.data(), &AccountManager::loginFailed, this, [&](){
qDebug() << "login failed.";
});
accountManager->requestAccessToken(_username, _password);
}
QTimer* doTimer = new QTimer(this);
doTimer->setSingleShot(true);
connect(doTimer, &QTimer::timeout, this, &ACClientApp::timedOut);

View file

@ -47,6 +47,9 @@ private:
bool _sawAvatarMixer { false };
bool _sawAssetServer { false };
bool _sawMessagesMixer { false };
QString _username;
QString _password;
};
#endif //hifi_ACClientApp_h

View file

@ -55,7 +55,6 @@ ATPClientApp::ATPClientApp(int argc, char* argv[]) :
const QCommandLineOption listenPortOption("listenPort", "listen port", QString::number(INVALID_PORT));
parser.addOption(listenPortOption);
if (!parser.parse(QCoreApplication::arguments())) {
qCritical() << parser.errorText() << endl;
parser.showHelp();
@ -80,7 +79,6 @@ ATPClientApp::ATPClientApp(int argc, char* argv[]) :
const_cast<QLoggingCategory*>(&shared())->setEnabled(QtWarningMsg, false);
}
QStringList posArgs = parser.positionalArguments();
if (posArgs.size() != 1) {
qDebug() << "give remote url argument";
@ -120,7 +118,6 @@ ATPClientApp::ATPClientApp(int argc, char* argv[]) :
_password = pieces[1];
}
if (parser.isSet(listenPortOption)) {
_listenPort = parser.value(listenPortOption).toInt();
}
@ -141,7 +138,6 @@ ATPClientApp::ATPClientApp(int argc, char* argv[]) :
}
}
void ATPClientApp::connectToDomain(QString domainServerAddress) {
if (_verbose) {
@ -217,7 +213,6 @@ ATPClientApp::~ATPClientApp() {
delete _timeoutTimer;
}
void ATPClientApp::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
qDebug() << "domainConnectionRefused";
}