diff --git a/include/db/AuthTable.h b/include/db/AuthTable.h index c6495ea5..161c3856 100644 --- a/include/db/AuthTable.h +++ b/include/db/AuthTable.h @@ -8,6 +8,11 @@ #include #include +namespace hyperion { +const char DEFAULT_USER[] = "Hyperion"; +const char DEFAULT_PASSWORD[] = "hyperion"; +} + /// /// @brief Authentication table interface /// @@ -149,10 +154,10 @@ public: inline bool resetHyperionUser() { QVariantMap map; - map["password"] = calcPasswordHashOfUser("Hyperion", "hyperion"); + map["password"] = calcPasswordHashOfUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD); VectorPair cond; - cond.append(CPair("user", "Hyperion")); + cond.append(CPair("user", hyperion::DEFAULT_USER)); return updateRecord(cond, map); } diff --git a/include/hyperion/AuthManager.h b/include/hyperion/AuthManager.h index 3ee594c5..a7750552 100644 --- a/include/hyperion/AuthManager.h +++ b/include/hyperion/AuthManager.h @@ -3,6 +3,8 @@ #include #include +#include + //qt #include #include @@ -172,7 +174,7 @@ public slots: /// @param usr the defined user /// @return The token /// - QString getUserToken(const QString &usr = "Hyperion") const; + QString getUserToken(const QString &usr = hyperion::DEFAULT_USER) const; /// /// @brief Get all available token entries diff --git a/libsrc/api/API.cpp b/libsrc/api/API.cpp index cc7d13be..a98f1a1f 100644 --- a/libsrc/api/API.cpp +++ b/libsrc/api/API.cpp @@ -417,7 +417,7 @@ bool API::updateHyperionPassword(const QString &password, const QString &newPass if (!_adminAuthorized) return false; bool res; - QMetaObject::invokeMethod(_authManager, "updateUserPassword", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, "Hyperion"), Q_ARG(QString, password), Q_ARG(QString, newPassword)); + QMetaObject::invokeMethod(_authManager, "updateUserPassword", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, DEFAULT_USER), Q_ARG(QString, password), Q_ARG(QString, newPassword)); return res; } @@ -490,7 +490,7 @@ bool API::getPendingTokenRequests(QVector &map) bool API::isUserTokenAuthorized(const QString &userToken) { bool res; - QMetaObject::invokeMethod(_authManager, "isUserTokenAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, "Hyperion"), Q_ARG(QString, userToken)); + QMetaObject::invokeMethod(_authManager, "isUserTokenAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, DEFAULT_USER), Q_ARG(QString, userToken)); if (res) { _authorized = true; @@ -521,7 +521,7 @@ bool API::isTokenAuthorized(const QString &token) bool API::isUserAuthorized(const QString &password) { bool res; - QMetaObject::invokeMethod(_authManager, "isUserAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, "Hyperion"), Q_ARG(QString, password)); + QMetaObject::invokeMethod(_authManager, "isUserAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, DEFAULT_USER), Q_ARG(QString, password)); if (res) { _authorized = true; @@ -535,7 +535,7 @@ bool API::isUserAuthorized(const QString &password) bool API::hasHyperionDefaultPw() { bool res; - QMetaObject::invokeMethod(_authManager, "isUserAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, "Hyperion"), Q_ARG(QString, "hyperion")); + QMetaObject::invokeMethod(_authManager, "isUserAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, DEFAULT_USER), Q_ARG(QString, DEFAULT_PASSWORD)); return res; } diff --git a/libsrc/hyperion/AuthManager.cpp b/libsrc/hyperion/AuthManager.cpp index 931443a7..fd4bd071 100644 --- a/libsrc/hyperion/AuthManager.cpp +++ b/libsrc/hyperion/AuthManager.cpp @@ -36,13 +36,13 @@ AuthManager::AuthManager(QObject *parent, bool readonlyMode) connect(_authBlockTimer, &QTimer::timeout, this, &AuthManager::checkAuthBlockTimeout); // init with default user and password - if (!_authTable->userExist("Hyperion")) + if (!_authTable->userExist(hyperion::DEFAULT_USER)) { - _authTable->createUser("Hyperion", "hyperion"); + _authTable->createUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD); } // update Hyperion user token on startup - _authTable->setUserToken("Hyperion"); + _authTable->setUserToken(hyperion::DEFAULT_USER); } AuthManager::AuthDefinition AuthManager::createToken(const QString &comment)