mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:30:39 +02:00
91 lines
3.2 KiB
C++
91 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include "entity.h"
|
|
#include <QSet>
|
|
#include <qsqlquery.h>
|
|
#include <QVariant>
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
#include "serversdk/databasetable.h"
|
|
#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(const QString& name, QString tokenData, const QString& decription = "mobile");
|
|
explicit Token(const QString& name);
|
|
~Token() override;
|
|
|
|
QByteArray jsonData(const QSet<QString> &filters = {}) const override;
|
|
bool fromJson(const QByteArray &data) override;
|
|
|
|
friend bool operator<(const Token &lToken, const Token &rToken){
|
|
return lToken.lastModified() < rToken.lastUpdate();
|
|
}
|
|
friend bool operator>(const Token &lToken, const Token &rToken){
|
|
return lToken.lastModified() > rToken.lastUpdate();
|
|
}
|
|
|
|
friend bool operator==(const Token &lToken, const 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();
|
|
}
|
|
|
|
|
|
const QSet<QString> &getFlags() const;
|
|
void setFlags(const QSet<QString> &flags);
|
|
|
|
QString idToStringWithoutBraces();
|
|
QString subjectIdToStringWithoutBraces();
|
|
|
|
void fromSQLRecord(const QSqlQuery& query);
|
|
void fromJSON(const QJsonObject &json);
|
|
QJsonObject toJSON() const;
|
|
|
|
static QByteArray tokensToColnodJson(const QHash<QString, std::shared_ptr<Token> > &tokens);
|
|
static QByteArray idsToJSON(const QList<QString> &ids);
|
|
|
|
private:
|
|
//QSet<QString> flags = {"NoValidity", "Enabled"};
|
|
};
|