Commit bcb666c9 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add two checkboxes to Upload CSV screen:

* Force password change: if checked, users are forced to change their password on next log in. This was mandatory before, now people uploading CSV files can choose.
* E-mail users about accounts: if checked, users are sent an e-mail about their new account. This was never an option before and never happened, now it is on by default.

We send a slightly different e-mail based on whether the user needs to change their password or not. This affects the Add User script a tiny bit.
parent ce38179f
......@@ -244,8 +244,8 @@ function adduser_submit(Pieform $form, $values) {
db_commit();
email_user($user, $USER, get_string('accountcreated'),
get_string('accountcreatedtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename')),
get_string('accountcreatedhtml', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename'))
get_string('accountcreatedchangepasswordtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename')),
get_string('accountcreatedchangepasswordhtml', 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename'))
);
redirect('/admin/users/edit.php?id='.$id);
......
......@@ -120,6 +120,18 @@ $form = array(
'required' => true
)
),
'forcepasswordchange' => array(
'type' => 'checkbox',
'title' => get_string('forceuserstochangepassword', 'admin'),
'description' => get_string('forceuserstochangepassworddescription', 'admin'),
'defaultvalue' => true,
),
'emailusers' => array(
'type' => 'checkbox',
'title' => get_string('emailusersaboutnewaccount', 'admin'),
'description' => get_string('emailusersaboutnewaccountdescription', 'admin'),
'defaultvalue' => true,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('uploadcsv', 'admin')
......@@ -284,11 +296,14 @@ function uploadcsv_submit(Pieform $form, $values) {
log_info('Inserting users from the CSV file');
db_begin();
$addedusers = array();
foreach ($CSVDATA as $record) {
log_debug('adding user ' . $record[$formatkeylookup['username']]);
$user = new StdClass;
$user->authinstance = $authinstance;
$user->username = $record[$formatkeylookup['username']];
$user->firstname = $record[$formatkeylookup['firstname']];
$user->lastname = $record[$formatkeylookup['lastname']];
$user->password = $record[$formatkeylookup['password']];
$user->email = $record[$formatkeylookup['email']];
......@@ -298,7 +313,7 @@ function uploadcsv_submit(Pieform $form, $values) {
if (isset($formatkeylookup['preferredname'])) {
$user->preferredname = $record[$formatkeylookup['preferredname']];
}
$user->passwordchange = 1;
$user->passwordchange = (int)$values['forcepasswordchange'];
$id = insert_record('usr', $user, 'id', true);
$user->id = $id;
if ($institution->name != 'mahara') {
......@@ -322,8 +337,25 @@ function uploadcsv_submit(Pieform $form, $values) {
}
handle_event('createuser', $user);
if ($values['emailusers']) {
$addedusers[] = $user;
}
}
db_commit();
// Only send e-mail to users after we're sure they have been inserted
// successfully
$straccountcreatedtext = ($values['forcepasswordchange']) ? 'accountcreatedchangepasswordtext' : 'accountcreatedtext';
$straccountcreatedhtml = ($values['forcepasswordchange']) ? 'accountcreatedchangepasswordhtml' : 'accountcreatedhtml';
if ($values['emailusers'] && $addedusers) {
foreach ($addedusers as $user) {
email_user($user, null, get_string('accountcreated'),
get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename')),
get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('sitename'))
);
}
}
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
......
......@@ -196,6 +196,10 @@ $string['wwwrootdescription'] = 'This is the URL at which your users access this
// Upload CSV
$string['csvfile'] = 'CSV File';
$string['emailusersaboutnewaccount'] = 'E-mail users about their account?';
$string['emailusersaboutnewaccountdescription'] = 'Whether an e-mail should be sent to users informing them of their new account details';
$string['forceuserstochangepassword'] = 'Force password change?';
$string['forceuserstochangepassworddescription'] = 'Whether users should be forced to change their password when they log in for the first time';
$string['uploadcsvinstitution'] = 'The institution and authentication method for the new users';
$string['uploadcsvconfigureauthplugin'] = 'You must configure an authentication plugin before you can add users by CSV';
$string['csvfiledescription'] = 'The file containing users to add';
......
......@@ -111,6 +111,16 @@ A new account has been created for you on %s. Your details are as follows:
Username: %s
Password: %s
Visit ' . get_config('wwwroot') . ' to get started!
Regards, %s Site Administrator';
$string['accountcreatedchangepasswordtext'] = 'Dear %s,
A new account has been created for you on %s. Your details are as follows:
Username: %s
Password: %s
Once you log in for the first time, you will be asked to change your password.
Visit ' . get_config('wwwroot') . ' to get started!
......@@ -125,6 +135,19 @@ $string['accountcreatedhtml'] = '<p>Dear %s</p>
<li><strong>Password:</strong> %s</li>
</ul>
<p>Visit <a href="' . get_config('wwwroot') . '">' . get_config('wwwroot') . '</a> to get started!</p>
<p>Regards, %s Site Administrator</p>
';
$string['accountcreatedchangepasswordhtml'] = '<p>Dear %s</p>
<p>A new account has been created for you on <a href="' . get_config('wwwroot') . '">%s</a>. Your details are as follows:</p>
<ul>
<li><strong>Username:</strong> %s</li>
<li><strong>Password:</strong> %s</li>
</ul>
<p>Once you log in for the first time, you will be asked to change your password.</p>
<p>Visit <a href="' . get_config('wwwroot') . '">' . get_config('wwwroot') . '</a> to get started!</p>
......
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