Skip to content
Snippets Groups Projects
Commit 7d7d822f authored by Jared Hancock's avatar Jared Hancock
Browse files

Implement staff registration / welcome email

parent 7a1e2129
Branches
Tags
No related merge requests found
...@@ -721,8 +721,11 @@ class Staff extends AuthenticatedUser { ...@@ -721,8 +721,11 @@ class Staff extends AuthenticatedUser {
} }
function create($vars, &$errors) { function create($vars, &$errors) {
if(($id=self::save(0, $vars, $errors)) && $vars['teams'] && ($staff=Staff::lookup($id))) { if(($id=self::save(0, $vars, $errors)) && ($staff=Staff::lookup($id))) {
$staff->updateTeams($vars['teams']); if ($vars['teams'])
$staff->updateTeams($vars['teams']);
if ($vars['welcome_email'])
$staff->sendResetEmail('registration-staff');
Signal::send('model.created', $staff); Signal::send('model.created', $staff);
} }
...@@ -738,27 +741,28 @@ class Staff extends AuthenticatedUser { ...@@ -738,27 +741,28 @@ class Staff extends AuthenticatedUser {
unset($_SESSION['_staff']['reset-token']); unset($_SESSION['_staff']['reset-token']);
} }
function sendResetEmail() { function sendResetEmail($template='pwreset-staff') {
global $ost, $cfg; global $ost, $cfg;
if(!($tpl = $this->getDept()->getTemplate())) $content = Page::lookup(Page::getIdByType($template));
$tpl= $ost->getConfig()->getDefaultTemplate();
$token = Misc::randCode(48); // 290-bits $token = Misc::randCode(48); // 290-bits
if (!($template = $tpl->getMsgTemplate('staff.pwreset')))
if (!$content)
return new Error('Unable to retrieve password reset email template'); return new Error('Unable to retrieve password reset email template');
$vars = array( $vars = array(
'url' => $ost->getConfig()->getBaseUrl(), 'url' => $ost->getConfig()->getBaseUrl(),
'token' => $token, 'token' => $token,
'staff' => $this, 'staff' => $this,
'recipient' => $this,
'reset_link' => sprintf( 'reset_link' => sprintf(
"%s/scp/pwreset.php?token=%s", "%s/scp/pwreset.php?token=%s",
$ost->getConfig()->getBaseUrl(), $ost->getConfig()->getBaseUrl(),
$token), $token),
); );
$vars['link'] = &$vars['reset_link'];
if(!($email=$cfg->getAlertEmail())) if (!($email = $cfg->getAlertEmail()))
$email = $cfg->getDefaultEmail(); $email = $cfg->getDefaultEmail();
$info = array('email' => $email, 'vars' => &$vars, 'log'=>true); $info = array('email' => $email, 'vars' => &$vars, 'log'=>true);
...@@ -778,12 +782,16 @@ class Staff extends AuthenticatedUser { ...@@ -778,12 +782,16 @@ class Staff extends AuthenticatedUser {
$email->getEmail() $email->getEmail()
), false); ), false);
$msg = $ost->replaceTemplateVariables($template->asArray(), $vars); $msg = $ost->replaceTemplateVariables(array(
'subj' => $content->getName(),
'body' => $content->getBody(),
), $vars);
$_config = new Config('pwreset'); $_config = new Config('pwreset');
$_config->set($vars['token'], $this->getId()); $_config->set($vars['token'], $this->getId());
$email->send($this->getEmail(), $msg['subj'], $msg['body']); $email->send($this->getEmail(), Format::stripTags($msg['subj']),
$msg['body']);
} }
function save($id, $vars, &$errors) { function save($id, $vars, &$errors) {
...@@ -823,7 +831,7 @@ class Staff extends AuthenticatedUser { ...@@ -823,7 +831,7 @@ class Staff extends AuthenticatedUser {
if($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2'])) { if($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2'])) {
$errors['passwd2']='Password(s) do not match'; $errors['passwd2']='Password(s) do not match';
} }
elseif ($vars['backend'] != 'local') { elseif ($vars['backend'] != 'local' || $vars['welcome_email']) {
// Password can be omitted // Password can be omitted
} }
elseif(!$vars['passwd1'] && !$id) { elseif(!$vars['passwd1'] && !$id) {
......
...@@ -20,6 +20,7 @@ if($staff && $_REQUEST['a']!='add'){ ...@@ -20,6 +20,7 @@ if($staff && $_REQUEST['a']!='add'){
$passwd_text='Temporary password required only for "Local" authenication'; $passwd_text='Temporary password required only for "Local" authenication';
//Some defaults for new staff. //Some defaults for new staff.
$info['change_passwd']=1; $info['change_passwd']=1;
$info['welcome_email']=1;
$info['isactive']=1; $info['isactive']=1;
$info['isvisible']=1; $info['isvisible']=1;
$info['isadmin']=0; $info['isadmin']=0;
...@@ -106,6 +107,22 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -106,6 +107,22 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
&nbsp;<span class="error">&nbsp;<?php echo $errors['mobile']; ?></span> &nbsp;<span class="error">&nbsp;<?php echo $errors['mobile']; ?></span>
</td> </td>
</tr> </tr>
<?php if (!$staff) { ?>
<tr>
<td width="180">Welcome Email</td>
<td><input type="checkbox" name="welcome_email" id="welcome-email" <?php
if ($info['welcome_email']) echo 'checked="checked"';
?> onchange="javascript:
var sbk = $('#backend-selection');
if ($(this).is(':checked'))
$('#password-fields').hide();
else if (sbk.val() == '' || sbk.val() == 'local')
$('#password-fields').show();
" />
Send staff welcome email with account access link
</td>
</tr>
<?php } ?>
<tr> <tr>
<th colspan="2"> <th colspan="2">
<em><strong>Authentication</strong>: <?php echo $passwd_text; ?> &nbsp;<span class="error">&nbsp;<?php echo $errors['temppasswd']; ?></span></em> <em><strong>Authentication</strong>: <?php echo $passwd_text; ?> &nbsp;<span class="error">&nbsp;<?php echo $errors['temppasswd']; ?></span></em>
...@@ -114,10 +131,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -114,10 +131,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<tr> <tr>
<td>Authentication Backend</td> <td>Authentication Backend</td>
<td> <td>
<select name="backend" onchange="javascript: <select name="backend" id="backend-selection" onchange="javascript:
if (this.value != '' && this.value != 'local') if (this.value != '' && this.value != 'local')
$('#password-fields').hide(); $('#password-fields').hide();
else else if (!$('#welcome-email').is(':checked'))
$('#password-fields').show(); $('#password-fields').show();
"> ">
<option value="">&mdash; Use any available backend &mdash;</option> <option value="">&mdash; Use any available backend &mdash;</option>
...@@ -131,8 +148,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -131,8 +148,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</select> </select>
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tbody id="password-fields" style="<?php if ($info['backend'] && $info['backend'] != 'local') <tbody id="password-fields" style="<?php
if ($info['welcome_email'] || ($info['backend'] && $info['backend'] != 'local'))
echo 'display:none;'; ?>"> echo 'display:none;'; ?>">
<tr> <tr>
<td width="180"> <td width="180">
......
...@@ -62,10 +62,11 @@ if($_POST) { ...@@ -62,10 +62,11 @@ if($_POST) {
} }
} }
elseif ($_GET['token']) { elseif ($_GET['token']) {
$msg = 'Re-enter your username or email'; $msg = 'Please enter your username or email';
$_config = new Config('pwreset'); $_config = new Config('pwreset');
if (($id = $_config->get($_GET['token'])) if (($id = $_config->get($_GET['token']))
&& ($staff = Staff::lookup($id))) && ($staff = Staff::lookup($id)))
// TODO: Detect staff confirmation (for welcome email)
$tpl = 'pwreset.login.php'; $tpl = 'pwreset.login.php';
else else
header('Location: index.php'); header('Location: index.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment