File indexing completed on 2025-01-05 03:53:36

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-03-22
0007  * Description : a Iface C++ interface
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2011      by Alexandre Mendes <alex dot mendes1988 at gmail dot com>
0011  * SPDX-FileCopyrightText: 2011      by Peter Potrowl <peter dot potrowl at gmail dot com>
0012  * SPDX-FileCopyrightText: 2011      by Manuel Campomanes <campomanes dot manuel at gmail dot com>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #ifndef DIGIKAM_MEDIAWIKI_LOGIN_H
0019 #define DIGIKAM_MEDIAWIKI_LOGIN_H
0020 
0021 // Qt includes
0022 
0023 #include <QString>
0024 #include <QNetworkCookieJar>
0025 
0026 // Local includes
0027 
0028 #include "mediawiki_job.h"
0029 
0030 
0031 namespace MediaWiki
0032 {
0033 
0034 class Iface;
0035 class LoginPrivate;
0036 /**
0037  * @brief Login job.
0038  *
0039  * Uses for log in a user.
0040  */
0041 class Login : public Job
0042 {
0043     Q_OBJECT
0044     Q_DECLARE_PRIVATE(Login)
0045 
0046 public:
0047 
0048     enum
0049     {
0050         /**
0051          * @brief You didn't set the login parameter
0052          */
0053         LoginMissing = Job::UserDefinedError + 1,
0054 
0055         /**
0056          * @brief You provided an illegal username
0057          */
0058         IllegalUsername,
0059 
0060         /**
0061          * @brief The username you provided doesn't exist
0062          */
0063         UsernameNotExists,
0064 
0065         /**
0066         * @brief You didn't set the lgpassword parameter or you left it empty
0067         */
0068         PasswordMissing,
0069 
0070         /**
0071         * @brief The password you provided is incorrect
0072         */
0073         WrongPassword,
0074 
0075         /**
0076         * @brief Same as WrongPass, returned when an authentication plugin rather than Iface itself rejected the password
0077         */
0078         WrongPluginPassword,
0079 
0080         /**
0081         * @brief The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation
0082         */
0083         IPAddressBlocked,
0084 
0085         /**
0086         * @brief You've logged in too many times in a short time.
0087         */
0088         TooManyConnections,
0089 
0090         /**
0091         * @brief User is blocked
0092         */
0093         UserBlocked,
0094 
0095         /**
0096         * @brief Either you did not provide the login token or the sessionid cookie. Request again with the token and cookie given in this response
0097         */
0098         TokenNeeded
0099     };
0100 
0101 public:
0102 
0103     /**
0104      * @brief Constructs a Login job.
0105      * @param MediaWiki the MediaWiki concerned by the job
0106      * @param login the QObject parent
0107      * @param password the QObject parent
0108      * @param parent the QObject parent
0109      */
0110     explicit Login(Iface& MediaWiki,
0111                    const QString& login,
0112                    const QString& password,
0113                    QObject* const parent = nullptr);
0114 
0115     /**
0116      * @brief Destroys the Login job.
0117      */
0118     ~Login()     override;
0119 
0120     /**
0121      * @brief Starts the job asynchronously.
0122      */
0123     void start() override;
0124 
0125 private Q_SLOTS:
0126 
0127     /**
0128      * @brief Send a request to get the token and the cookie.
0129      */
0130     void doWorkSendRequest();
0131 
0132     /**
0133      * @brief Reads the xml
0134      * if the attribute value is equal to "NeedToken", try to log in the user
0135      * else if the attribute value is equal to "Success", the user is logged in
0136      * @param success true if the connection was completed successfully.
0137      */
0138     void doWorkProcessReply();
0139 };
0140 
0141 } // namespace MediaWiki
0142 
0143 #endif // DIGIKAM_MEDIAWIKI_LOGIN_H