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

Enforce LOCKED and !CONFIRMED flags on clients

parent b8c3e5e7
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,9 @@ elseif ($thisclient) { ...@@ -37,9 +37,9 @@ elseif ($thisclient) {
// Existing client (with an account) updating profile // Existing client (with an account) updating profile
else { else {
$user = User::lookup($thisclient->getId()); $user = User::lookup($thisclient->getId());
$content = Page::lookup(Page::lookupByType('registration-thanks')); $content = Page::lookup(Page::getIdByType('registration-thanks'));
$inc = isset($_GET['confirmed']) $inc = isset($_GET['confirmed'])
? 'registration.confirmed.inc.php' : 'profile.inc.php'; ? 'register.confirmed.inc.php' : 'profile.inc.php';
} }
} }
...@@ -81,7 +81,7 @@ elseif ($_POST) { ...@@ -81,7 +81,7 @@ elseif ($_POST) {
if (!$errors) { if (!$errors) {
switch ($_POST['do']) { switch ($_POST['do']) {
case 'create': case 'create':
$content = Page::lookup(Page::lookupByType('registration-confirm')); $content = Page::lookup(Page::getIdByType('registration-confirm'));
$inc = 'register.confirm.inc.php'; $inc = 'register.confirm.inc.php';
$acct->sendResetEmail('registration-client'); $acct->sendResetEmail('registration-client');
} }
......
...@@ -128,17 +128,23 @@ abstract class AuthenticationBackend { ...@@ -128,17 +128,23 @@ abstract class AuthenticationBackend {
// All backends are queried here, even if they don't support // All backends are queried here, even if they don't support
// authentication so that extensions like lockouts and audits // authentication so that extensions like lockouts and audits
// can be supported. // can be supported.
$result = $bk->authenticate($username, $password); try {
if ($result instanceof AuthenticatedUser $result = $bk->authenticate($username, $password);
&& ($bk->login($result, $bk))) if ($result instanceof AuthenticatedUser
return $result; && ($bk->login($result, $bk)))
elseif ($result instanceof AccessDenied) { return $result;
elseif ($result instanceof AccessDenied) {
break;
}
}
catch (AccessDenied $e) {
$result = $e;
break; break;
} }
} }
if (!$result) if (!$result)
$result = new AccessDenied('Access denied'); $result = new AccessDenied('Access denied');
if ($result && $result instanceof AccessDenied) if ($result && $result instanceof AccessDenied)
$errors['err'] = $result->reason; $errors['err'] = $result->reason;
...@@ -413,6 +419,15 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend { ...@@ -413,6 +419,15 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend {
|| !($authkey = $bk->getAuthKey($user))) || !($authkey = $bk->getAuthKey($user)))
return false; return false;
$acct = $user->getAccount();
if ($acct) {
if (!$acct->isConfirmed())
throw new AccessDenied('Account confirmation required');
elseif ($acct->isLocked())
throw new AccessDenied('Account is administratively locked');
}
//Tag the authkey. //Tag the authkey.
$authkey = $bk::$id.':'.$authkey; $authkey = $bk::$id.':'.$authkey;
...@@ -482,9 +497,10 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend { ...@@ -482,9 +497,10 @@ abstract class UserAuthenticationBackend extends AuthenticationBackend {
/** /**
* This will be an exception in later versions of PHP * This will be an exception in later versions of PHP
*/ */
class AccessDenied { class AccessDenied extends Exception {
function __construct($reason) { function __construct($reason) {
$this->reason = $reason; $this->reason = $reason;
parent::__construct($reason);
} }
} }
......
...@@ -59,6 +59,7 @@ abstract class TicketUser { ...@@ -59,6 +59,7 @@ abstract class TicketUser {
$vars = array( $vars = array(
'url' => $ost->getConfig()->getBaseUrl(), 'url' => $ost->getConfig()->getBaseUrl(),
'ticket' => $this->getTicket(), 'ticket' => $this->getTicket(),
'user' => $this,
'recipient' => $this); 'recipient' => $this);
$msg = $ost->replaceTemplateVariables(array( $msg = $ost->replaceTemplateVariables(array(
...@@ -348,6 +349,7 @@ class ClientAccount extends ClientAccountModel { ...@@ -348,6 +349,7 @@ class ClientAccount extends ClientAccountModel {
$vars = array( $vars = array(
'url' => $ost->getConfig()->getBaseUrl(), 'url' => $ost->getConfig()->getBaseUrl(),
'token' => $token, 'token' => $token,
'user' => $this->getUser(),
'recipient' => $this->getUser(), 'recipient' => $this->getUser(),
'link' => sprintf( 'link' => sprintf(
"%s/pwreset.php?token=%s", "%s/pwreset.php?token=%s",
......
...@@ -12,13 +12,13 @@ notes: > ...@@ -12,13 +12,13 @@ notes: >
verification. Please use %{link} somewhere in the body. verification. Please use %{link} somewhere in the body.
name: "Welcome to %{company.name}" name: "Welcome to %{company.name}"
body: > body: >
<h3><strong>Hi %{user.name.first},</strong></h3> We've created an <h3><strong>Hi %{recipient.name.first},</strong></h3> We've created an
account for you at our help desk at %{url}.<br /> account for you at our help desk at %{url}.<br />
<br /> <br />
Please follow the link below to confirm your account and gain access to Please follow the link below to confirm your account and gain access to
your tickets.<br /> your tickets.<br />
<br /> <br />
<a href="%{reset_link}">%{confirmation_link}</a><br /> <a href="%{link}">%{link}</a><br />
<br /> <br />
<em style="font-size: small">Your friendly Customer Support System<br <em style="font-size: small">Your friendly Customer Support System<br
/>%{company.name}</em> />%{company.name}</em>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment