mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
cleanup login/logout in menu, logout only when in
This commit is contained in:
parent
6165ca658a
commit
a8493ecaa2
9 changed files with 86 additions and 24 deletions
|
@ -70,7 +70,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
// TODO: failure case for not receiving a token
|
||||
accountManager.requestAccessToken(username, password);
|
||||
|
||||
connect(&accountManager, &AccountManager::receivedAccessToken, this, &DomainServer::requestCreationFromDataServer);
|
||||
connect(&accountManager, &AccountManager::loginComplete, this, &DomainServer::requestCreationFromDataServer);
|
||||
|
||||
} else {
|
||||
qDebug() << "Authentication was requested against" << qPrintable(_nodeAuthenticationURL.toString())
|
||||
|
@ -301,7 +301,7 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet<Ass
|
|||
void DomainServer::requestAuthenticationFromPotentialNode(const HifiSockAddr& senderSockAddr) {
|
||||
// this is a node we do not recognize and we need authentication - ask them to do so
|
||||
// by providing them the hostname they should authenticate with
|
||||
QByteArray authenticationRequestPacket = byteArrayWithPopluatedHeader(PacketTypeDomainServerAuthRequest);
|
||||
QByteArray authenticationRequestPacket = byteArrayWithPopulatedHeader(PacketTypeDomainServerAuthRequest);
|
||||
|
||||
QDataStream authPacketStream(&authenticationRequestPacket, QIODevice::Append);
|
||||
authPacketStream << _nodeAuthenticationURL;
|
||||
|
@ -417,7 +417,7 @@ NodeSet DomainServer::nodeInterestListFromPacket(const QByteArray& packet, int n
|
|||
void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const HifiSockAddr &senderSockAddr,
|
||||
const NodeSet& nodeInterestList) {
|
||||
|
||||
QByteArray broadcastPacket = byteArrayWithPopluatedHeader(PacketTypeDomainList);
|
||||
QByteArray broadcastPacket = byteArrayWithPopulatedHeader(PacketTypeDomainList);
|
||||
|
||||
// always send the node their own UUID back
|
||||
QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append);
|
||||
|
|
|
@ -227,9 +227,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
|
||||
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
|
||||
connect(nodeList, &NodeList::uuidChanged, this, &Application::updateWindowTitle);
|
||||
|
||||
connect(&AccountManager::getInstance(), SIGNAL(authenticationRequired()),
|
||||
Menu::getInstance(), SLOT(loginForCurrentDomain()));
|
||||
|
||||
// connect to appropriate slots on AccountManager
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
connect(&accountManager, &AccountManager::authRequired, Menu::getInstance(), &Menu::loginForCurrentDomain);
|
||||
connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);
|
||||
|
||||
_settings = new QSettings(this);
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ Menu::Menu() :
|
|||
_voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE),
|
||||
_boundaryLevelAdjust(0),
|
||||
_maxVoxelPacketsPerSecond(DEFAULT_MAX_VOXEL_PPS),
|
||||
_lastAdjust(usecTimestampNow())
|
||||
_lastAdjust(usecTimestampNow()),
|
||||
_loginAction(NULL)
|
||||
{
|
||||
Application *appInstance = Application::getInstance();
|
||||
|
||||
|
@ -86,13 +87,17 @@ Menu::Menu() :
|
|||
QAction::AboutRole);
|
||||
#endif
|
||||
|
||||
(addActionToQMenuAndActionHash(fileMenu,
|
||||
MenuOption::Login,
|
||||
0,
|
||||
this,
|
||||
SLOT(loginForCurrentDomain())));
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout, 0, &AccountManager::getInstance(), SLOT(logout()));
|
||||
_loginAction = addActionToQMenuAndActionHash(fileMenu, MenuOption::Logout);
|
||||
|
||||
// call our toggle login function now so the menu option is setup properly
|
||||
toggleLoginMenuItem();
|
||||
|
||||
// connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item
|
||||
connect(&accountManager, &AccountManager::loginComplete, this, &Menu::toggleLoginMenuItem);
|
||||
connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem);
|
||||
connect(&accountManager, &AccountManager::authEndpointChanged, this, &Menu::toggleLoginMenuItem);
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Scripts");
|
||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
|
||||
|
@ -1114,6 +1119,32 @@ void Menu::pasteToVoxel() {
|
|||
sendFakeEnterEvent();
|
||||
}
|
||||
|
||||
void Menu::toggleLoginMenuItem() {
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
disconnect(_loginAction, 0, 0, 0);
|
||||
|
||||
if (accountManager.isLoggedIn()) {
|
||||
// change the menu item to logout
|
||||
_loginAction->setText("Logout " + accountManager.getUsername());
|
||||
connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout);
|
||||
|
||||
_loginAction->setEnabled(true);
|
||||
} else {
|
||||
// change the menu item to login
|
||||
_loginAction->setText("Login");
|
||||
|
||||
// if we don't have a rootURL in the AccountManager we're in a domain that doesn't use auth
|
||||
// so setup the menu item according to the presence of that root URL
|
||||
if (accountManager.hasAuthEndpoint()) {
|
||||
connect(_loginAction, &QAction::triggered, this, &Menu::loginForCurrentDomain);
|
||||
_loginAction->setEnabled(true);
|
||||
} else {
|
||||
_loginAction->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::bandwidthDetails() {
|
||||
if (! _bandwidthDialog) {
|
||||
_bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(),
|
||||
|
|
|
@ -111,6 +111,8 @@ public slots:
|
|||
void exportSettings();
|
||||
void goTo();
|
||||
void pasteToVoxel();
|
||||
|
||||
void toggleLoginMenuItem();
|
||||
|
||||
private slots:
|
||||
void aboutApp();
|
||||
|
@ -172,6 +174,7 @@ private:
|
|||
QMenu* _activeScriptsMenu;
|
||||
QString replaceLastOccurrence(QChar search, QChar replace, QString string);
|
||||
quint64 _lastAdjust;
|
||||
QAction* _loginAction;
|
||||
};
|
||||
|
||||
namespace MenuOption {
|
||||
|
|
|
@ -34,7 +34,6 @@ const QString ACCOUNTS_GROUP = "accounts";
|
|||
|
||||
AccountManager::AccountManager() :
|
||||
_rootURL(),
|
||||
_username(),
|
||||
_networkAccessManager(),
|
||||
_pendingCallbackMap(),
|
||||
_accounts()
|
||||
|
@ -76,18 +75,22 @@ void AccountManager::logout() {
|
|||
settings.remove(keyURLString);
|
||||
|
||||
qDebug() << "Removed account info for" << _rootURL << "from in-memory accounts and .ini file";
|
||||
|
||||
emit logoutComplete();
|
||||
// the username has changed to blank
|
||||
emit usernameChanged(QString());
|
||||
|
||||
}
|
||||
|
||||
void AccountManager::setRootURL(const QUrl& rootURL) {
|
||||
if (_rootURL != rootURL) {
|
||||
_rootURL = rootURL;
|
||||
|
||||
// we have an auth URL change, set the username empty
|
||||
// we will need to ask for profile information again
|
||||
_username.clear();
|
||||
|
||||
qDebug() << "URL for node authentication has been changed to" << qPrintable(_rootURL.toString());
|
||||
qDebug() << "Re-setting authentication flow.";
|
||||
|
||||
// tell listeners that the auth endpoint has changed
|
||||
emit authEndpointChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +219,7 @@ bool AccountManager::checkAndSignalForAccessToken() {
|
|||
|
||||
if (!hasToken) {
|
||||
// emit a signal so somebody can call back to us and request an access token given a username and password
|
||||
emit authenticationRequired();
|
||||
emit authRequired();
|
||||
}
|
||||
|
||||
return hasToken;
|
||||
|
@ -265,7 +268,9 @@ void AccountManager::requestFinished() {
|
|||
DataServerAccountInfo freshAccountInfo(rootObject);
|
||||
_accounts.insert(rootURL, freshAccountInfo);
|
||||
|
||||
emit receivedAccessToken(rootURL);
|
||||
emit loginComplete(rootURL);
|
||||
// the username has changed to whatever came back
|
||||
emit usernameChanged(freshAccountInfo.getUsername());
|
||||
|
||||
// store this access token into the local settings
|
||||
QSettings localSettings;
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
const QByteArray& dataByteArray = QByteArray());
|
||||
|
||||
void setRootURL(const QUrl& rootURL);
|
||||
bool hasAuthEndpoint() { return !_rootURL.isEmpty(); }
|
||||
|
||||
bool isLoggedIn() { return !_rootURL.isEmpty() && hasValidAccessToken(); }
|
||||
bool hasValidAccessToken();
|
||||
|
@ -56,9 +57,11 @@ public slots:
|
|||
void requestError(QNetworkReply::NetworkError error);
|
||||
void logout();
|
||||
signals:
|
||||
void authenticationRequired();
|
||||
void receivedAccessToken(const QUrl& rootURL);
|
||||
void authRequired();
|
||||
void authEndpointChanged();
|
||||
void usernameChanged(const QString& username);
|
||||
void loginComplete(const QUrl& rootURL);
|
||||
void logoutComplete();
|
||||
private slots:
|
||||
void passSuccessToCallback();
|
||||
void passErrorToCallback(QNetworkReply::NetworkError errorCode);
|
||||
|
@ -71,7 +74,6 @@ private:
|
|||
const JSONCallbackParameters& callbackParams, const QByteArray& dataByteArray);
|
||||
|
||||
QUrl _rootURL;
|
||||
QString _username;
|
||||
QNetworkAccessManager _networkAccessManager;
|
||||
QMap<QNetworkReply*, JSONCallbackParameters> _pendingCallbackMap;
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include "AccountManager.h"
|
||||
|
||||
#include "DomainInfo.h"
|
||||
|
||||
DomainInfo::DomainInfo() :
|
||||
|
@ -20,7 +22,8 @@ DomainInfo::DomainInfo() :
|
|||
_publicKey(),
|
||||
_isConnected(false)
|
||||
{
|
||||
|
||||
// clear appropriate variables after a domain-server logout
|
||||
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete, this, &DomainInfo::logout);
|
||||
}
|
||||
|
||||
void DomainInfo::reset() {
|
||||
|
@ -98,3 +101,14 @@ void DomainInfo::setIsConnected(bool isConnected) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DomainInfo::logout() {
|
||||
// clear any information related to auth for this domain, assuming it had requested auth
|
||||
if (!_rootAuthenticationURL.isEmpty()) {
|
||||
_rootAuthenticationURL = QUrl();
|
||||
_connectionSecret = QUuid();
|
||||
_registrationToken = QByteArray();
|
||||
_publicKey = QString();
|
||||
_isConnected = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public:
|
|||
|
||||
private slots:
|
||||
void completedHostnameLookup(const QHostInfo& hostInfo);
|
||||
|
||||
void logout();
|
||||
signals:
|
||||
void hostnameChanged(const QString& hostname);
|
||||
void connectedToDomain(const QString& hostname);
|
||||
|
|
|
@ -76,6 +76,9 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
|||
|
||||
// clear our NodeList when the domain changes
|
||||
connect(&_domainInfo, &DomainInfo::hostnameChanged, this, &NodeList::reset);
|
||||
|
||||
// clear our NodeList when logout is requested
|
||||
connect(&AccountManager::getInstance(), &AccountManager::logoutComplete , this, &NodeList::reset);
|
||||
}
|
||||
|
||||
bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
|
||||
|
|
Loading…
Reference in a new issue