mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Hyperion JSON-API (#1727)
This commit is contained in:
@@ -15,7 +15,6 @@ AuthManager::AuthManager(QObject *parent, bool readonlyMode)
|
||||
, _authTable(new AuthTable("", this, readonlyMode))
|
||||
, _metaTable(new MetaTable(this, readonlyMode))
|
||||
, _pendingRequests()
|
||||
, _authRequired(true)
|
||||
, _timer(new QTimer(this))
|
||||
, _authBlockTimer(new QTimer(this))
|
||||
{
|
||||
@@ -36,13 +35,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)
|
||||
@@ -201,6 +200,8 @@ QVector<AuthManager::AuthDefinition> AuthManager::getPendingRequests() const
|
||||
def.comment = entry.comment;
|
||||
def.id = entry.id;
|
||||
def.timeoutTime = entry.timeoutTime - QDateTime::currentMSecsSinceEpoch();
|
||||
def.tan = entry.tan;
|
||||
def.caller = nullptr;
|
||||
finalVec.append(def);
|
||||
}
|
||||
return finalVec;
|
||||
@@ -208,20 +209,26 @@ QVector<AuthManager::AuthDefinition> AuthManager::getPendingRequests() const
|
||||
|
||||
bool AuthManager::renameToken(const QString &id, const QString &comment)
|
||||
{
|
||||
if (_authTable->renameToken(id, comment))
|
||||
if (_authTable->idExist(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
if (_authTable->renameToken(id, comment))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthManager::deleteToken(const QString &id)
|
||||
{
|
||||
if (_authTable->deleteToken(id))
|
||||
if (_authTable->idExist(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
if (_authTable->deleteToken(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -231,9 +238,7 @@ void AuthManager::handleSettingsUpdate(settings::type type, const QJsonDocument
|
||||
if (type == settings::NETWORK)
|
||||
{
|
||||
const QJsonObject &obj = config.object();
|
||||
_authRequired = obj["apiAuth"].toBool(true);
|
||||
_localAuthRequired = obj["localApiAuth"].toBool(false);
|
||||
_localAdminAuthRequired = obj["localAdminAuth"].toBool(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user