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

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 "personalaccesstokeninfo.h"
0008 #include "utils.h"
0009 
0010 #include <QLocale>
0011 
0012 PersonalAccessTokenInfo::PersonalAccessTokenInfo() = default;
0013 
0014 QDebug operator<<(QDebug d, const PersonalAccessTokenInfo &t)
0015 {
0016     d << "mBypassTwoFactor " << t.bypassTwoFactor();
0017     d << "mName " << t.name();
0018     d << "mLastTokenPart " << t.lastTokenPart();
0019     d << "mCreatedAt " << t.createdAt();
0020     return d;
0021 }
0022 
0023 void PersonalAccessTokenInfo::parsePersonalAccessTokenInfo(const QJsonObject &replyObject)
0024 {
0025     mName = replyObject.value(QLatin1String("name")).toString();
0026     mLastTokenPart = replyObject.value(QLatin1String("lastTokenPart")).toString();
0027     mBypassTwoFactor = replyObject.value(QLatin1String("bypassTwoFactor")).toBool();
0028     setCreatedAt(Utils::parseIsoDate(QStringLiteral("createdAt"), replyObject));
0029 }
0030 
0031 qint64 PersonalAccessTokenInfo::createdAt() const
0032 {
0033     return mCreatedAt;
0034 }
0035 
0036 void PersonalAccessTokenInfo::setCreatedAt(qint64 newCreatedAt)
0037 {
0038     mCreatedAt = newCreatedAt;
0039     if (mCreatedAt != -1) {
0040         QLocale l;
0041         mCreateAtDisplayDateTime = l.toString(QDateTime::fromMSecsSinceEpoch(mCreatedAt), QLocale::LongFormat);
0042     }
0043 }
0044 
0045 const QString &PersonalAccessTokenInfo::createAtDisplayDateTime() const
0046 {
0047     return mCreateAtDisplayDateTime;
0048 }
0049 
0050 bool PersonalAccessTokenInfo::bypassTwoFactor() const
0051 {
0052     return mBypassTwoFactor;
0053 }
0054 
0055 void PersonalAccessTokenInfo::setBypassTwoFactor(bool newBypassTwoFactor)
0056 {
0057     mBypassTwoFactor = newBypassTwoFactor;
0058 }
0059 
0060 const QString &PersonalAccessTokenInfo::name() const
0061 {
0062     return mName;
0063 }
0064 
0065 void PersonalAccessTokenInfo::setName(const QString &newName)
0066 {
0067     mName = newName;
0068 }
0069 
0070 const QString &PersonalAccessTokenInfo::lastTokenPart() const
0071 {
0072     return mLastTokenPart;
0073 }
0074 
0075 void PersonalAccessTokenInfo::setLastTokenPart(const QString &newLastTokenPart)
0076 {
0077     mLastTokenPart = newLastTokenPart;
0078 }
0079 
0080 bool PersonalAccessTokenInfo::isValid() const
0081 {
0082     return !mName.isEmpty() && !mLastTokenPart.isEmpty() && (mCreatedAt != -1);
0083 }