mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 13:00:41 +02:00
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "entity.h"
|
|
#include <QSet>
|
|
#include <qsqlquery.h>
|
|
#include <QVariant>
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
|
|
class Token : public Entity {
|
|
public:
|
|
// using Entity::Entity;
|
|
|
|
/**
|
|
* # 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)
|
|
*
|
|
*/
|
|
|
|
Token() = default;
|
|
Token(const QString& name, QString tokenData, const QString& decription = "mobile");
|
|
explicit Token(const QString& name);
|
|
~Token() override;
|
|
|
|
friend bool operator<(const Token &lToken, const Token &rToken){
|
|
return lToken.getLastModified() < rToken.getLastUpdate();
|
|
}
|
|
friend bool operator>(const Token &lToken, const Token &rToken){
|
|
return lToken.getLastModified() > rToken.getLastUpdate();
|
|
}
|
|
friend bool operator==(const Token &lToken, const Token &rToken){
|
|
return lToken.getId() == rToken.getId() &&
|
|
lToken.getName() == rToken.getName() &&
|
|
lToken.getDescription() == rToken.getDescription() &&
|
|
lToken.getLastUpdate() == rToken.getLastUpdate() &&
|
|
lToken.tokenType == rToken.tokenType &&
|
|
lToken.tokenBits == rToken.tokenBits &&
|
|
lToken.tokenData == rToken.tokenData &&
|
|
lToken.timeToLive == rToken.timeToLive &&
|
|
lToken.authErrors == rToken.authErrors &&
|
|
lToken.flags == rToken.flags &&
|
|
lToken.subjectId == rToken.subjectId;
|
|
}
|
|
|
|
|
|
const QString &getTokenType() const;
|
|
void setTokenType(const QString &tokenType);
|
|
int getTokenBits() const;
|
|
void setTokenBits(int tokenBits);
|
|
const QString &getTokenData() const;
|
|
void setTokenData(const QString &tokenData);
|
|
int getTimeToLive() const;
|
|
void setTimeToLive(int timeToLive);
|
|
int getAuthErrors() const;
|
|
void setAuthErrors(int authErrors);
|
|
const QSet<QString> &getFlags() const;
|
|
void setFlags(const QSet<QString> &flags);
|
|
const QUuid &getSubjectId() const;
|
|
void setSubjectId(const QUuid &subjectId);
|
|
|
|
|
|
QString subjectIdToStringWithoutBraces();
|
|
|
|
void fromSQLRecord(const QSqlQuery& query);
|
|
void fromJSON(const QJsonObject &json) override;
|
|
QJsonObject toJSON() const override;
|
|
|
|
static QByteArray tokensToJSON(const QHash<QUuid, Token> &tokens);
|
|
|
|
private:
|
|
QString tokenType = "Token";
|
|
int tokenBits = 32;
|
|
QString tokenData;
|
|
int timeToLive = 255;
|
|
int authErrors = 255;
|
|
QSet<QString> flags = {"NoValidity", "Enabled"};
|
|
QUuid subjectId;
|
|
};
|