Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 1 addition & 1 deletion auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class auth_plugin_wp2moodle extends auth_plugin_base {
*/
function auth_plugin_wp2moodle() {
$this->authtype = 'wp2moodle';
$this->config = get_config('auth/wp2moodle');
$this->config = get_config('auth_wp2moodle');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @author Dan Abel <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle / wordpress single sign on (wp2moodle)
*
* source https://github.com/frumbert/wp2moodle-moodle
* Authentication Plugin: Wordpress 2 Moodle Single Sign On
*
* 2018-12-04 File created.
*/
function xmldb_auth_wp2moodle_install() {
global $CFG, $DB;

}
37 changes: 37 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @author Dan Abel <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle / wordpress single sign on (wp2moodle)
*
* source https://github.com/frumbert/wp2moodle-moodle
* Authentication Plugin: Wordpress 2 Moodle Single Sign On
*
* 2018-12-04 File created.
*/
defined('MOODLE_INTERNAL') || die();

function xmldb_auth_wp2moodle_upgrade($oldversion) {
global $CFG;

// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.

// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
$upgradeversion = 2017081401; // Used last known version + 1
if ($oldversion < $upgradeversion) {
// Convert info in config plugins from auth/wp2moodle to auth_wp2moodle.
upgrade_fix_config_auth_plugin_names('wp2moodle');
upgrade_fix_config_auth_plugin_defaults('wp2moodle');
upgrade_plugin_savepoint(true, $upgradeversion, 'auth', 'wp2moodle');
}

// Automatically generated Moodle v3.4.0 release upgrade line.
// Put any upgrade step following this.

// Automatically generated Moodle v3.5.0 release upgrade line.
// Put any upgrade step following this.

return true;
}
16 changes: 8 additions & 8 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

$SESSION->wantsurl = $CFG->wwwroot.'/';

$PASSTHROUGH_KEY = get_config('auth/wp2moodle', 'sharedsecret');
$PASSTHROUGH_KEY = get_config('auth_wp2moodle', 'sharedsecret');
if (!isset($PASSTHROUGH_KEY)) {
echo "Sorry, this plugin has not yet been configured. Please contact the Moodle administrator for details.";
}
Expand Down Expand Up @@ -111,12 +111,12 @@ function enrol_into_course($courseid, $userid, $roleid = 5) {
$userdata = decrypt_string($rawdata, $PASSTHROUGH_KEY);

// time (in minutes) before incoming link is considered invalid
$timeout = (integer) get_config('auth/wp2moodle', 'timeout');
$timeout = (integer) get_config('auth_wp2moodle', 'timeout');
if ($timeout == 0) { $timeout = 5; }

$default_firstname = get_config('auth/wp2moodle', 'firstname') ?: "no-firstname"; // php 5.3 ternary
$default_lastname = get_config('auth/wp2moodle', 'lastname') ?: "no-lastname";
$idnumber_prefix = get_config('auth/wp2moodle', 'idprefix') ?: "";
$default_firstname = get_config('auth_wp2moodle', 'firstname') ?: "no-firstname"; // php 5.3 ternary
$default_lastname = get_config('auth_wp2moodle', 'lastname') ?: "no-lastname";
$idnumber_prefix = get_config('auth_wp2moodle', 'idprefix') ?: "";

// if userdata didn't decrypt, then timestamp will = 0, so following code will be bypassed anyway (e.g. bad data)
$timestamp = (integer) get_key_value($userdata, "stamp"); // remote site should have set this to new DateTime("now").getTimestamp(); which is a unix timestamp (utc)
Expand Down Expand Up @@ -248,7 +248,7 @@ function enrol_into_course($courseid, $userid, $roleid = 5) {
}

// if the plugin auto-opens the course, then find the course this cohort enrols for and set it as the opener link
if (get_config('auth/wp2moodle', 'autoopen') == 'yes') {
if (get_config('auth_wp2moodle', 'autoopen') == 'yes') {
if ($enrolrow = $DB->get_record('enrol', array('enrol'=>'cohort','customint1'=>$cohortrow->id,'status'=>0))) {
$courseId = $enrolrow->courseid;
}
Expand Down Expand Up @@ -283,7 +283,7 @@ function enrol_into_course($courseid, $userid, $roleid = 5) {
foreach ($ids as $course) {
if ($DB->record_exists('course', array('idnumber'=>$course))) {
$courserow = $DB->get_record('course', array('idnumber'=>$course));
if (get_config('auth/wp2moodle', 'redirectnoenrol') !== 'yes') {
if (get_config('auth_wp2moodle', 'redirectnoenrol') !== 'yes') {
if (!enrol_try_internal_enrol($courserow->id, $user->id, $studentrow->id)) {
continue;
}
Expand All @@ -294,7 +294,7 @@ function enrol_into_course($courseid, $userid, $roleid = 5) {
}

// if auto-open is enabled, work out where to start (e.g. course homepage or a particular activity)
if (get_config('auth/wp2moodle', 'autoopen') !== 'no') {
if (get_config('auth_wp2moodle', 'autoopen') !== 'no') {
if ($courseId > 0) {
$SESSION->wantsurl = new moodle_url('/course/view.php', array('id'=>$courseId));
}
Expand Down
110 changes: 110 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* @author Dan Abel <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodle / wordpress single sign on (wp2moodle)
*
* source https://github.com/frumbert/wp2moodle-moodle
* Authentication Plugin: Wordpress 2 Moodle Single Sign On
*
* 2018-12-04 File created.
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
/**
* @see lib/moodle.lib.php for PARA_XXX definitions
*/

// $name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null
$settings->add(new admin_setting_configtext(
'auth_wp2moodle/sharedsecret',
get_string('auth_wp2moodle_secretkey', 'auth_wp2moodle'),
get_string('auth_wp2moodle_secretkey_desc', 'auth_wp2moodle'),
'this is not a secure key, change it'
));

// $name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null, $maxlength = 0
$settings->add(new admin_setting_configtext_with_maxlength(
'auth_wp2moodle/timeout',
get_string('auth_wp2moodle_timeout', 'auth_wp2moodle'),
get_string('auth_wp2moodle_timeout_desc', 'auth_wp2moodle'),
'5',
PARAM_INT,
3,
3
));

// $name, $visiblename, $description, $defaultsetting$, paramtype=PARAM_RAW, $size=null
$settings->add(new admin_setting_configtext(
'auth_wp2moodle/logoffurl',
get_string('auth_wp2moodle_logoffurl', 'auth_wp2moodle'),
get_string('auth_wp2moodle_logoffurl_desc', 'auth_wp2moodle'),
'',
PARAM_URL
));

// $name, $visiblename, $description, $defaultsetting, $choices
$settings->add(new admin_setting_configselect(
'auth_wp2moodle/autoopen',
get_string('auth_wp2moodle_autoopen', 'auth_wp2moodle'),
get_string('auth_wp2moodle_autoopen_desc', 'auth_wp2moodle'),
'yes',
array(
'yes'=> 'Yes',
'no'=> 'No'
)
));

// $name, $visiblename, $description, $defaultsetting, $choices
$settings->add(new admin_setting_configselect(
'auth_wp2moodle/updateuser',
get_string('auth_wp2moodle_updateuser', 'auth_wp2moodle'),
get_string('auth_wp2moodle_updateuser_desc', 'auth_wp2moodle'),
'yes',
array(
'yes'=> 'Yes',
'no'=> 'No'
)
));

// $name, $visiblename, $description, $defaultsetting, $choices
$settings->add(new admin_setting_configselect(
'auth_wp2moodle/redirectnoenrol',
get_string('auth_wp2moodle_redirectnoenrol', 'auth_wp2moodle'),
get_string('auth_wp2moodle_redirectnoenrol_desc', 'auth_wp2moodle'),
'no',
array(
'yes'=> 'Yes',
'no'=> 'No'
)
));


// $name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null
$settings->add(new admin_setting_configtext(
'auth_wp2moodle/firstname',
get_string('auth_wp2moodle_firstname', 'auth_wp2moodle'),
get_string('auth_wp2moodle_firstname_desc', 'auth_wp2moodle'),
'no-first-name',
PARAM_ALPHAEXT
));

// $name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null
$settings->add(new admin_setting_configtext(
'auth_wp2moodle/lastname',
get_string('auth_wp2moodle_lastname', 'auth_wp2moodle'),
get_string('auth_wp2moodle_lastname_desc', 'auth_wp2moodle'),
'no-last-name',
PARAM_ALPHAEXT
));

// $name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null
$settings->add(new admin_setting_configtext(
'auth_wp2moodle/idprefix',
get_string('auth_wp2moodle_idprefix', 'auth_wp2moodle'),
get_string('auth_wp2moodle_idprefix_desc', 'auth_wp2moodle'),
'',
PARAM_ALPHANUMEXT,
10
));
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2017081400; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2017081401; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2011112900; // Requires this Moodle version
$plugin->component = 'auth_wp2moodle'; // Full name of the plugin (used for diagnostics)
$plugin->maturity = MATURITY_STABLE;
Expand Down