File indexing completed on 2024-04-21 15:32:07
0001 /** =========================================================== 0002 * @file 0003 * 0004 * This file is a part of KDE project 0005 * <a href="https://commits.kde.org/libmediawiki">libmediawiki</a> 0006 * 0007 * @date 2011-03-22 0008 * @brief a MediaWiki C++ interface for KDE 0009 * 0010 * @author Copyright (C) 2011-2012 by Gilles Caulier 0011 * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> 0012 * @author Copyright (C) 2011 by Manuel Campomanes 0013 * <a href="mailto:campomanes dot manuel at gmail dot com">campomanes dot manuel at gmail dot com</a> 0014 * @author Copyright (C) 2010 by Alexandre Mendes 0015 * <a href="mailto:alex dot mendes1988 at gmail dot com">alex dot mendes1988 at gmail dot com</a> 0016 * 0017 * This program is free software; you can redistribute it 0018 * and/or modify it under the terms of the GNU General 0019 * Public License as published by the Free Software Foundation; 0020 * either version 2, or (at your option) 0021 * any later version. 0022 * 0023 * This program is distributed in the hope that it will be useful, 0024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0026 * GNU General Public License for more details. 0027 * 0028 * ============================================================ */ 0029 0030 #ifndef MEDIAWIKI_LOGIN_H 0031 #define MEDIAWIKI_LOGIN_H 0032 0033 // Qt includes 0034 0035 #include <QString> 0036 #include <QNetworkCookieJar> 0037 0038 // Local includes 0039 0040 #include "job.h" 0041 #include "mediawiki_export.h" 0042 0043 0044 namespace mediawiki 0045 { 0046 0047 class MediaWiki; 0048 class LoginPrivate; 0049 /** 0050 * @brief Login job. 0051 * 0052 * Uses for log in a user. 0053 */ 0054 class MEDIAWIKI_EXPORT Login : public Job 0055 { 0056 Q_OBJECT 0057 Q_DECLARE_PRIVATE(Login) 0058 0059 public: 0060 0061 enum 0062 { 0063 /** 0064 * @brief You didn't set the login parameter 0065 */ 0066 LoginMissing = Job::UserDefinedError + 1, 0067 0068 /** 0069 * @brief You provided an illegal username 0070 */ 0071 IllegalUsername, 0072 0073 /** 0074 * @brief The username you provided doesn't exist 0075 */ 0076 UsernameNotExists, 0077 0078 /** 0079 * @brief You didn't set the lgpassword parameter or you left it empty 0080 */ 0081 PasswordMissing, 0082 0083 /** 0084 * @brief The password you provided is incorrect 0085 */ 0086 WrongPassword, 0087 0088 /** 0089 * @brief Same as WrongPass, returned when an authentication plugin rather than MediaWiki itself rejected the password 0090 */ 0091 WrongPluginPassword, 0092 0093 /** 0094 * @brief The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation 0095 */ 0096 IPAddressBlocked, 0097 0098 /** 0099 * @brief You've logged in too many times in a short time. 0100 */ 0101 TooManyConnections, 0102 0103 /** 0104 * @brief User is blocked 0105 */ 0106 UserBlocked, 0107 0108 /** 0109 * @brief Either you did not provide the login token or the sessionid cookie. Request again with the token and cookie given in this response 0110 */ 0111 TokenNeeded 0112 }; 0113 0114 public: 0115 0116 /** 0117 * @brief Constructs a Login job. 0118 * @param mediawiki the mediawiki concerned by the job 0119 * @param login the QObject parent 0120 * @param password the QObject parent 0121 * @param parent the QObject parent 0122 */ 0123 explicit Login(MediaWiki& mediawiki, const QString& login, const QString& password, QObject* const parent = nullptr); 0124 0125 /** 0126 * @brief Destroys the Login job. 0127 */ 0128 ~Login() override; 0129 0130 /** 0131 * @brief Starts the job asynchronously. 0132 */ 0133 void start() override; 0134 0135 private Q_SLOTS: 0136 0137 /** 0138 * @brief Send a request to get the token and the cookie. 0139 */ 0140 void doWorkSendRequest(); 0141 0142 /** 0143 * @brief Reads the xml 0144 * if the attribute value is equal to "NeedToken", try to log in the user 0145 * else if the attribute value is equal to "Success", the user is logged in 0146 * @param success true if the connection was completed successfully. 0147 */ 0148 void doWorkProcessReply(); 0149 }; 0150 0151 } // namespace mediawiki 0152 0153 #endif // LOGIN_H