Commit 20f82907 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Enforce max user account limit on registration

parent e03d40b4
......@@ -179,6 +179,7 @@ $string['registerstep3fieldsoptional'] = '<h3>Choose an Optional Profile Image</
$string['registerstep3fieldsmandatory'] = '<h3>Fill Out Mandatory Profile Fields</h3><p>The following fields are required. You must fill them out before your registration is complete.</p>';
$string['registeringdisallowed'] = 'Sorry, you cannot register for this system at this time';
$string['membershipexpiry'] = 'Membership expires';
$string['institutionfull'] = 'The institution you have chosen is not accepting any more registrations.';
// Forgot password
$string['cantchangepassword'] = 'Sorry, you are unable to change your password through this interface - please use your institution\'s interface instead';
......
......@@ -432,6 +432,22 @@ function register_validate(Pieform $form, $values) {
if (!isset($_POST['captcha']) || strtolower($_POST['captcha']) != strtolower($SESSION->get('captcha'))) {
$form->set_error('captcha', get_string('captchaincorrect'));
}
$membercount = get_record_sql('
SELECT
i.name, i.maxuseraccounts, COUNT(u.id)
FROM {institution} i
LEFT OUTER JOIN {usr_institution} ui ON ui.institution = i.name
LEFT OUTER JOIN {usr} u ON (ui.usr = u.id AND u.deleted = 0)
WHERE
i.name = ?
GROUP BY
i.name, i.maxuseraccounts', array($institution));
if (!empty($membercount->maxuseraccounts) && $membercount->count >= $membercount->maxuseraccounts) {
$form->set_error('institution', get_string('institutionfull'));
}
}
function register_submit(Pieform $form, $values) {
......
Markdown is supported
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