$name = $password = $domain = null;
extract($this->extractRequestParams());
- $params = new FauxRequest(array (
- 'wpName' => $name,
- 'wpPassword' => $password,
- 'wpDomain' => $domain,
- 'wpRemember' => ''
- ));
-
$result = array ();
+ // Make sure noone is trying to guess the password brut-force
$nextLoginIn = $this->getNextLoginTimeout();
if ($nextLoginIn > 0) {
$result['result'] = 'NeedToWait';
return;
}
+ $params = new FauxRequest(array (
+ 'wpName' => $name,
+ 'wpPassword' => $password,
+ 'wpDomain' => $domain,
+ 'wpRemember' => ''
+ ));
+
$loginForm = new LoginForm($params);
switch ($loginForm->authenticateUserData()) {
case LoginForm :: SUCCESS :
$elapse = (time() - $val['lastReqTime']) / 1000; // in seconds
$canRetryIn = ApiLogin::calculateDelay($val) - $elapse;
- $canRetryIn = $canRetryIn < 0 ? 0 : $canRetryIn;
- return $canRetryIn;
+ return $canRetryIn < 0 ? 0 : $canRetryIn;
}
/**
// Printer may not be initialized if the extractRequestParams() fails for the main module
if (!isset ($this->mPrinter)) {
- $this->mPrinter = $this->createPrinterByName(self :: API_DEFAULT_FORMAT);
+ // The printer has not been created yet. Try to manually get formatter value.
+ $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
+ if (!in_array($value, $this->mFormatNames))
+ $value = self::API_DEFAULT_FORMAT;
+
+ $this->mPrinter = $this->createPrinterByName($value);
if ($this->mPrinter->getNeedsRawData())
$this->getResult()->setRawMode();
}
//
$errMessage = array (
'code' => $e->getCodeString(), 'info' => $e->getMessage());
- ApiResult :: setContent($errMessage, $this->makeHelpMsg());
+
+ // Only print the help message when this is for the developer, not runtime
+ if ($this->mPrinter->getIsHtml())
+ ApiResult :: setContent($errMessage, $this->makeHelpMsg());
} else {
//
* Execute the actual module, without any error handling
*/
protected function executeAction() {
- $action = $format = $version = null;
- extract($this->extractRequestParams());
- $this->mShowVersions = $version;
+
+ $params = $this->extractRequestParams();
+
+ $this->mShowVersions = $params['version'];
+ $action = $params['action'];
// Instantiate the module requested by the user
$module = new $this->mModules[$action] ($this, $action);
$this->mPrinter = $module->getCustomPrinter();
if (is_null($this->mPrinter)) {
// Create an appropriate printer
- $this->mPrinter = $this->createPrinterByName($format);
+ $this->mPrinter = $this->createPrinterByName($params['format']);
}
if ($this->mPrinter->getNeedsRawData())