Skip to content

Commit

Permalink
IOMAD: update to have per tenant login pages and instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
turf212 committed Jun 7, 2024
1 parent 22a5385 commit 5d4e0de
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
15 changes: 12 additions & 3 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// IOMAD
require_once($CFG->dirroot . '/local/iomad/lib/company.php');
$companyid = iomad::get_my_companyid(context_system::instance(), false);
if (!empty($companyid)) {
$postfix = "_$companyid";
} else {
$postfix = "";
}

if ($hassiteconfig) {
/* @var admin_root $ADMIN */
$ADMIN->locate('modules')->set_sorting(true);
Expand Down Expand Up @@ -100,11 +109,11 @@
$temp->add(new admin_setting_configselect('limitconcurrentlogins',
new lang_string('limitconcurrentlogins', 'core_auth'),
new lang_string('limitconcurrentlogins_desc', 'core_auth'), 0, $options));
$temp->add(new admin_setting_configtext('alternateloginurl', new lang_string('alternateloginurl', 'auth'),
$temp->add(new admin_setting_configtext('alternateloginurl'.$postfix, new lang_string('alternateloginurl', 'auth'),
new lang_string('alternatelogin', 'auth', htmlspecialchars(get_login_url(), ENT_COMPAT)), ''));
$temp->add(new admin_setting_configtext('forgottenpasswordurl', new lang_string('forgottenpasswordurl', 'auth'),
$temp->add(new admin_setting_configtext('forgottenpasswordurl'.$postfix, new lang_string('forgottenpasswordurl', 'auth'),
new lang_string('forgottenpassword', 'auth'), '', PARAM_URL));
$temp->add(new admin_setting_confightmleditor('auth_instructions', new lang_string('instructions', 'auth'),
$temp->add(new admin_setting_confightmleditor('auth_instructions'.$postfix, new lang_string('instructions', 'auth'),
new lang_string('authinstructions', 'auth'), ''));
$setting = new admin_setting_configtext('allowemailaddresses', new lang_string('allowemailaddresses', 'admin'),
new lang_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS);
Expand Down
16 changes: 15 additions & 1 deletion auth/classes/output/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use renderer_base;
use stdClass;
use templatable;
use iomad;

/**
* Login renderable class.
Expand Down Expand Up @@ -85,6 +86,15 @@ class login implements renderable, templatable {
public function __construct(array $authsequence, $username = '') {
global $CFG, $OUTPUT, $PAGE;

// IOMAD
require_once($CFG->dirroot . '/local/iomad/lib/company.php');
$companyid = iomad::get_my_companyid(context_system::instance(), false);
if (!empty($companyid)) {
$postfix = "_$companyid";
} else {
$postfix = "";
}

$this->username = $username;

$languagedata = new \core\output\language_menu($PAGE);
Expand All @@ -106,7 +116,11 @@ public function __construct(array $authsequence, $username = '') {
$this->signupurl = new moodle_url('/login/signup.php');

// Authentication instructions.
$this->instructions = $CFG->auth_instructions;
$auth_instructions = "auth_instructions" . $postfix;
if (empty($CFG->$auth_instructions)) {
$CFG->$auth_instructions = $CFG->auth_instructions;
}
$this->instructions = $CFG->$auth_instructions;
if (is_enabled_auth('none')) {
$this->instructions = get_string('loginstepsnone');
} else if ($CFG->registerauth == 'email' && empty($this->instructions)) {
Expand Down
14 changes: 12 additions & 2 deletions login/forgot_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@

$token = optional_param('token', false, PARAM_ALPHANUM);

// IOMAD
require_once($CFG->dirroot . '/local/iomad/lib/company.php');
$companyid = iomad::get_my_companyid(context_system::instance(), false);
if (!empty($companyid)) {
$postfix = "_$companyid";
} else {
$postfix = "";
}

$PAGE->set_url('/login/forgot_password.php');
$systemcontext = context_system::instance();
$PAGE->set_context($systemcontext);
Expand All @@ -53,8 +62,9 @@
$PAGE->set_heading($COURSE->fullname);

// if alternatepasswordurl is defined, then we'll just head there
if (!empty($CFG->forgottenpasswordurl)) {
redirect($CFG->forgottenpasswordurl);
$forgottenpasswordurl = "forgottenpasswordurl" . $postfix;
if (!empty($CFG->$forgottenpasswordurl)) {
redirect($CFG->$forgottenpasswordurl);
}

// if you are logged in then you shouldn't be here!
Expand Down
11 changes: 8 additions & 3 deletions login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
$errorcode = 0;

// IOMAD - Set the theme if the server hostname matches one of ours.
$postfix = "";
if ($DB->get_manager()->table_exists('company') &&
$company = $DB->get_record('company', array('hostname' => $_SERVER["SERVER_NAME"]))) {
$hascompanybyurl = true;
Expand All @@ -98,8 +99,10 @@
$SESSION->company = $company;
$wantedcompanyid = $company->id;
$wantedcompanyshort = $company->shortname;
$postfix = "_" . $wantedcompanyid;
} else {
$hascompanybyurl = false;
$postfix = "_" . $wantedcompanyid;
}

// login page requested session test
Expand Down Expand Up @@ -399,8 +402,9 @@
}

/// Redirect to alternative login URL if needed
if (!empty($CFG->alternateloginurl)) {
$loginurl = new moodle_url($CFG->alternateloginurl);
$alternateloginurl = "alternateloginurl" . $postfix;
if (!empty($CFG->$alternateloginurl)) {
$loginurl = new moodle_url($CFG->$alternateloginurl);

$loginurlstr = $loginurl->out(false);

Expand Down Expand Up @@ -435,7 +439,8 @@
}

// IOMAD - changes to display the instructions.
if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_instructions)) {
$auth_instructions = "auth_instructions" . $postfix;
if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->$auth_instructions)) {
if (!empty($CFG->local_iomad_signup_showinstructions)) {
$show_instructions = true;
} else {
Expand Down

0 comments on commit 5d4e0de

Please sign in to comment.