#pragma once #include "entity.h" #include #include #include #include #include #include "serversdk/databasetable.h" #include 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 &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 &getFlags() const; void setFlags(const QSet &flags); QString idToStringWithoutBraces(); QString subjectIdToStringWithoutBraces(); void fromSQLRecord(const QSqlQuery& query); void fromJSON(const QJsonObject &json); QJsonObject toJSON() const; static QByteArray tokensToColnodJson(const QHash > &tokens); static QByteArray idsToJSON(const QList &ids); private: //QSet flags = {"NoValidity", "Enabled"}; };