Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use moodle's jquery and jquery-ui. #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
49 changes: 32 additions & 17 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function config_form($config, $err, $user_fields) {
$dbman = $DB->get_manager();

$table_course_mapping = $this->get_course_mapping_xmldb();
$table_role_mapping = $this->get_role_mapping_xmldb();
$table_role_mapping = $this->get_role_mapping_xmldb();

if(isset($config->supportcourses) && $config->supportcourses == 'internal') {
if(!$dbman->table_exists($table_course_mapping)) {
Expand Down Expand Up @@ -216,9 +216,9 @@ function validate_form($form, &$err) {
}

if ($form->supportcourses == 'external') {
if ($form->externalcoursemappingdsn == '' || $form->externalcoursemappingsql == '' || $form->externalrolemappingdsn == '' || $form->externalrolemappingsql == '') {
if ($form->externalcoursemappingdsn == '' || $form->externalcoursemappingsql == '' || $form->externalrolemappingdsn == '' || $form->externalrolemappingsql == '') {
$err['samlexternal'] = get_string('auth_saml_errorsamlexternal', 'auth_saml', $form->samllib);
}
}
}
else if($form->supportcourses == 'internal') {

Expand All @@ -228,7 +228,7 @@ function validate_form($form, &$err) {
if (isset($form->update_courses_id)) {
foreach ($form->update_courses_id as $course_id) {
$course = $form->{'course_' . $course_id};
if (!empty($course[1]) && !empty($course[2])) {
if (!empty($course[1]) && !empty($course[2])) {
$lms_course_form_id[$course_id] = $course[0];
$saml_course_form_id[$course_id] = $course[1] . '_' . $course[2];
}
Expand All @@ -244,7 +244,7 @@ function validate_form($form, &$err) {
$lms_course_form_id[$i] = $new_course[0];
$saml_course_form_id[$i] = $new_course[1] . '_' . $new_course[2];
}
}
}
}
//Comment the next line if you want let duplicate lms mapping
$err['course_mapping']['lms'] = array_diff_key($lms_course_form_id, array_unique($lms_course_form_id));
Expand Down Expand Up @@ -365,8 +365,8 @@ function process_config($config) {
if (!isset ($config->samllogoinfo)) {
$config->samllogoinfo = 'SAML login';
}
if (!isset ($config->autologin)) {
$config->autologin = false;
if (!isset ($config->autologin)) {
$config->autologin = false;
}
if (!isset ($config->samllogfile)) {
$config->samllogfile = '';
Expand All @@ -381,16 +381,16 @@ function process_config($config) {
$config->ignoreinactivecourses = '';
}
if (!isset ($config->externalcoursemappingdsn)) {
$config->externalcoursemappingdsn = '';
$config->externalcoursemappingdsn = '';
}
if (!isset ($config->externalrolemappingdsn)) {
$config->externalrolemappingdsn = '';
$config->externalrolemappingdsn = '';
}
if (!isset ($config->externalcoursemappingsql)) {
$config->externalcoursemappingsql = '';
$config->externalcoursemappingsql = '';
}
if (!isset ($config->externalrolemappingsql)) {
$config->externalrolemappingsql = '';
$config->externalrolemappingsql = '';
}
if (!isset ($config->disablejit)) {
$config->disablejit = false;
Expand Down Expand Up @@ -498,13 +498,13 @@ function process_config($config) {
}
}
}
}
}
else {
//Updating roles
if (isset($config->update_roles_id) && empty($err['roles_mapping'])) {
foreach($config->update_roles_id as $role_id) {
$role = $config->{'role_' . $role_id};
$sql = "UPDATE ".$DB->get_prefix() ."role_mapping SET lms_role='" . $role[0] . "', saml_role='" . $role[1] . "' where saml_role='" . $role_id . "'";
$sql = "UPDATE ".$DB->get_prefix() ."role_mapping SET lms_role='" . $role[0] . "', saml_role='" . $role[1] . "' where saml_role='" . $role_id . "'";
try {
$DB->execute($sql);
}
Expand Down Expand Up @@ -533,12 +533,27 @@ function process_config($config) {
if(isset($err['role_mapping_db']) || isset($err['course_mapping_db'])) {
return false;
}

//END-COURSE MAPPINGS
}
return true;
}

/**
* Get the auth description (from core or own auth lang files)
*
* @return string The description
*/
function get_description() {
global $PAGE;
if ($PAGE->pagetype == 'admin-auth-saml') {
// Workaround require jquery and jquery-ui before auto_config.php $OUTPUT->header()
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('ui');
}
return parent::get_description();
}

/**
* Cleans and returns first of potential many values (multi-valued attributes)
*
Expand Down Expand Up @@ -589,7 +604,7 @@ function create_role_mapping_db($DB, &$err) {
$dbman->create_table($table);
echo '<span class="notifysuccess">';
print_string("auth_saml_sucess_creating_role_mapping", "auth_saml");
echo '</span><br>';
echo '</span><br>';
}
catch (Exception $e) {
$err['role_mapping_db'][] = get_string("auth_saml_error_creating_role_mapping", "auth_saml");
Expand All @@ -599,7 +614,7 @@ function create_role_mapping_db($DB, &$err) {

function get_course_mapping_xmldb() {

$table = new xmldb_table('course_mapping');
$table = new xmldb_table('course_mapping');

$table->add_field('course_mapping_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_field('saml_course_id', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null);
Expand Down Expand Up @@ -647,5 +662,5 @@ function initialize_roles($DB, &$err) {
}
}
return $sucess;
}
}
}
34 changes: 15 additions & 19 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<script src="../auth/saml/resources/moodle_saml.js" type="text/javascript"></script>


<link rel="stylesheet" type="text/css" href="../auth/saml/resources/ui.theme.css" />
<link rel="stylesheet" type="text/css" href="../auth/saml/resources/ui.core.css" />
<link rel="stylesheet" type="text/css" href="../auth/saml/resources/ui.tabs.css" />
<link rel="stylesheet" type="text/css" href="../auth/saml/resources/moodle_saml.css" />

<script type="text/javascript" src="../auth/saml/resources/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../auth/saml/resources/jquery-ui-1.7.2.custom.min.js"></script>


<?php
/**
* @author Erlend Strømsvik - Ny Media AS
Expand Down Expand Up @@ -103,17 +99,17 @@
if (!isset ($config->ignoreinactivecourses)) {
$config->ignoreinactivecourses = true;
}
if (!isset ($config->externalcoursemappingdsn)) {
$config->externalcoursemappingdsn = '';
if (!isset ($config->externalcoursemappingdsn)) {
$config->externalcoursemappingdsn = '';
}
if (!isset ($config->externalrolemappingdsn)) {
$config->externalrolemappingdsn = '';
if (!isset ($config->externalrolemappingdsn)) {
$config->externalrolemappingdsn = '';
}
if (!isset ($config->externalcoursemappingsql)) {
$config->externalcoursemappingsql = '';
if (!isset ($config->externalcoursemappingsql)) {
$config->externalcoursemappingsql = '';
}
if (!isset ($config->externalrolemappingsql)) {
$config->externalrolemappingsql = '';
if (!isset ($config->externalrolemappingsql)) {
$config->externalrolemappingsql = '';
}

if (!isset ($config->disablejit)) {
Expand Down Expand Up @@ -342,7 +338,7 @@

<div id="coursemapping">

<?php
<?php

if(isset($err['course_mapping_db']) && in_array("error_creating_course_mapping", $err['course_mapping_db'])) {
echo '<span class="error">';
Expand Down Expand Up @@ -401,29 +397,29 @@
<input name="externalcoursemappingdsn" type="text" size="55" value="<?php echo $config->externalcoursemappingdsn; ?>" />
</td>
</tr>
<tr class="required">
<tr class="required">
<td class="right" valign="top"><?php print_string("auth_saml_course_mapping_sql", "auth_saml"); ?>:</td>
<td>
<textarea name="externalcoursemappingsql" type="text" size="55" rows="3" cols="55"><?php echo $config->externalcoursemappingsql; ?></textarea>
<textarea name="externalcoursemappingsql" type="text" size="55" rows="3" cols="55"><?php echo $config->externalcoursemappingsql; ?></textarea>
</td>
</tr>
<tr valign="top">
<td colspan="2"></td>
</tr>
<tr class="required">
<tr class="required">
<td class="right"><?php print_string("auth_saml_role_mapping_dsn", "auth_saml"); ?>:</td>
<td>
<input name="externalrolemappingdsn" type="text" size="55" value="<?php echo $config->externalrolemappingdsn; ?>" />
</td>
</tr>
<tr class="required">
<tr class="required">
<td class="right" valign="top"><?php print_string("auth_saml_role_mapping_sql", "auth_saml"); ?>:</td>
<td>
<textarea name="externalrolemappingsql" type="text" size="55" rows="3" cols="55"><?php echo htmlspecialchars($config->externalrolemappingsql); ?></textarea>
</td>
</tr>
</table>
<p>DSN and SQL examples:</p>
<p>DSN and SQL examples:</p>
<?php
echo "<p>" . htmlspecialchars(get_string("auth_saml_mapping_dsn_examples", "auth_saml")) . "</p>";
echo "<p>" . htmlspecialchars(get_string("auth_saml_mapping_sql_examples", "auth_saml")) . "</p>";
Expand Down
23 changes: 22 additions & 1 deletion login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

include_once("../../config.php");


global $CFG, $PAGE, $OUTPUT;
include_once($CFG->libdir . "/authlib.php");

//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();
Expand All @@ -21,6 +23,9 @@
exit;
}

$errorcode = optional_param('errorcode', 0, PARAM_INT);


$context = CONTEXT_SYSTEM::instance();
$PAGE->set_url("$CFG->httpswwwroot/auth/saml/login.php");
$PAGE->set_context($context);
Expand Down Expand Up @@ -72,6 +77,22 @@

$frm = data_submitted();

if (empty($errormsg) && $errorcode == AUTH_LOGIN_UNAUTHORISED) {
$errormsg = get_string("unauthorisedlogin", "", $frm->username);
} else if(empty($errormsg) && $errorcode == AUTH_LOGIN_FAILED) {
$errormsg = get_string("invalidlogin");
} else if (empty($errormsg) && $errorcode == AUTH_LOGIN_LOCKOUT) {
$errormsg = get_string('sessionerroruser', 'error');
} else if (empty($errormsg) && !empty($SESSION->loginerrormsg)) {
// We had some errors before redirect, show them now.
$errormsg = $SESSION->loginerrormsg;
unset($SESSION->loginerrormsg);
}

if (!empty($errormsg) && method_exists($PAGE->requires, 'js_init_call')) {
$PAGE->requires->js_init_call('M.util.focus_login_error', null, true);
}

echo '<center>';

if (in_array('saml', $authsequence)){
Expand Down Expand Up @@ -151,7 +172,7 @@
if (!empty($CFG->auth_instructions)) {
echo format_text($CFG->auth_instructions);
} else {
print_string("loginsteps", "", "signup.php");
print_string("loginsteps", "", $CFG->httpswwwroot . "/login/signup.php");
} ?>
<div class="signupform">
<form action="<?php echo $CFG->httpswwwroot; ?>/login/signup.php" method="get" id="signup">
Expand Down