File indexing completed on 2024-05-12 16:25:55

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "oauthinfo.h"
0008 
0009 #include "utils.h"
0010 
0011 OauthInfo::OauthInfo() = default;
0012 
0013 QDebug operator<<(QDebug d, const OauthInfo &t)
0014 {
0015     d.space() << "Identifier" << t.identifier();
0016     d.space() << "Active" << t.active();
0017     d.space() << "Name" << t.name();
0018     d.space() << "ClientId" << t.clientId();
0019     d.space() << "ClientSecret" << t.clientSecret();
0020     d.space() << "RedirectUri" << t.redirectUri();
0021     d.space() << "CreatedBy" << t.createdBy();
0022     return d;
0023 }
0024 
0025 bool OauthInfo::operator==(const OauthInfo &other) const
0026 {
0027     return mIdentifier == other.identifier() && mActive == other.active() && mName == other.name() && mClientId == other.clientId()
0028         && mClientSecret == other.clientSecret() && mRedirectUri == other.redirectUri() && mCreatedBy == other.createdBy();
0029 }
0030 
0031 void OauthInfo::parseOauthInfo(const QJsonObject &replyObject, bool restApi)
0032 {
0033     mIdentifier = replyObject[QLatin1String("_id")].toString();
0034     mActive = replyObject[QLatin1String("active")].toBool();
0035     mName = replyObject[QLatin1String("name")].toString();
0036     mClientId = replyObject[QLatin1String("clientId")].toString();
0037     mClientSecret = replyObject[QLatin1String("clientSecret")].toString();
0038     mRedirectUri = replyObject[QLatin1String("redirectUri")].toString();
0039     // TODO _updatedAt
0040     const QJsonObject createdBy = replyObject[QLatin1String("_createdBy")].toObject();
0041     mCreatedBy = createdBy[QLatin1String("username")].toString();
0042     // {"_id":"system","username":"system"}
0043     if (replyObject.contains(QLatin1String("_createdAt"))) {
0044         if (restApi) {
0045             setCreatedDateTime(QDateTime::fromMSecsSinceEpoch(Utils::parseIsoDate(QStringLiteral("_createdAt"), replyObject)));
0046         } else {
0047             setCreatedDateTime(QDateTime::fromMSecsSinceEpoch(Utils::parseDate(QStringLiteral("_createdAt"), replyObject)));
0048         }
0049     }
0050 }
0051 
0052 const QString &OauthInfo::identifier() const
0053 {
0054     return mIdentifier;
0055 }
0056 
0057 void OauthInfo::setIdentifier(const QString &newIdentifier)
0058 {
0059     mIdentifier = newIdentifier;
0060 }
0061 
0062 bool OauthInfo::active() const
0063 {
0064     return mActive;
0065 }
0066 
0067 void OauthInfo::setActive(bool newActive)
0068 {
0069     mActive = newActive;
0070 }
0071 
0072 const QString &OauthInfo::name() const
0073 {
0074     return mName;
0075 }
0076 
0077 void OauthInfo::setName(const QString &newName)
0078 {
0079     mName = newName;
0080 }
0081 
0082 const QString &OauthInfo::clientId() const
0083 {
0084     return mClientId;
0085 }
0086 
0087 void OauthInfo::setClientId(const QString &newClientId)
0088 {
0089     mClientId = newClientId;
0090 }
0091 
0092 const QString &OauthInfo::clientSecret() const
0093 {
0094     return mClientSecret;
0095 }
0096 
0097 void OauthInfo::setClientSecret(const QString &newClientSecret)
0098 {
0099     mClientSecret = newClientSecret;
0100 }
0101 
0102 const QString &OauthInfo::redirectUri() const
0103 {
0104     return mRedirectUri;
0105 }
0106 
0107 void OauthInfo::setRedirectUri(const QString &newRedirectUri)
0108 {
0109     mRedirectUri = newRedirectUri;
0110 }
0111 
0112 const QString &OauthInfo::createdBy() const
0113 {
0114     return mCreatedBy;
0115 }
0116 
0117 void OauthInfo::setCreatedBy(const QString &newCreatedBy)
0118 {
0119     mCreatedBy = newCreatedBy;
0120 }
0121 
0122 const QDateTime &OauthInfo::createdDateTime() const
0123 {
0124     return mCreatedDateTime;
0125 }
0126 
0127 void OauthInfo::setCreatedDateTime(const QDateTime &newCreatedDateTime)
0128 {
0129     mCreatedDateTime = newCreatedDateTime;
0130 }