mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:10:37 +02:00
153 lines
3.6 KiB
C++
153 lines
3.6 KiB
C++
#include "token.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <qjsondocument.h>
|
|
#include <utility>
|
|
|
|
|
|
Token::Token(const QString& name, QString tokenData, const QString& decription)
|
|
{
|
|
this->setName(name);
|
|
this->tokenData = std::move(tokenData);
|
|
this->setDescription(decription);
|
|
this->setId(QUuid::createUuid());
|
|
}
|
|
|
|
Token::Token(const QString &name)
|
|
{
|
|
this->setName(name);
|
|
}
|
|
|
|
Token::~Token()
|
|
= default;
|
|
|
|
|
|
void Token::fromJSON(const QJsonObject &json) {
|
|
Entity::fromJSON(json);
|
|
|
|
tokenType = json["tokenType"].toString();
|
|
tokenBits = json["tokenBits"].toInt();
|
|
tokenData = json["tokenData"].toString();
|
|
timeToLive = json["timeToLive"].toInt();
|
|
authErrors = json["authErrors"].toInt();
|
|
const auto &flagsArray = json["flags"].toArray();
|
|
flags.clear();
|
|
for(const auto &flag : flagsArray){
|
|
flags.insert(flag.toString());
|
|
}
|
|
subjectId = json["subjectId"].toString();
|
|
}
|
|
|
|
QJsonObject Token::toJSON() const {
|
|
QJsonObject json = Entity::toJSON();
|
|
json.insert("tokenType", tokenType);
|
|
json["tokenBits"] = tokenBits;
|
|
json["tokenType"] = tokenType;
|
|
json["tokenBits"] = tokenBits;
|
|
json["tokenData"] = tokenData;
|
|
json["timeToLive"] = timeToLive;
|
|
json["authErrors"] = authErrors;
|
|
json["flags"] = QJsonArray::fromStringList(flags.toList());
|
|
json["subjectId"] = subjectId.toString().mid(1,36);
|
|
|
|
return json;
|
|
}
|
|
|
|
QByteArray Token::tokensToJSON(const QHash<QUuid, Token> &tokens)
|
|
{
|
|
QJsonObject items;
|
|
QJsonArray jsonTokens;
|
|
for (const auto& token : tokens)
|
|
{
|
|
jsonTokens.push_back(token.toJSON());
|
|
}
|
|
items.insert("items", jsonTokens);
|
|
QJsonDocument doc;
|
|
doc.setObject(items);
|
|
return doc.toJson();
|
|
}
|
|
|
|
void Token::fromSQLRecord(const QSqlQuery& query)
|
|
{
|
|
setId(query.value(0).toUuid());
|
|
authErrors = query.value(1).toInt();
|
|
setDescription(query.value(2).toString());
|
|
QSet<QString> flags;
|
|
if (query.value(6).toBool())
|
|
flags.insert("NoValidity");
|
|
if (query.value(3).toBool())
|
|
flags.insert("Enabled");
|
|
this->flags = flags;
|
|
QDateTime date = query.value(4).toDateTime();
|
|
setLastUpdate(date.toMSecsSinceEpoch());
|
|
setName(query.value(5).toString());
|
|
timeToLive = query.value(7).toInt();
|
|
tokenBits = query.value(8).toInt();
|
|
tokenData = query.value(9).toString();
|
|
tokenType = query.value(10).toString();
|
|
subjectId = query.value(11).toUuid();
|
|
date = query.value(12).toDateTime();
|
|
setLastModified(date.toMSecsSinceEpoch());
|
|
setDeleted(query.value(13).toBool());
|
|
}
|
|
|
|
const QString &Token::getTokenType() const {
|
|
return tokenType;
|
|
}
|
|
|
|
void Token::setTokenType(const QString &tokenType) {
|
|
Token::tokenType = tokenType;
|
|
}
|
|
|
|
int Token::getTokenBits() const {
|
|
return tokenBits;
|
|
}
|
|
|
|
void Token::setTokenBits(int tokenBits) {
|
|
Token::tokenBits = tokenBits;
|
|
}
|
|
|
|
const QString &Token::getTokenData() const {
|
|
return tokenData;
|
|
}
|
|
|
|
void Token::setTokenData(const QString &tokenData) {
|
|
Token::tokenData = tokenData;
|
|
}
|
|
|
|
int Token::getTimeToLive() const {
|
|
return timeToLive;
|
|
}
|
|
|
|
void Token::setTimeToLive(int timeToLive) {
|
|
Token::timeToLive = timeToLive;
|
|
}
|
|
|
|
int Token::getAuthErrors() const {
|
|
return authErrors;
|
|
}
|
|
|
|
void Token::setAuthErrors(int authErrors) {
|
|
Token::authErrors = authErrors;
|
|
}
|
|
|
|
const QSet<QString> &Token::getFlags() const {
|
|
return flags;
|
|
}
|
|
|
|
void Token::setFlags(const QSet<QString> &flags) {
|
|
Token::flags = flags;
|
|
}
|
|
|
|
const QUuid &Token::getSubjectId() const {
|
|
return subjectId;
|
|
}
|
|
|
|
void Token::setSubjectId(const QUuid &subjectId) {
|
|
Token::subjectId = subjectId;
|
|
}
|
|
|
|
QString Token::subjectIdToStringWithoutBraces(){
|
|
return subjectId.toString().mid(1,36);
|
|
}
|