Skip to content

Commit

Permalink
MDL-60432 auth_cas: Update with PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Dec 14, 2018
1 parent 26a07f2 commit 3b01721
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
34 changes: 22 additions & 12 deletions auth/cas/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,27 @@ public function postlogout_hook($user) {
* @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),
],
];
}
}
1 change: 1 addition & 0 deletions auth/cas/lang/en/auth_cas.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$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.';
Expand Down
42 changes: 17 additions & 25 deletions auth/cas/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
4 changes: 3 additions & 1 deletion auth/cas/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
// 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'));
Expand Down
2 changes: 1 addition & 1 deletion auth/cas/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3b01721

Please sign in to comment.