webservice MDL-21351 token error message more explicit

This commit is contained in:
jerome mouneyrac 2010-01-18 07:41:53 +00:00
parent cedc5b828a
commit 3785c9e221
2 changed files with 8 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
$string['accessexception'] = 'Access control exception'; $string['accessexception'] = 'Access control exception';
$string['activatehttps'] = 'connect with HTTPS to see the token'; $string['activatehttps'] = '******************';
$string['addfunction'] = 'Add function'; $string['addfunction'] = 'Add function';
$string['addfunctionhelp'] = 'Select the function to add to the service.'; $string['addfunctionhelp'] = 'Select the function to add to the service.';
$string['addrequiredcapability'] = 'Assign/Unassign the required capability'; $string['addrequiredcapability'] = 'Assign/Unassign the required capability';
@ -10,6 +10,7 @@ $string['actwebserviceshhdr'] = 'Active web service protocols';
$string['apiexplorer'] = 'API explorer'; $string['apiexplorer'] = 'API explorer';
$string['apiexplorernotavalaible'] = 'API explorer not available yet.'; $string['apiexplorernotavalaible'] = 'API explorer not available yet.';
$string['arguments'] = 'Arguments'; $string['arguments'] = 'Arguments';
$string['authmethod'] = 'Authentication method';
$string['configwebserviceplugins'] = 'For security reasons enable only protocols that are used.'; $string['configwebserviceplugins'] = 'For security reasons enable only protocols that are used.';
$string['context'] = 'Context'; $string['context'] = 'Context';
$string['createtoken'] = 'Create token'; $string['createtoken'] = 'Create token';
@ -31,6 +32,9 @@ $string['function'] = 'Function';
$string['functions'] = 'Functions'; $string['functions'] = 'Functions';
$string['generalstructure'] = 'General structure'; $string['generalstructure'] = 'General structure';
$string['httpswarning'] = 'Token strings are only displayed if your connection is secured (https)'; $string['httpswarning'] = 'Token strings are only displayed if your connection is secured (https)';
$string['invalidiptoken'] = 'Invalid token - your IP is not supported';
$string['invalidtimedtoken'] = 'Invalid token - token expired';
$string['invalidtoken'] = 'Invalid token - token not found';
$string['iprestriction'] = 'IP restriction'; $string['iprestriction'] = 'IP restriction';
$string['manageprotocols'] = 'Manage protocols'; $string['manageprotocols'] = 'Manage protocols';
$string['managetokens'] = 'Manage tokens'; $string['managetokens'] = 'Manage tokens';

View file

@ -157,15 +157,15 @@ abstract class webservice_server implements webservice_server_interface {
} else { } else {
if (!$token = $DB->get_record('external_tokens', array('token'=>$this->token, 'tokentype'=>EXTERNAL_TOKEN_PERMANENT))) { if (!$token = $DB->get_record('external_tokens', array('token'=>$this->token, 'tokentype'=>EXTERNAL_TOKEN_PERMANENT))) {
// TODO: MDL-12886 log failed login attempts // TODO: MDL-12886 log failed login attempts
throw new webservice_access_exception('Invalid token'); throw new webservice_access_exception(get_string('invalidtoken', 'webservice'));
} }
if ($token->validuntil and $token->validuntil < time()) { if ($token->validuntil and $token->validuntil < time()) {
throw new webservice_access_exception('Invalid token'); throw new webservice_access_exception(get_string('invalidtimedtoken', 'webservice'));
} }
if ($token->iprestriction and !address_in_subnet(getremoteaddr(), $token->iprestriction)) { if ($token->iprestriction and !address_in_subnet(getremoteaddr(), $token->iprestriction)) {
throw new webservice_access_exception('Invalid token'); throw new webservice_access_exception(get_string('invalidiptoken', 'webservice'));
} }
$this->restricted_context = get_context_instance_by_id($token->contextid); $this->restricted_context = get_context_instance_by_id($token->contextid);