14 using namespace Huggle;
16 QString
Login::Test =
"<login result=\"NeedToken\" token=\"";
18 Login::Login(QWidget *parent) : QDialog(parent), ui(new Ui::
Login)
22 this->LoginQuery = NULL;
23 this->timer =
new QTimer(
this);
24 connect(this->timer, SIGNAL(timeout()),
this, SLOT(on_Time()));
35 ui->Language->setCurrentIndex(0);
38 if (!QSslSocket::supportsSsl())
41 ui->checkBox->setEnabled(
false);
42 ui->checkBox->setChecked(
false);
44 ui->ButtonExit->setText(Core::Localize(
"[[main-system-exit]]"));
58 ui->progressBar->setValue(progress);
63 ui->ButtonExit->setText(Core::Localize(
"[[main-system-exit]]"));
64 ui->ButtonOK->setText(Core::Localize(
"[[login-start]]"));
65 ui->checkBox->setText(Core::Localize(
"[[login-ssl]]"));
66 ui->label_2->setText(Core::Localize(
"[[login-username]]"));
67 ui->pushButton->setText(Core::Localize(
"[[reload]]"));
68 ui->label_3->setText(Core::Localize(
"[[login-username]]"));
69 ui->label_4->setText(Core::Localize(
"[[login-project]]"));
70 ui->label_5->setText(Core::Localize(
"[[login-language]]"));
71 ui->label_7->setText(Core::Localize(
"[[login-password"));
76 ui->label_6->setText(Core::Localize(
"[[login-intro]]"));
82 ui->progressBar->setValue(0);
85 ui->lineEdit_3->setText(
"");
86 ui->ButtonOK->setText(Core::Localize(
"[[login-start]]"));
91 ui->lineEdit->setEnabled(
true);
92 ui->Language->setEnabled(
true);
93 ui->Project->setEnabled(
true);
94 ui->checkBox->setEnabled(QSslSocket::supportsSsl());
95 ui->lineEdit_2->setEnabled(
true);
96 ui->ButtonExit->setEnabled(
true);
97 ui->lineEdit_3->setEnabled(
true);
98 ui->pushButton->setEnabled(
true);
104 ui->Project->clear();
110 ui->Project->setCurrentIndex(0);
115 if (this->LoginQuery == NULL)
125 QDomNodeList l = d.elementsByTagName(
"rev");
134 if (wiki.open(QIODevice::WriteOnly))
136 wiki.write(l.at(0).toElement().text().toUtf8());
148 void Login::Disable()
150 ui->lineEdit->setDisabled(
true);
151 ui->Language->setDisabled(
true);
152 ui->Project->setDisabled(
true);
153 ui->checkBox->setDisabled(
true);
154 ui->ButtonExit->setDisabled(
true);
155 ui->lineEdit_3->setDisabled(
true);
156 ui->lineEdit_2->setDisabled(
true);
157 ui->pushButton->setDisabled(
true);
162 if (ui->tab->isVisible())
165 mb.setWindowTitle(
"Function not supported");
167 mb.setText(
"This function is not available for wmf wikis in this moment");
173 if (ui->lineEdit_2->text() ==
"Developer Mode")
182 ui->ButtonOK->setText(Core::Localize(
"[[cancel]]"));
184 this->timer->start(200);
187 void Login::PerformLogin()
189 ui->label_6->setText(Core::Localize(
"[[login-progress-start]]"));
193 this->LoginQuery->
SetAction(ActionLogin);
198 this->
_Status = WaitingForLoginQuery;
201 void Login::FinishLogin()
207 if (this->LoginQuery->
Result->Failed)
209 ui->label_6->setText(Core::Localize(
"[[login-fail]]") +
": " + this->LoginQuery->
Result->
ErrorMessage);
212 delete this->LoginQuery;
213 this->LoginQuery = NULL;
218 this->
_Status = WaitingForToken;
219 delete this->LoginQuery;
222 this->LoginQuery->
SetAction(ActionLogin);
235 ui->lineEdit_3->setText(pw);
241 if (this->LoginQuery != NULL)
245 if (this->LoginQuery->
Result->Failed)
247 ui->label_6->setText(Core::Localize(
"[[login-error-global]]") +
": " + this->LoginQuery->
Result->
ErrorMessage);
250 delete this->LoginQuery;
251 this->LoginQuery = NULL;
256 QDomNodeList l = d.elementsByTagName(
"rev");
259 ui->label_6->setText(
"Login failed unable to retrieve global config, the api query returned no data");
262 delete this->LoginQuery;
263 this->LoginQuery = NULL;
266 QDomElement data = l.at(0).toElement();
269 if (!Configuration::GlobalConfig_EnableAll)
272 ui->label_6->setText(
"Login failed because huggle is globally disabled");
275 delete this->LoginQuery;
276 this->LoginQuery = NULL;
279 delete this->LoginQuery;
280 this->LoginQuery = NULL;
281 this->
_Status = RetrievingWhitelist;
285 ui->label_6->setText(
"Login failed unable to parse the global config, see debug log for more details");
289 delete this->LoginQuery;
290 this->LoginQuery = NULL;
296 ui->label_6->setText(Core::Localize(
"[[login-progress-global]]"));
298 this->LoginQuery->
SetAction(ActionQuery);
300 this->LoginQuery->
Parameters =
"prop=revisions&format=xml&rvprop=content&rvlimit=1&titles=Huggle/Config";
304 void Login::FinishToken()
310 if (this->LoginQuery->
Result->Failed)
315 delete this->LoginQuery;
316 this->LoginQuery = NULL;
324 this->
_Status = RetrievingGlobalConfig;
327 delete this->LoginQuery;
328 this->LoginQuery = NULL;
331 void Login::RetrieveWhitelist()
343 list = list.replace(
"<!-- list -->",
"");
359 this->
_Status = RetrievingLocalConfig;
365 ui->label_6->setText(Core::Localize(
"[[login-progress-whitelist]]"));
367 wq->RetryOnTimeoutFailure =
false;
374 if (this->LoginQuery != NULL)
378 if (this->LoginQuery->
Result->Failed)
381 ui->label_6->setText(
"Login failed unable to retrieve local config: " + this->LoginQuery->
Result->
ErrorMessage);
384 delete this->LoginQuery;
385 this->LoginQuery = NULL;
390 QDomNodeList l = d.elementsByTagName(
"rev");
394 ui->label_6->setText(
"Login failed unable to retrieve local config, the api query returned no data");
397 delete this->LoginQuery;
398 this->LoginQuery = NULL;
401 QDomElement data = l.at(0).toElement();
404 if (!Configuration::LocalConfig_EnableAll)
407 ui->label_6->setText(
"Login failed because huggle is disabled");
410 delete this->LoginQuery;
411 this->LoginQuery = NULL;
414 delete this->LoginQuery;
415 this->LoginQuery = NULL;
416 this->
_Status = RetrievingUserConfig;
420 ui->label_6->setText(
"Login failed unable to parse the local config, see debug log for more details");
424 delete this->LoginQuery;
425 this->LoginQuery = NULL;
432 ui->label_6->setText(
"Retrieving local config");
434 this->LoginQuery->
SetAction(ActionQuery);
435 this->LoginQuery->
Parameters =
"prop=revisions&format=xml&rvprop=content&rvlimit=1&titles=Project:Huggle/Config";
441 if (this->LoginQuery != NULL)
445 if (this->LoginQuery->
Result->Failed)
448 ui->label_6->setText(
"Login failed unable to retrieve user config: " + this->LoginQuery->
Result->
ErrorMessage);
451 delete this->LoginQuery;
452 this->LoginQuery = NULL;
457 QDomNodeList l = d.elementsByTagName(
"rev");
462 ui->label_6->setText(
"Login failed unable to retrieve user config, the api query returned no data");
465 delete this->LoginQuery;
466 this->LoginQuery = NULL;
469 QDomElement data = l.at(0).toElement();
472 if (!Configuration::LocalConfig_EnableAll)
475 ui->label_6->setText(
"Login failed because you don't have enable:true in your personal config");
478 delete this->LoginQuery;
479 this->LoginQuery = NULL;
482 delete this->LoginQuery;
483 this->LoginQuery = NULL;
484 this->
_Status = RetrievingUser;
488 ui->label_6->setText(
"Login failed unable to parse the user config, see debug log for more details");
492 delete this->LoginQuery;
493 this->LoginQuery = NULL;
499 ui->label_6->setText(
"Retrieving user config");
501 QString page = Configuration::GlobalConfig_UserConf;
503 this->LoginQuery->
SetAction(ActionQuery);
504 this->LoginQuery->
Parameters =
"prop=revisions&rvprop=content&rvlimit=1&titles=" +
505 QUrl::toPercentEncoding(page);
511 if (this->LoginQuery != NULL)
515 if (this->LoginQuery->
Result->Failed)
518 ui->label_6->setText(
"Login failed unable to retrieve user info: " + this->LoginQuery->
Result->
ErrorMessage);
521 delete this->LoginQuery;
522 this->LoginQuery = NULL;
527 QDomNodeList l = d.elementsByTagName(
"r");
532 ui->label_6->setText(
"Login failed unable to retrieve user info, the api query returned no data");
535 delete this->LoginQuery;
536 this->LoginQuery = NULL;
542 Configuration::Rights.append(l.at(c).toElement().text());
545 if (Configuration::LocalConfig_RequireRollback && !Configuration::Rights.contains(
"rollback"))
548 ui->label_6->setText(
"Login failed because you don't have rollback permissions on this project");
551 delete this->LoginQuery;
552 this->LoginQuery = NULL;
555 delete this->LoginQuery;
556 this->LoginQuery = NULL;
565 ui->label_6->setText(
"Retrieving user info");
567 this->LoginQuery->
SetAction(ActionQuery);
568 this->LoginQuery->
Parameters =
"meta=userinfo&format=xml&uiprop=rights";
572 void Login::DeveloperMode()
580 void Login::DisplayError(QString message)
584 ui->label_6->setText(message);
598 if (this->
_Status != LoginDone)
600 QApplication::quit();
607 QString Result = this->LoginQuery->
Result->
Data;
608 if (!Result.contains((
"<login result")))
611 DisplayError(
"ERROR: The api.php responded with invalid text (webserver is down?), please check debug log for precise information");
615 Result = Result.mid(Result.indexOf(
"result=\"") + 8);
616 if (!Result.contains(
"\""))
619 DisplayError(
"ERROR: The api.php responded with invalid text (webserver is broken), please check debug log for precise information");
623 Result = Result.mid(0, Result.indexOf(
"\""));
625 if (Result ==
"Success")
630 if (Result ==
"EmptyPass")
633 DisplayError(
"The password you entered was empty");
637 if (Result ==
"WrongPass")
640 DisplayError(
"Your password is not correct");
644 if (Result ==
"NoName")
647 DisplayError(
"You provided no correct user name for login");
652 DisplayError(
"ERROR: The api.php responded with unknown result: " + Result);
658 QString token = this->
Token;
663 Core::Log(
"WARNING: the result of api request doesn't contain valid token");
664 Core::DebugLog(
"The token didn't contain the correct string, token was " + token);
665 return "<invalid token>";
668 if (!token.contains(
"\""))
672 Core::Log(
"WARNING: the result of api request doesn't contain valid token");
673 Core::DebugLog(
"The token didn't contain the closing mark, token was " + token);
674 return "<invalid token>";
676 token = token.mid(0, token.indexOf(
"\""));
680 void Login::on_ButtonOK_clicked()
695 void Login::on_ButtonExit_clicked()
700 void Login::on_Time()
707 case WaitingForLoginQuery:
710 case RetrievingWhitelist:
713 case WaitingForToken:
716 case RetrievingGlobalConfig:
719 case RetrievingLocalConfig:
722 case RetrievingUserConfig:
739 if (this->
_Status == LoginFailed)
743 ui->ButtonOK->setText(
"Login");
748 void Login::on_pushButton_clicked()
751 if(this->LoginQuery != NULL)
753 delete this->LoginQuery;
758 this->LoginQuery->
SetAction(ActionQuery);
759 this->timer->start(200);
761 this->ui->ButtonOK->setText(Core::Localize(
"[[cancel]]"));
762 this->LoginQuery->
Parameters =
"prop=revisions&format=xml&rvprop=content&rvlimit=1&titles=Project:Huggle/List";
766 void Login::on_Language_currentIndexChanged(
const QString &arg1)
static QString HuggleVersion
Version.
void Process()
Execute query.
virtual bool SafeDelete()
Use this if you are not sure if you can delete this object in this moment.
static QString WikiDB
Path to a file where information about wikis are stored.
static void Log(QString Message)
Write text to terminal as well as ring log.
static QString UserName
User name.
static bool Restricted
When this is true most of functions will not work.
void Progress(const int progress)
virtual bool Processed()
Returns true in case that query is processed.
_Status
Status of a query.
QString OverrideWiki
You can change this to url of different wiki than a project.
Window that is displayed as first when huggle is started.
static void Shutdown()
Terminate the process, call this after you release all resources and finish all queries.
void RetrieveGlobalConfig()
void CancelLogin()
Cancel currently running login attempt.
void Reset()
Reset the interface to default.
void Enable()
Enable parts of interface.
void RetrieveLocalConfig()
static QString Language
Language selected by user this is only a language of interface.
static QString Password
Password.
static QStringList WhiteList
Data of wl.
void SetAction(const Action action)
Change the action type.
static bool ParseUserConfig(QString config)
bool UsingPOST
Whether the query will submit parameters using POST data.
static WikiSite Project
currently selected project
void RetrievePrivateConfig()
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
static bool ParseGlobalConfig(QString config)
Parse all information from global config on meta.
static QList< Language * > LocalizationData
Languages D:
QString ErrorMessage
If query is in error the reason for error is stored here.
QString Parameters
Parameters for action, for example page title.
static bool WhitelistDisabled
Whitelist is not useable.
static bool UsingSSL
If SSL is being used.
static bool ParseLocalConfig(QString config)
Parse all information from local config, this function is used in login.
bool ProcessOutput()
This function make sure that login result is done.
static QList< WikiSite * > ProjectList
List of projects.
static QString GlobalConfigurationWikiAddress
URL of wiki that contains a global config.
QString Token
The token obtained from login.
static MainWindow * Main
Pointer to main.
This class can be used to execute any kind of api query on any wiki.
QString Data
Data retrieved by query.
QueryResult * Result
Result of query, see documentation of QueryResult for more.