Skip to content
Snippets Groups Projects
Commit 321b15b2 authored by Peter Rotich's avatar Peter Rotich
Browse files

User directory support

parent fd084d90
Branches
Tags
No related merge requests found
...@@ -137,7 +137,7 @@ class UsersAjaxAPI extends AjaxController { ...@@ -137,7 +137,7 @@ class UsersAjaxAPI extends AjaxController {
include(STAFFINC_DIR . 'templates/user-register.tmpl.php'); include(STAFFINC_DIR . 'templates/user-register.tmpl.php');
} }
function manage($id, $target) { function manage($id, $target=null) {
global $thisstaff; global $thisstaff;
if (!$thisstaff) if (!$thisstaff)
......
...@@ -235,10 +235,16 @@ class User extends UserModel { ...@@ -235,10 +235,16 @@ class User extends UserModel {
function getAccountStatus() { function getAccountStatus() {
if ($this->getAccount()) if (!($account=$this->getAccount()))
return (string) $this->getAccount()->getStatus(); return 'Guest';
if ($account->isLocked())
return 'Locked (Administrative)';
if (!$account->isConfirmed())
return 'Locked (Pending Activation)';
return 'Unregistered'; return 'Active';
} }
function register($vars, &$errors) { function register($vars, &$errors) {
...@@ -247,35 +253,7 @@ class User extends UserModel { ...@@ -247,35 +253,7 @@ class User extends UserModel {
if ($this->getAccount()) if ($this->getAccount())
return true; return true;
//Require temp password. return UserAccount::register($this, $vars, $errors);
if (!isset($vars['sendemail'])) {
if (!$vars['passwd1'])
$errors['passwd1'] = 'Temp. password required';
elseif ($vars['passwd1'] && strlen($vars['passwd1'])<6)
$errors['passwd1'] = 'Must be at least 6 characters';
elseif ($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2']))
$errors['passwd2'] = 'Password(s) do not match';
}
if ($errors) return false;
$account = UserAccount::create(array('user_id' => $this->getId()));
if (!$account)
return false;
$account->set('dst', isset($vars['dst'])?1:0);
$account->set('timezone_id', $vars['timezone_id']);
if ($vars['username'] && strcasecmp($vars['username'], $this->getEmail()))
$account->set('username', $vars['username']);
if (!$vars['sendemail'])
$account->set('passwd', Password::hash($vars['passwd1']));
//TODO: else $account->sendActivationEmail();
$account->save(true);
return $account;
} }
//TODO: Add organization support //TODO: Add organization support
...@@ -563,6 +541,7 @@ class UserAccountModel extends VerySimpleModel { ...@@ -563,6 +541,7 @@ class UserAccountModel extends VerySimpleModel {
class UserAccount extends UserAccountModel { class UserAccount extends UserAccountModel {
var $_options = null; var $_options = null;
var $_user;
const CONFIRMED = 0x0001; const CONFIRMED = 0x0001;
const LOCKED = 0x0002; const LOCKED = 0x0002;
...@@ -628,17 +607,20 @@ class UserAccount extends UserAccountModel { ...@@ -628,17 +607,20 @@ class UserAccount extends UserAccountModel {
} }
function getUser() { function getUser() {
$user = User::lookup($this->getUserId());
$user->set('account', $this); if (!isset($this->_user)) {
return $user; if ($this->_user = User::lookup($this->getUserId()))
$this->_user->set('account', $this);
}
return $this->_user;
} }
function sendResetEmail() { function sendResetEmail() {
return static::sendUnlockEmail('pwreset-client'); return static::sendUnlockEmail('pwreset-client') === true;
} }
function sendConfirmEmail() { function sendConfirmEmail() {
return static::sendUnlockEmail('registration-confirm'); return static::sendUnlockEmail('registration-client') === true;
} }
protected function sendUnlockEmail($template) { protected function sendUnlockEmail($template) {
...@@ -650,7 +632,7 @@ class UserAccount extends UserAccountModel { ...@@ -650,7 +632,7 @@ class UserAccount extends UserAccountModel {
$content = Page::lookup(Page::getIdByType($template)); $content = Page::lookup(Page::getIdByType($template));
if (!$email || !$content) if (!$email || !$content)
return new Error('Unable to retrieve password reset email template'); return new Error($template.': Unable to retrieve template');
$vars = array( $vars = array(
'url' => $ost->getConfig()->getBaseUrl(), 'url' => $ost->getConfig()->getBaseUrl(),
...@@ -673,10 +655,12 @@ class UserAccount extends UserAccountModel { ...@@ -673,10 +655,12 @@ class UserAccount extends UserAccountModel {
), $vars); ), $vars);
$_config = new Config('pwreset'); $_config = new Config('pwreset');
$_config->set($vars['token'], $this->user->getId()); $_config->set($vars['token'], $this->getUser()->getId());
$email->send($this->user->default_email->get('address'), $email->send($this->getUser()->getEmail(),
Format::striptags($msg['subj']), $msg['body']); Format::striptags($msg['subj']), $msg['body']);
return true;
} }
...@@ -704,7 +688,7 @@ class UserAccount extends UserAccountModel { ...@@ -704,7 +688,7 @@ class UserAccount extends UserAccountModel {
// Changing password? // Changing password?
if ($vars['passwd1'] || $vars['passwd2']) { if ($vars['passwd1'] || $vars['passwd2']) {
if (!$vars['passwd1']) if (!$vars['passwd1'])
$errors['passwd1'] = 'New password required'; $errors['passwd1'] = 'Password required';
elseif ($vars['passwd1'] && strlen($vars['passwd1'])<6) elseif ($vars['passwd1'] && strlen($vars['passwd1'])<6)
$errors['passwd1'] = 'Must be at least 6 characters'; $errors['passwd1'] = 'Must be at least 6 characters';
elseif ($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2'])) elseif ($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2']))
...@@ -727,6 +711,17 @@ class UserAccount extends UserAccountModel { ...@@ -727,6 +711,17 @@ class UserAccount extends UserAccountModel {
$this->setStatus(self::CONFIRMED); $this->setStatus(self::CONFIRMED);
} }
// Set flags
if ($vars['pwreset-flag'])
$this->setStatus(self::PASSWD_RESET_REQUIRED);
else
$this->clearStatus(self::PASSWD_RESET_REQUIRED);
if ($vars['locked-flag'])
$this->setStatus(self::LOCKED);
else
$this->clearStatus(self::LOCKED);
return $this->save(true); return $this->save(true);
} }
...@@ -742,6 +737,47 @@ class UserAccount extends UserAccountModel { ...@@ -742,6 +737,47 @@ class UserAccount extends UserAccountModel {
return $user; return $user;
} }
static function register($user, $vars, &$errors) {
if (!$user || !$vars)
return false;
//Require temp password.
if (!isset($vars['sendemail'])) {
if (!$vars['passwd1'])
$errors['passwd1'] = 'Temp. password required';
elseif ($vars['passwd1'] && strlen($vars['passwd1'])<6)
$errors['passwd1'] = 'Must be at least 6 characters';
elseif ($vars['passwd1'] && strcmp($vars['passwd1'], $vars['passwd2']))
$errors['passwd2'] = 'Password(s) do not match';
}
if ($errors) return false;
$account = UserAccount::create(array('user_id' => $user->getId()));
if (!$account)
return false;
$account->set('dst', isset($vars['dst'])?1:0);
$account->set('timezone_id', $vars['timezone_id']);
if ($vars['username'] && strcasecmp($vars['username'], $user->getEmail()))
$account->set('username', $vars['username']);
if ($vars['passwd1'] && !$vars['sendemail']) {
$account->set('passwd', Password::hash($vars['passwd1']));
$account->setStatus(self::CONFIRMED);
}
$account->save(true);
if ($vars['sendemail'])
$account->sendConfirmEmail();
return $account;
}
} }
......
...@@ -95,6 +95,10 @@ if ($info['error']) { ...@@ -95,6 +95,10 @@ if ($info['error']) {
<tr> <tr>
<th colspan="2"><em><strong>Account Access</strong></em></th> <th colspan="2"><em><strong>Account Access</strong></em></th>
</tr> </tr>
<tr>
<td width="180"> Status: </td>
<td> <?php echo $user->getAccountStatus(); ?> </td>
</tr>
<tr> <tr>
<td width="180"> <td width="180">
Username: Username:
...@@ -130,8 +134,15 @@ if ($info['error']) { ...@@ -130,8 +134,15 @@ if ($info['error']) {
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<div><input type="checkbox" name="flags[]" value="locked"> Locked (reason here) </div> <?php
<div><input type="checkbox" name="flags[]" value="locked"> Require Password Reset</div> echo sprintf('<div><input type="checkbox" name="locked-flag" %s
value="1"> Administratively Locked</div>',
$account->isLocked() ? 'checked="checked"' : ''
);
?>
<div><input type="checkbox" name="pwreset-flag" value="1" <?php
echo $account->isPasswdResetForced() ?
'checked="checked"' : ''; ?>> Password Reset Required</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
......
<?php <?php
global $cfg;
if (!$info['title']) if (!$info['title'])
$info['title'] = 'Register: '.Format::htmlchars($user->getName()); $info['title'] = 'Register: '.Format::htmlchars($user->getName());
// TODO: Set defaults
if (!$_POST) { if (!$_POST) {
$info['sendemail'] = true; // send email confirmation. $info['sendemail'] = true; // send email confirmation.
if (!isset($info['timezone_id']))
$info['timezone_id'] = $cfg->getDefaultTimezoneId();
if (!isset($info['dst']))
$info['dst'] = $cfg->observeDaylightSaving();
} }
?> ?>
...@@ -83,11 +91,12 @@ $user->getName()->getOriginal(); ?></b>.</p></div> ...@@ -83,11 +91,12 @@ $user->getName()->getOriginal(); ?></b>.</p></div>
<td> <td>
<select name="timezone_id" id="timezone_id"> <select name="timezone_id" id="timezone_id">
<?php <?php
$sql='SELECT id, offset,timezone FROM '.TIMEZONE_TABLE.' ORDER BY id'; $sql='SELECT id, offset, timezone FROM '.TIMEZONE_TABLE.' ORDER BY id';
if(($res=db_query($sql)) && db_num_rows($res)){ if(($res=db_query($sql)) && db_num_rows($res)){
while(list($id,$offset, $tz)=db_fetch_row($res)){ while(list($id, $offset, $tz) = db_fetch_row($res)) {
$sel=($info['timezone_id']==$id)?'selected="selected"':''; $sel=($info['timezone_id']==$id) ? 'selected="selected"' : '';
echo sprintf('<option value="%d" %s>GMT %s - %s</option>',$id,$sel,$offset,$tz); echo sprintf('<option value="%d" %s>GMT %s - %s</option>',
$id, $sel, $offset, $tz);
} }
} }
?> ?>
......
...@@ -31,13 +31,24 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path' ...@@ -31,13 +31,24 @@ if(!defined('OSTSCPINC') || !$thisstaff || !is_object($user)) die('Invalid path'
} ?> } ?>
<div id="action-dropdown-more" class="action-dropdown anchor-right"> <div id="action-dropdown-more" class="action-dropdown anchor-right">
<ul> <ul>
<li><a class="confirm-action" href="#confirmlink"><i <?php
class="icon-lock"></i> Send Confirmation Link</a></li> if ($user->getAccount()) {
<li><a class="confirm-action" href="#pwreset"><i if (!$user->getAccount()->isConfirmed()) {
class="icon-lock"></i> Send Password Reset Link</a></li> ?>
<li><a class="user-action" <li><a class="confirm-action" href="#confirmlink"><i
href="#users/<?php echo $user->getId(); ?>/manage/access"><i class="icon-envelope"></i> Send Activation Email</a></li>
class="icon-lock"></i> Manage Account Access</a></li> <?php
} else { ?>
<li><a class="confirm-action" href="#pwreset"><i
class="icon-envelope"></i> Send Password Reset Email</a></li>
<?php
} ?>
<li><a class="user-action"
href="#users/<?php echo $user->getId(); ?>/manage/access"><i
class="icon-lock"></i> Manage Account Access</a></li>
<?php
} ?>
</ul> </ul>
</div> </div>
</td> </td>
......
...@@ -42,10 +42,22 @@ if ($_POST) { ...@@ -42,10 +42,22 @@ if ($_POST) {
} }
break; break;
case 'confirmlink': case 'confirmlink':
$errors['err'] = "Send Confirmation Link: Coming soon!"; if (!$user || !$user->getAccount())
$errors['err'] = 'Unknown or invalid user account';
elseif ($user->getAccount()->isConfirmed())
$errors['err'] = 'Account is already confirmed';
elseif ($user->getAccount()->sendConfirmEmail())
$msg = 'Account activation email sent to '.$user->getEmail();
else
$errors['err'] = 'Unable to send account activation email - try again!';
break; break;
case 'pwreset': case 'pwreset':
$errors['err'] = "Send Password Reset Link: Coming soon!"; if (!$user || !$user->getAccount())
$errors['err'] = 'Unknown or invalid user account';
elseif ($user->getAccount()->sendResetEmail())
$msg = 'Account password reset email sent to '.$user->getEmail();
else
$errors['err'] = 'Unable to send account password reset email - try again!';
break; break;
case 'mass_process': case 'mass_process':
if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment