Commit 103103a7 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents b943b1f2 9f389db3
......@@ -154,7 +154,7 @@ function accountprefs_validate(Pieform $form, $values) {
$form->set_error('oldpassword', get_string('oldpasswordincorrect', 'account'));
return;
}
password_validate($form, $values, $USER);
password_validate($form, $values, $USER->get('username'), $USER->get('institution'));
}
else if ($values['password1'] !== '' || $values['password2'] !== '') {
$form->set_error('oldpassword', get_string('mustspecifyoldpassword'));
......
......@@ -33,12 +33,58 @@ $smarty = smarty();
$institution = param_variable('i', '');
$add = param_boolean('add');
$edit = param_boolean('edit');
$delete = param_boolean('delete');
if ($institution || $add) {
if ($delete) {
function delete_validate(Pieform $form, $values) {
if (get_field('usr', 'COUNT(*)', 'institution', $values['i'])) {
throw new Exception('Attempt to delete an institution that has members');
}
}
function delete_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
function delete_submit($values) {
global $SESSION;
db_begin();
delete_records('institution_locked_profile_field', 'name', $values['i']);
delete_records('institution', 'name', $values['i']);
db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
$form = array(
'name' => 'delete',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution
),
'delete' => array(
'type' => 'hidden',
'value' => 1
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no'))
)
)
);
$smarty->assign('delete_form', pieform($form));
$smarty->display('admin/institutions.tpl');
exit;
}
if (!$add) {
$data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array)get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
}
else {
$data = new StdClass;
......@@ -52,76 +98,74 @@ if ($institution || $add) {
}
safe_require('artefact', 'internal');
$elements = array();
if ($add) {
$elements['name'] = array(
$elements = array(
'name' => array(
'type' => 'text',
'title' => get_string('institutionname'),
'title' => get_string('institutionname', 'admin'),
'rules' => array(
'required' => true,
'maxlength' => 255,
'regex' => '/^[a-z]+$/'
),
'ignore' => !$add
),
'add' => array(
'type' => 'hidden',
'value' => true,
'ignore' => !$add
),
'i' => array(
'type' => 'hidden',
'value' => $institution,
'ignore' => $add
),
'displayname' => array(
'type' => 'text',
'title' => get_string('institutiondisplayname', 'admin'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
'maxlength' => 255
)
);
$elements['add'] = array(
'type' => 'hidden',
'value' => true
);
}
else {
$elements['i'] = array(
'type' => 'hidden',
'value' => $institution
);
}
$elements['displayname'] = array(
'type' => 'text',
'title' => get_string('institutiondisplayname'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
'maxlength' => 255
),
'authplugin' => array(
'type' => 'select',
'title' => get_string('authplugin', 'admin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
),
'registerallowed' => array(
'type' => 'checkbox',
'title' => get_string('registrationallowed', 'admin'),
'description' => get_string('registrationalloweddescription', 'admin'),
'checked' => $data->registerallowed
),
'defaultaccountlifetime' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountlifetime', 'admin'),
'description' => get_string('defaultaccountlifetimedescription', 'admin'),
'defaultvalue' => $data->defaultaccountlifetime
),
'defaultaccountinactiveexpire' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire', 'admin'),
'description' => get_string('defaultaccountinactiveexpiredescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactiveexpire
),
'defaultaccountinactivewarn' => array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn', 'admin'),
'description' => get_string('defaultaccountinactivewarndescription', 'admin'),
'defaultvalue' => $data->defaultaccountinactivewarn
),
'lockedfields' => array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
)
);
$elements['authplugin'] = array(
'type' => 'select',
'title' => get_string('authplugin'),
'options' => get_records_menu('auth_installed', '', '', 'name', 'name, name')
);
$elements['registerallowed'] = array(
'type' => 'checkbox',
'title' => get_string('registrationallowed'),
'description' => get_string('registrationalloweddescription'),
'checked' => $data->registerallowed
);
$elements['defaultaccountlifetime'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountlifetime'),
'description' => get_string('defaultaccountlifetimedescription'),
'defaultvalue' => $data->defaultaccountlifetime
);
$elements['defaultaccountinactiveexpire'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactiveexpire'),
'description' => get_string('defaultaccountinactiveexpiredescription'),
'defaultvalue' => $data->defaultaccountinactiveexpire
);
$elements['defaultaccountinactivewarn'] = array(
'type' => 'expiry',
'title' => get_string('defaultaccountinactivewarn'),
'description' => get_string('defaultaccountinactivewarndescription'),
'defaultvalue' => $data->defaultaccountinactivewarn
);
$elements['lockedfields'] = array(
'value' => '<tr><th colspan="2">Locked fields</th></tr>'
);
foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) {
$elements[$field] = array(
'type' => 'checkbox',
'title' => get_string($field),
'title' => get_string($field, 'artefact.internal'),
'checked' => in_array($field, $lockedprofilefields)
);
}
......@@ -138,7 +182,7 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*)
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*) AS hasmembers
FROM institution i
LEFT OUTER JOIN usr u ON (u.institution = i.name)
GROUP BY 1, 2, 3, 4
......@@ -185,7 +229,8 @@ function institution_submit($values) {
}
db_commit();
$SESSION->add_ok_msg(get_string('institutionupdatedsuccessfully'));
$message = ($add) ? 'institutionaddedsuccessfully' : 'institutionupdatedsuccessfully';
$SESSION->add_ok_msg(get_string($message, 'admin'));
redirect(get_config('wwwroot') . 'admin/institutions.php');
}
......
......@@ -313,7 +313,7 @@ function change_password_validate(Pieform $form, $values) {
safe_require('auth', $authtype);
// @todo this could be done by a custom form rule... 'password' => $user
password_validate($form, $values, $USER);
password_validate($form, $values, $USER->get('username'), $USER->get('institution'));
// The password cannot be the same as the old one
if (!$form->get_error('password1')
......
......@@ -154,7 +154,7 @@ function forgotpasschange_validate(Pieform $form, $values) {
if (!$user = get_record('usr', 'id', $values['user'])) {
throw new Exception('Request to change the password for a user who does not exist');
}
password_validate($form, $values, $user);
password_validate($form, $values, $user->username, $user->institution);
}
......@@ -163,7 +163,7 @@ function forgotpasschange_validate(Pieform $form, $values) {
// support autofocus => (true|'id'), remove stuff doing autofocus from where it is, focus error fields
// commit stuff
function forgotpasschange_submit($values) {
global $SESSION;
global $SESSION, $USER;
if (!$user = get_record('usr', 'id', $values['user'])) {
throw new Exception('Request to change the password for a user who does not exist');
......@@ -186,7 +186,7 @@ function forgotpasschange_submit($values) {
// Remove the password request(s) for the user
delete_records('usr_password_request', 'usr', $values['user']);
$SESSION->login($user);
$USER->login($user);
$SESSION->add_ok_msg(get_string('passwordchangedok'));
redirect(get_config('wwwroot'));
exit;
......
......@@ -26,13 +26,6 @@
defined('INTERNAL') || die();
$string['adminoptionsauthenticationtitle'] = 'AdminOptionsAuthentication';
$string['adminoptionsauthenticationdescription'] = '<p>List of installed authentication methods. Internal is used by default, if an
institution uses another authentication type then they will be listed beside it.</p>
<p>Did you want to <a href="institution.php">change the type of authentication for an institution</a>?</p>';
$string['authnoconfigurationoptions'] = 'No configuration options are available for this authentication type';
// Installer
$string['release'] = 'Release %s (%s)';
$string['component'] = 'Component or plugin';
......@@ -56,6 +49,7 @@ $string['siteoptions'] = 'Site options';
$string['institutions'] = 'Institutions';
$string['pageeditor'] = 'Site pages';
$string['menueditor'] = 'Site menu';
$string['adminplugins'] = 'Administer Plugins';
$string['files'] = 'Files';
$string['adminhome'] = 'Admin home';
......@@ -153,7 +147,23 @@ $string['adminnotifications'] = 'Admin Notifications';
// Suspended Users
$string['suspendedusers'] = 'Suspended Users';
// Authentication
$string['authconfigoptionssaved'] = 'Auth configuration has been saved';
// Institutions
$string['addinstitution'] = 'Add Institution';
$string['authplugin'] = 'Authentication plugin';
$string['defaultaccountinactiveexpire'] = 'Default account expiry time';
$string['defaultaccountinactiveexpiredescription'] = 'How long a user account will remain active without the user logging in';
$string['defaultaccountinactivewarn'] = 'Default account expire warning time';
$string['defaultaccountinactivewarndescription'] = 'The time before user accounts are to expire at which a warning message will be sent to them';
$string['defaultaccountlifetime'] = 'Default account lifetime';
$string['defaultaccountlifetimedescription'] = 'How long accounts will last for by default';
$string['deleteinstitution'] = 'Delete Institution';
$string['deleteinstitutionconfirm'] = 'Are you really sure you wish to delete this institution?';
$string['institutionaddedsuccessfully'] = 'Institution added successfully';
$string['institutiondeletedsuccessfully'] = 'Institution deleted successfully';
$string['institutionname'] = 'Institution name';
$string['institutiondisplayname'] = 'Institution display name';
$string['institutionupdatedsuccessfully'] = 'Institution updated successfully';
$string['registrationallowed'] = 'Registration allowed?';
$string['registrationalloweddescription'] = 'Whether users can register for the system with this institution';
?>
......@@ -568,15 +568,17 @@ function check_dir_exists($dir, $create=true, $recursive=true) {
*
* @todo need such a function for password too.
*/
function validate_username($username) {
return preg_match('/^[a-zA-Z0-9_\.@]+$/', $username);
}
//function validate_username($username) {
// return preg_match('/^[a-zA-Z0-9_\.@]+$/', $username);
//}
/**
* Function to require a plugin file. This is to avoid doing
* require and include directly with variables.
*
* This function is the one safe point to require plugin files.
* so USE it :)
*
* @param string $plugintype the type of plugin (eg artefact)
* @param string $pluginname the name of the plugin (eg blog)
* @param string $filename the name of the file to include within the plugin structure
......@@ -584,17 +586,13 @@ function validate_username($username) {
* @param string $nonfatal (optional, defaults to false) just returns false if the file doesn't exist
*/
function safe_require($plugintype, $pluginname, $filename='lib.php', $function='require_once', $nonfatal=false) {
$plugintypes = plugin_types();
if (!in_array($plugintype, $plugintypes)) {
throw new Exception("\"$plugintype\" is not a valid plugin type");
}
require_once(get_config('docroot') . $plugintype . '/lib.php');
$plugintype = clean_filename($plugintype);
$pluginname = clean_filename($pluginname);
if (!in_array($function,array('require','include','require_once','include_once'))) {
if (!in_array($function,array('require', 'include', 'require_once', 'include_once'))) {
if (!empty($nonfatal)) {
return false;
}
......@@ -817,6 +815,11 @@ function admin_nav() {
'section' => 'admin',
'link' => $wwwroot . 'admin/editmenu.php',
),
array(
'name' => 'adminplugins',
'section' => 'admin',
'link' => $wwwroot . 'admin/plugins/',
),
array(
'name' => 'files',
'section' => 'admin',
......@@ -1188,8 +1191,8 @@ function get_random_key() {
* @param array $values The values passed through
* @param string $authplugin The authentication plugin that the user uses
*/
function password_validate(Pieform $form, $values, $user) {
$authtype = auth_get_authtype_for_institution($user->get('institution'));
function password_validate(Pieform $form, $values, $username, $institution) {
$authtype = auth_get_authtype_for_institution($institution);
$authclass = 'Auth' . ucfirst($authtype);
safe_require('auth', $authtype);
if (!$form->get_error('password1') && !call_static_method($authclass, 'is_password_valid', ($values['password1']))) {
......@@ -1197,7 +1200,7 @@ function password_validate(Pieform $form, $values, $user) {
}
$suckypasswords = array(
'mahara', 'password', $user->get('username')
'mahara', 'password', $username
);
if (!$form->get_error('password1') && in_array($values['password1'], $suckypasswords)) {
$form->set_error('password1', get_string('passwordtooeasy'));
......
......@@ -397,15 +397,28 @@ class Pieform {
if (!is_array($data['elements']) || count($data['elements']) == 0) {
throw new PieformException('Forms must have a list of elements');
}
// Remove elements to ignore
foreach ($data['elements'] as $name => $element) {
if (isset($element['type']) && $element['type'] == 'fieldset') {
foreach ($element['elements'] as $subname => $subelement) {
if (!empty($subelement['ignore'])) {
unset ($data['elements'][$name]['elements'][$subname]);
}
}
}
else {
if (!empty($element['ignore'])) {
unset($data['elements'][$name]);
}
}
}
$this->elements = $data['elements'];
// Set some attributes for all elements
$autofocusadded = false;
foreach ($this->elements as $name => &$element) {
if (!empty($element['ignore'])) {
unset($this->elements[$name]);
continue;
}
// The name can be in the element itself. This is compatibility for the perl version
if (isset($element['name'])) {
$name = $element['name'];
......@@ -432,10 +445,6 @@ class Pieform {
}
if ($element['type'] == 'fieldset') {
foreach ($element['elements'] as $subname => &$subelement) {
if (!empty($subelement['ignore'])) {
unset($element['elements'][$subname]);
continue;
}
// The name can be in the element itself. This is compatibility for the perl version
if (isset($subelement['name'])) {
$subname = $subelement['name'];
......
......@@ -47,7 +47,7 @@ function pieform_render_userlist($element, Pieform $form) {
}
if (is_array($value) && count($value)) {
$members = get_records_select_array('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname');
$members = get_records_select_assoc('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname');
foreach($members as &$member) {
$member = display_name($member);
......
......@@ -226,12 +226,6 @@ function theme_get_image_path($imagelocation, $pluginlocation='') {
}
}
function clean_filename($filename) {
//@todo
return $filename;
}
/**
* This function sends headers suitable for all JSON returning scripts.
*
......
......@@ -41,7 +41,7 @@ if (!session_id()) {
}
// Logged in people can't register
if ($SESSION->is_logged_in()) {
if ($USER->is_logged_in()) {
redirect(get_config('wwwroot'));
}
......@@ -63,7 +63,7 @@ if (!empty($_SESSION['registered'])) {
if (isset($_REQUEST['key'])) {
function register_profile_submit($values) {
global $registration, $SESSION;
global $registration, $SESSION, $USER;
db_begin();
// Move the user record to the usr table from the registration table
......@@ -93,7 +93,7 @@ if (isset($_REQUEST['key'])) {
db_commit();
// Log the user in and send them to the homepage
$SESSION->login($registration);
$USER->login($registration);
redirect(get_config('wwwroot'));
}
......@@ -277,7 +277,7 @@ function register_validate(Pieform $form, $values) {
$form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
}
password_validate($form, $values, (object)$values);
password_validate($form, $values, $values['username'], $values['institution']);
// First name and last name must contain at least one non whitespace
// character, so that there's something to read
......
......@@ -2,19 +2,24 @@
<h2>AdminInstitutions</h2>
{if $delete_form}
<h3>{str tag="deleteinstitution" section="admin"}</h3>
<p>{str tag="deleteinstitutionconfirm" section="admin"}</p>
{$delete_form}
{else}
{if $institution_form}
{if $add}
<h3>Add Institution</h3>
<h3>{str tag="addinstitution" section="admin"}</h3>
{/if}
{$institution_form}
{else}
<p>Here is a list of all installed institutions.</p>
<table>
<tr>
<th>Institution</th>
<th>Authentication Method</th>
<th>Registration Allowed?</th>
<th>{str tag="institution"}</th>
<th>{str tag="authplugin" section="admin"}</th>
<th>{str tag="registrationallowed" section="admin"}</th>
<th></th>
</tr>
{foreach from=$institutions item=institution}
......@@ -25,8 +30,8 @@
<td>
<form action="" method="post">
<input type="hidden" name="i" value="{$institution->name}">
<input type="submit" name="edit" value="Edit">
{if $institution->candelete}<input type="submit" name="delete" value="Delete">{/if}
<input type="submit" name="edit" value="{str tag="edit"}">
{if !$institution->hasmembers && $institution->name != 'mahara'}<input type="submit" name="delete" value="{str tag="delete"}">{/if}
</form>
</td>
</tr>
......@@ -34,11 +39,12 @@
<tr>
<td colspan="4">
<form action="" method="post">
<input type="submit" name="add" value="Add Institution">
<input type="submit" name="add" value="{str tag="addinstitution" section="admin"}">
</form>
</td>
</tr>
</table>
{/if}
{/if}
{include file="footer.tpl"}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment