Skip to content

Commit

Permalink
Audit Plugin: Reduce Lookups
Browse files Browse the repository at this point in the history
Reduce the number of calls we make to the database for users or agents loggin in or out of the helpdesk.
  • Loading branch information
aydreeihn committed Oct 10, 2019
1 parent 203c716 commit 54a175a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
18 changes: 6 additions & 12 deletions include/class.auth.php
Expand Up @@ -683,7 +683,7 @@ function login($user, $bk) {
$user->getUserName(), $user->getId(), $_SERVER['REMOTE_ADDR']);
$ost->logDebug(_S('User login'), $msg);

$u = User::lookup($user->getId());
$u = $user->getSessionUser()->getUser();
$type = array('type' => 'login');
Signal::send('person.login', $u, $type);

Expand Down Expand Up @@ -723,7 +723,7 @@ static function signOut($user) {
sprintf(_S("%s logged out [%s]" /* Tokens are <username> and <ip> */),
$user->getUserName(), $_SERVER['REMOTE_ADDR']));

$u = User::lookup($user->getId());
$u = $user->getSessionUser()->getUser();
$type = array('type' => 'logout');
Signal::send('person.logout', $u, $type);
}
Expand Down Expand Up @@ -906,14 +906,9 @@ function authstrike($credentials) {
$alert, $admin_alert);

if ($username) {
$staffId = Staff::objects()->filter(array('username'=>$username))->values_flat('staff_id')->first();
if ($staffId)
$staff = Staff::lookup($staffId[0]);
if ($staff) {
$agent = Staff::lookup($staff->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}
$agent = Staff::lookup($username);
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $agent, $type);
}

return new AccessDenied(__('Forgot your login info? Contact Admin.'));
Expand Down Expand Up @@ -986,9 +981,8 @@ function authstrike($credentials) {
$user = User::lookup($id);

if ($user) {
$u = User::lookup($user->getId());
$type = array('type' => 'login', 'msg' => sprintf('Excessive login attempts (%s)', $authsession['strikes']));
Signal::send('person.login', $u, $type);
Signal::send('person.login', $user, $type);
}
}

Expand Down
7 changes: 7 additions & 0 deletions include/class.client.php
Expand Up @@ -312,6 +312,13 @@ function getAccount() {
return $this->_account;
}

function getUser() {
if ($this->user === false)
$this->user = User::lookup($this->getId());

return $this->user;
}

function getLanguage($flags=false) {
if ($acct = $this->getAccount())
return $acct->getLanguage($flags);
Expand Down

0 comments on commit 54a175a

Please sign in to comment.