File indexing completed on 2024-05-19 04:50:10

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *           (c) 2010 Ian Monroe <ian@monroe.nu>                                        *
0004  *           (c) 2013 Ralf Engels <ralf-engels@gmx.de>                                  *
0005  *                                                                                      *
0006  * This program is free software; you can redistribute it and/or modify it under        *
0007  * the terms of the GNU General Public License as published by the Free Software        *
0008  * Foundation; either version 2 of the License, or (at your option) version 3 or        *
0009  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0010  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0011  * version 3 of the license.                                                            *
0012  *                                                                                      *
0013  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0016  *                                                                                      *
0017  * You should have received a copy of the GNU General Public License along with         *
0018  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0019  ****************************************************************************************/
0020 
0021 
0022 #ifndef AMPACHEACCOUNTLOGIN_H
0023 #define AMPACHEACCOUNTLOGIN_H
0024 
0025 #include "NetworkAccessManagerProxy.h"
0026 
0027 #include <QDomDocument>
0028 #include <QObject>
0029 #include <QUrl>
0030 
0031 class QNetworkReply;
0032 
0033 #ifdef MAKE_AMPACHE_ACCOUNT_LOGIN_LIB
0034 #define AMPACHE_ACCOUNT_EXPORT Q_DECL_EXPORT
0035 #else
0036 #define AMPACHE_ACCOUNT_EXPORT Q_DECL_IMPORT
0037 #endif
0038 
0039 class AMPACHE_ACCOUNT_EXPORT AmpacheAccountLogin : public QObject
0040 {
0041     Q_OBJECT
0042     public:
0043         AmpacheAccountLogin ( const QUrl& url, const QString& username, const QString& password, QWidget* parent = nullptr );
0044         ~AmpacheAccountLogin() override;
0045         QUrl server() const { return m_server; }
0046         QString sessionId() const { return m_sessionId; }
0047         bool authenticated() const { return m_authenticated; }
0048         void reauthenticate();
0049 
0050     Q_SIGNALS:
0051         void loginSuccessful(); //!authentication was successful
0052         void finished(); //!authentication was or was not successful
0053 
0054     private Q_SLOTS:
0055         void authenticate( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e );
0056         void authenticationComplete( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e );
0057 
0058     private:
0059         int getVersion( const QDomDocument& doc ) const;
0060 
0061         /** Does general response verification.
0062             Emits finished if something is fishy.
0063             @returns true if the check was successful.
0064         */
0065         bool generalVerify( QNetworkReply *reply, const QDomDocument& doc, const NetworkAccessManagerProxy::Error &e );
0066 
0067         /** Returns the base url.
0068             You would need to add query items to use it. */
0069         QUrl getRequestUrl( const QString &action = QString() ) const;
0070 
0071         bool m_authenticated;
0072         QUrl m_server;
0073         QString m_username;
0074         QString m_password;
0075         QString m_sessionId;
0076 
0077         QNetworkReply *m_authRequest;
0078         QNetworkReply *m_pingRequest;
0079 };
0080 
0081 #endif // AMPACHEACCOUNTLOGIN_H