MDL-60432 auth_cas: Update with PR changes

This commit is contained in:
Andrew Nicols 2018-12-14 13:26:49 +08:00
parent 26a07f2ebb
commit 3b017210d3
5 changed files with 44 additions and 39 deletions

View File

@ -360,17 +360,27 @@ class auth_plugin_cas extends auth_plugin_ldap {
* @return array List of arrays with keys url, iconurl and name.
*/
public function loginpage_idp_list($wantsurl) {
global $CFG;
$config = get_config('auth_cas');
$params = ["authCAS" => "CAS"];
$url = new moodle_url(get_login_url(), $params);
$iconurl = moodle_url::make_pluginfile_url(context_system::instance()->id,
'auth_cas',
'logo',
null,
'/',
$config->auth_logo);
$result[] = ['url' => $url, 'iconurl' => $iconurl, 'name' => $config->auth_name];
return $result;
if (empty($this->config->hostname)) {
// CAS is not configured.
return [];
}
$iconurl = moodle_url::make_pluginfile_url(
context_system::instance()->id,
'auth_cas',
'logo',
null,
'/',
$this->config->auth_logo);
return [
[
'url' => new moodle_url(get_login_url(), [
'authCAS' => 'CAS',
]),
'iconurl' => $iconurl,
'name' => format_string($this->config->auth_name),
],
];
}
}

View File

@ -27,6 +27,7 @@ $string['auth_cas_auth_name_description'] = 'Provide a name for the CAS authenti
$string['auth_cas_auth_logo'] = 'Authentication method logo';
$string['auth_cas_auth_logo_description'] = 'Provide a logo for the CAS authentication method that is familiar to your users.';
$string['auth_cas_auth_user_create'] = 'Create users externally';
$string['auth_cas_auth_service'] = 'CAS';
$string['auth_cas_baseuri'] = 'URI of the server (nothing if no baseUri)<br />For example, if the CAS server responds to host.domaine.fr/CAS/ then<br />cas_baseuri = CAS/';
$string['auth_cas_baseuri_key'] = 'Base URI';
$string['auth_cas_broken_password'] = 'You cannot proceed without changing your password, however there is no available page for changing it. Please contact your Moodle Administrator.';

View File

@ -15,33 +15,30 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Authentication Plugin: CAS Authentication
* Authentication Plugin: CAS Authentication.
*
* Authentication using CAS (Central Authentication Server).
*
* @package auth_cas
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package auth_cas
* @copyright 2018 Fabrice Ménard <menard.fabrice@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Serves the logo file settings.
*
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - justsend the file
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false|void
*/
function auth_cas_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
function auth_cas_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
if ($context->contextlevel != CONTEXT_SYSTEM) {
return false;
}
@ -50,26 +47,21 @@ function auth_cas_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
return false;
}
$itemid = 0;
// Use the itemid to retrieve any relevant data records and perform any security checks to see if the
// user really does have access to the file in question.
// Extract the filename / filepath from the $args array.
$filename = array_pop($args); // The last item in the $args array.
$filename = array_pop($args);
if (!$args) {
$filepath = '/'; // $args is empty => the path is '/'
$filepath = '/';
} else {
$filepath = '/'.implode('/', $args).'/'; // $args contains elements of the filepath
$filepath = '/' . implode('/', $args) . '/';
}
// Retrieve the file from the Files API.
$itemid = 0;
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'auth_cas', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false; // The file does not exist.
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
// From Moodle 2.3, use send_stored_file instead.
send_stored_file($file, null, 0, $forcedownload, $options);
}

View File

@ -48,7 +48,9 @@ if ($ADMIN->fulltree) {
// Authentication method name.
$settings->add(new admin_setting_configtext('auth_cas/auth_name',
get_string('auth_cas_auth_name', 'auth_cas'),
get_string('auth_cas_auth_name_description', 'auth_cas'), '', PARAM_RAW_TRIMMED));
get_string('auth_cas_auth_name_description', 'auth_cas'),
get_string('auth_cas_auth_service', 'auth_cas'),
PARAM_RAW_TRIMMED));
// Authentication method logo.
$opts = array('accepted_types' => array('.png', '.jpg', '.gif', '.webp', '.tiff', '.svg'));

View File

@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018121400; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2018112800; // Requires this Moodle version
$plugin->component = 'auth_cas'; // Full name of the plugin (used for diagnostics)