Returning 2 flags from l10n_client::validate_api_key(), 1 to reflect if connection was built up properly (just a boolean, not distuingishing between reasons in case of a failure), the other to reflect API validating success status.

Using this presenting a slightly more meaningfull error msg to user in case the connection would fail.
Fixes Ticket #1504
This commit is contained in:
Joe7
2011-01-12 00:05:11 +01:00
parent d74aad072d
commit 049f2af1c9
2 changed files with 14 additions and 7 deletions

View File

@@ -74,9 +74,11 @@ class Admin_Languages_Controller extends Admin_Controller {
private function _save_api_key($form) {
$new_key = $form->sharing->api_key->value;
if ($new_key && !l10n_client::validate_api_key($new_key)) {
$form->sharing->api_key->add_error("invalid", 1);
$valid = false;
if ($new_key) {
list($connected, $valid) = l10n_client::validate_api_key($new_key);
if (!$valid) {
$form->sharing->api_key->add_error($connected ? "invalid" : "noconn", 1);
}
} else {
$valid = true;
}
@@ -119,7 +121,8 @@ class Admin_Languages_Controller extends Admin_Controller {
array("server-link" => html::mark_clean(html::anchor($server_link))))
: t("API key"))
->value($api_key)
->error_messages("invalid", t("The API key you provided is invalid."));
->error_messages("invalid", t("The API key you provided is invalid."))
->error_messages("noconn", t("Could not connect to remote server to validate the API key."));
$group->submit("save")->value(t("Save settings"));
if ($api_key && $this->_outgoing_translations_count()) {
// TODO: UI improvement: hide API key / save button when API key is set.