Skip to content

Commit

Permalink
mnet MDL-21466 change "WS auth not enable" for "Web Service Authentic…
Browse files Browse the repository at this point in the history
…ation plugin is disabled" message + add hard coded ws error message string into lang file.
  • Loading branch information
mouneyrac committed Jan 29, 2010
1 parent 5b7984a commit b0a9a0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lang/en_utf8/webservice.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$string['accessexception'] = 'Access control exception';
$string['accessnotallowed'] = 'Access to web service not allowed';
$string['activatehttps'] = '******************';
$string['addcapabilitytousers'] = 'Check users capability';
$string['addcapabilitytousersdescription'] = 'To use web services, users need to have two different capabilities: \'/webservice:createtoken\' and a capability matching the web service protocols (\'webservice/rest:use\', \'webservice/soap:use\', ...).';
Expand Down Expand Up @@ -63,6 +64,8 @@
$string['key'] = 'Key';
$string['manageprotocols'] = 'Manage protocols';
$string['managetokens'] = 'Manage tokens';
$string['missingpassword'] = 'Missing password';
$string['missingusername'] = 'Missing username';
$string['norequiredcapability'] = 'No required capability';
$string['notoken'] = 'The token list is empty.';
$string['onesystemcontrolling'] = 'One system controlling Moodle with token';
Expand Down Expand Up @@ -111,6 +114,9 @@
$string['webservices'] = 'Web services';
$string['webservicesoverview'] = 'Overview';
$string['webservicetokens'] = 'Web service tokens';
$string['wrongusernamepassword'] = 'Wrong username or password';
$string['wsauthmissing'] = 'The web service authentication plugin is missing.';
$string['wsauthnotenabled'] = 'The web service authentication plugin is disabled.';
$string['wsdocumentation'] = 'Web service documentation';
$string['wsdocumentationdisable'] = 'Web service documentation is disabled.';
$string['wsdocumentationintro'] = 'Following is a listing of web service functions available for the username <b>$a</b>.<br/>To create a client we advise you to read the <a href=\"http://docs.moodle.org/en/Development:Creating_a_web_service_and_a_web_service_function#Create_your_own_client\">Moodle documentation</a>';
Expand Down
12 changes: 6 additions & 6 deletions webservice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ protected function authenticate_user() {
}

if (!is_enabled_auth('webservice')) {
throw new webservice_access_exception('WS auth not enabled');
throw new webservice_access_exception(get_string('wsauthnotenabled', 'webservice'));
}

if (!$auth = get_auth_plugin('webservice')) {
throw new webservice_access_exception('WS auth missing');
throw new webservice_access_exception(get_string('wsauthmissing', 'webservice'));
}

// NOTE: the exception details are here for debugging only, it is controlled via the $CFG->degug
Expand All @@ -143,17 +143,17 @@ protected function authenticate_user() {
$this->restricted_context = get_context_instance(CONTEXT_SYSTEM);

if (!$this->username) {
throw new webservice_access_exception('Missing username');
throw new webservice_access_exception(get_string('missingusername', 'webservice'));
}

if (!$this->password) {
throw new webservice_access_exception('Missing password');
throw new webservice_access_exception(get_string('missingpassword', 'webservice'));
}

if (!$auth->user_login_webservice($this->username, $this->password)) {
// log failed login attempts
add_to_log(1, 'webservice', get_string('simpleauthlog', 'webservice'), '' , get_string('failedtolog', 'webservice').": ".$this->username."/".$this->password." - ".getremoteaddr() , 0);
throw new webservice_access_exception('Wrong username or password');
throw new webservice_access_exception(get_string('wrongusernamepassword', 'webservice'));
}

$user = $DB->get_record('user', array('username'=>$this->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0), '*', MUST_EXIST);
Expand Down Expand Up @@ -188,7 +188,7 @@ protected function authenticate_user() {
$this->userid = $user->id;

if (!has_capability("webservice/$this->wsname:use", $this->restricted_context)) {
throw new webservice_access_exception('Access to web service not allowed');
throw new webservice_access_exception(get_string('accessnotallowed', 'webservice'));
}

external_api::set_context_restriction($this->restricted_context);
Expand Down
10 changes: 5 additions & 5 deletions webservice/wsdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ protected function authenticate_user() {
}

if (!is_enabled_auth('webservice')) {
throw new webservice_access_exception('WS auth not enabled');
throw new webservice_access_exception(get_string('wsauthnotenabled', 'webservice'));
}

if (!$auth = get_auth_plugin('webservice')) {
throw new webservice_access_exception('WS auth missing');
throw new webservice_access_exception(get_string('wsauthmissing', 'webservice'));
}

if (!$this->username) {
throw new webservice_access_exception('Missing username');
throw new webservice_access_exception(get_string('missingusername', 'webservice'));
}

if (!$this->password) {
throw new webservice_access_exception('Missing password');
throw new webservice_access_exception(get_string('missingpassword', 'webservice'));
}

if (!$auth->user_login_webservice($this->username, $this->password)) {
throw new webservice_access_exception('Wrong username or password');
throw new webservice_access_exception(get_string('wrongusernamepassword', 'webservice'));
}

$this->webserviceuser = $DB->get_record('user', array('username'=>$this->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0), '*', MUST_EXIST);
Expand Down

0 comments on commit b0a9a0c

Please sign in to comment.