mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 22:40:48 +02:00
75 lines
2.9 KiB
C++
75 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <QDateTime>
|
|
#include "serversdk/databasetable.h"
|
|
#include <QSqlQuery>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
|
|
class Token : public serversdk::DatabaseTable {
|
|
Q_OBJECT
|
|
TABLE_PROPERTY(QString, id, setId, QString())
|
|
TABLE_PROPERTY(int, authErrors, setAuthErrors, 255)
|
|
TABLE_PROPERTY(QString, description, setDescription, "")
|
|
TABLE_PROPERTY(bool, enabled, setEnabled, true)
|
|
TABLE_PROPERTY(QDateTime, lastUpdate, setLastUpdate, QDateTime())
|
|
TABLE_PROPERTY(QString, name, setName, "")
|
|
TABLE_PROPERTY(bool, noValidity, setNoValidity, true)
|
|
TABLE_PROPERTY(int, timeToLive, setTimeToLive, 255)
|
|
TABLE_PROPERTY(int, tokenBits, setTokenBits, 32)
|
|
TABLE_PROPERTY(QString, tokenData, setTokenData, QString())
|
|
TABLE_PROPERTY(QString, tokenType, setTokenType, "Token")
|
|
TABLE_PROPERTY(QString, subjectId, setSubjectId, QString())
|
|
TABLE_PROPERTY(QDateTime, lastModified, setLastModified, QDateTime())
|
|
TABLE_PROPERTY(bool, deleted, setDeleted, false)
|
|
|
|
|
|
|
|
public:
|
|
/**
|
|
* # Needed values to proper sync
|
|
*
|
|
* * id - primary key
|
|
* * lastModified - when it was edited/modified
|
|
* * tokenData - key to open doors
|
|
* * subjectId - no way of make unassinged token (token without subject)
|
|
*
|
|
*/
|
|
|
|
explicit Token() = default;
|
|
~Token() override;
|
|
|
|
QByteArray jsonData(const QSet<QString> &filters = {}) const override;
|
|
bool fromJson(const QByteArray &data) override;
|
|
|
|
friend bool operator<(const std::shared_ptr<Token> &lToken, const std::shared_ptr<Token> &rToken){
|
|
return lToken->lastModified() < rToken->lastUpdate();
|
|
}
|
|
friend bool operator>(const std::shared_ptr<Token> &lToken, const std::shared_ptr<Token> &rToken){
|
|
return lToken->lastModified() > rToken->lastUpdate();
|
|
}
|
|
friend bool operator==(const std::shared_ptr<Token> &lToken, const std::shared_ptr<Token> &rToken)
|
|
{
|
|
return lToken->id() == rToken->id() &&
|
|
lToken->name() == rToken->name() &&
|
|
lToken->description() == rToken->description() &&
|
|
lToken->lastUpdate() == rToken->lastUpdate() &&
|
|
lToken->tokenType() == rToken->tokenType() &&
|
|
lToken->tokenBits() == rToken->tokenBits() &&
|
|
lToken->tokenData() == rToken->tokenData() &&
|
|
lToken->timeToLive() == rToken->timeToLive() &&
|
|
lToken->authErrors() == rToken->authErrors() &&
|
|
lToken->noValidity() == rToken->noValidity() &&
|
|
lToken->enabled() == rToken->enabled() &&
|
|
lToken->subjectId() == rToken->subjectId();
|
|
}
|
|
|
|
void fromSQLRecord(const QSqlQuery& query);
|
|
|
|
static QByteArray tokensToColnodJson(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
|
static QByteArray idsToJSON(const QList<QString> &ids);
|
|
|
|
private:
|
|
};
|