From 227f60496d2259abd640aa802488607fd2975998 Mon Sep 17 00:00:00 2001 From: brindosch Date: Sun, 25 Aug 2019 17:39:08 +0200 Subject: [PATCH] resetPassword rework --- include/db/AuthTable.h | 7 ++++++- libsrc/hyperion/AuthManager.cpp | 2 +- src/hyperiond/hyperiond.cpp | 11 +---------- src/hyperiond/hyperiond.h | 2 +- src/hyperiond/main.cpp | 18 +++++++++++++++++- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/db/AuthTable.h b/include/db/AuthTable.h index 76b832f6..0cb7d15e 100644 --- a/include/db/AuthTable.h +++ b/include/db/AuthTable.h @@ -16,9 +16,14 @@ class AuthTable : public DBManager public: /// construct wrapper with auth table - AuthTable(QObject* parent = nullptr) + AuthTable(const QString& rootPath = "", QObject* parent = nullptr) : DBManager(parent) { + if(!rootPath.isEmpty()){ + // Init Hyperion database usage + setRootPath(rootPath); + setDatabaseName("hyperion"); + } // init Auth table setTable("auth"); // create table columns diff --git a/libsrc/hyperion/AuthManager.cpp b/libsrc/hyperion/AuthManager.cpp index 0f79724e..bd825515 100644 --- a/libsrc/hyperion/AuthManager.cpp +++ b/libsrc/hyperion/AuthManager.cpp @@ -12,7 +12,7 @@ AuthManager* AuthManager::manager = nullptr; AuthManager::AuthManager(QObject* parent) : QObject(parent) - , _authTable(new AuthTable(this)) + , _authTable(new AuthTable("",this)) , _metaTable(new MetaTable(this)) , _pendingRequests() , _authRequired(true) diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index fa9a67ad..8fde0c5c 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -55,7 +55,7 @@ HyperionDaemon* HyperionDaemon::daemon = nullptr; -HyperionDaemon::HyperionDaemon(const QString rootPath, QObject *parent, const bool& logLvlOverwrite, const bool& resetPassword) +HyperionDaemon::HyperionDaemon(const QString rootPath, QObject *parent, const bool& logLvlOverwrite) : QObject(parent) , _log(Logger::getInstance("DAEMON")) , _instanceManager(new HyperionIManager(rootPath, this)) @@ -93,15 +93,6 @@ HyperionDaemon::HyperionDaemon(const QString rootPath, QObject *parent, const bo if(!logLvlOverwrite) handleSettingsUpdate(settings::LOGGER, getSetting(settings::LOGGER)); - // reset password if requested from cmd - if(resetPassword){ - if(_authManager->resetHyperionUser()){ - Info(_log, "Password successfully resetted") - } else { - Error(_log, "Failed to reset password") - } - } - // init EffectFileHandler EffectFileHandler* efh = new EffectFileHandler(rootPath, getSetting(settings::EFFECTS), this); connect(this, &HyperionDaemon::settingsChanged, efh, &EffectFileHandler::handleSettingsUpdate); diff --git a/src/hyperiond/hyperiond.h b/src/hyperiond/hyperiond.h index 2edc3789..30fcc6ef 100644 --- a/src/hyperiond/hyperiond.h +++ b/src/hyperiond/hyperiond.h @@ -72,7 +72,7 @@ class HyperionDaemon : public QObject friend SysTray; public: - HyperionDaemon(QString rootPath, QObject *parent, const bool& logLvlOverwrite, const bool& resetPassword); + HyperionDaemon(QString rootPath, QObject *parent, const bool& logLvlOverwrite); ~HyperionDaemon(); /// diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index 7106a3af..04d68739 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -28,6 +28,7 @@ #include #include #include +#include <../../include/db/AuthTable.h> #ifdef ENABLE_X11 #include @@ -335,10 +336,25 @@ int main(int argc, char** argv) Info(log, "Set user data path to '%s'", QSTRING_CSTR(mDir.absolutePath())); + // reset Password without spawning daemon + if(parser.isSet(resetPassword)) + { + AuthTable* table = new AuthTable(userDataPath); + if(table->resetHyperionUser()){ + Info(log,"Password reset successfull"); + delete table; + exit(0); + } else { + Error(log,"Failed to reset password!"); + delete table; + exit(1); + } + } + HyperionDaemon* hyperiond = nullptr; try { - hyperiond = new HyperionDaemon(userDataPath, qApp, bool(logLevelCheck), parser.isSet(resetPassword)); + hyperiond = new HyperionDaemon(userDataPath, qApp, bool(logLevelCheck)); } catch (std::exception& e) {