File indexing completed on 2025-02-23 04:35:13

0001 // SPDX-FileCopyrightText: 2021 Linus Jahn <lnj@kaidan.im>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "credentials.h"
0005 
0006 #include <QUrl>
0007 
0008 using namespace QInvidious;
0009 
0010 QString Credentials::username() const
0011 {
0012     return m_username;
0013 }
0014 
0015 void Credentials::setUsername(const QString &username)
0016 {
0017     m_username = username;
0018 }
0019 
0020 void Credentials::setUsername(QStringView username)
0021 {
0022     m_username = username.toString();
0023 }
0024 
0025 std::optional<QNetworkCookie> Credentials::cookie() const
0026 {
0027     return m_cookie;
0028 }
0029 
0030 void Credentials::setCookie(const std::optional<QNetworkCookie> &cookie)
0031 {
0032     m_cookie = cookie;
0033 }
0034 
0035 bool Credentials::isAnonymous() const
0036 {
0037     return !m_cookie.has_value() || m_username.isEmpty();
0038 }
0039 
0040 Credentials::Credentials(QString username, QString cookie)
0041 {
0042     setUsername(username);
0043     setCookie(QNetworkCookie(cookie.toUtf8()));
0044 }