Skip to content
Snippets Groups Projects
Unverified Commit 23b8995b authored by Peter Rotich's avatar Peter Rotich Committed by GitHub
Browse files

Merge pull request #4450 from JediKev/sessions/clear-sessions-on-reset

sessions: Clear On Password Set/Reset
parents 7c19892a 1aaab76f
No related branches found
No related tags found
No related merge requests found
...@@ -1313,7 +1313,35 @@ abstract class PasswordPolicy { ...@@ -1313,7 +1313,35 @@ abstract class PasswordPolicy {
static function register($policy) { static function register($policy) {
static::$registry[] = $policy; static::$registry[] = $policy;
} }
static function cleanSessions($model, $user=null) {
$criteria = array();
switch (true) {
case ($model instanceof Staff):
$criteria['user_id'] = $model->getId();
if ($user && ($model->getId() == $user->getId()))
array_push($criteria,
Q::not(array('session_id' => $user->session->session_id)));
break;
case ($model instanceof User):
$regexp = '_auth\|.*"user";[a-z]+:[0-9]+:{[a-z]+:[0-9]+:"id";[a-z]+:'.$model->getId();
$criteria['user_id'] = 0;
$criteria['session_data__regex'] = $regexp;
if ($user)
array_push($criteria,
Q::not(array('session_id' => $user->session->session_id)));
break;
default:
return false;
}
return SessionData::objects()->filter($criteria)->delete();
}
} }
Signal::connect('auth.clean', array('PasswordPolicy', 'cleanSessions'));
class osTicketPasswordPolicy class osTicketPasswordPolicy
extends PasswordPolicy { extends PasswordPolicy {
......
...@@ -396,7 +396,7 @@ class ClientAccount extends UserAccount { ...@@ -396,7 +396,7 @@ class ClientAccount extends UserAccount {
global $cfg; global $cfg;
// FIXME: Updates by agents should go through UserAccount::update() // FIXME: Updates by agents should go through UserAccount::update()
global $thisstaff; global $thisstaff, $thisclient;
if ($thisstaff) if ($thisstaff)
return parent::update($vars, $errors); return parent::update($vars, $errors);
...@@ -454,6 +454,8 @@ class ClientAccount extends UserAccount { ...@@ -454,6 +454,8 @@ class ClientAccount extends UserAccount {
Signal::send('auth.pwchange', $this->getUser(), $info); Signal::send('auth.pwchange', $this->getUser(), $info);
$this->cancelResetTokens(); $this->cancelResetTokens();
$this->clearStatus(UserAccountStatus::REQUIRE_PASSWD_RESET); $this->clearStatus(UserAccountStatus::REQUIRE_PASSWD_RESET);
// Clean sessions
Signal::send('auth.clean', $this->getUser(), $thisclient);
} }
return $this->save(); return $this->save();
......
...@@ -217,6 +217,8 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -217,6 +217,8 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
} }
function setPassword($new, $current=false) { function setPassword($new, $current=false) {
global $thisstaff;
// Allow the backend to update the password. This is the preferred // Allow the backend to update the password. This is the preferred
// method as it allows for integration with password policies and // method as it allows for integration with password policies and
// also allows for remotely updating the password where possible and // also allows for remotely updating the password where possible and
...@@ -241,6 +243,9 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -241,6 +243,9 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$this->cancelResetTokens(); $this->cancelResetTokens();
$this->passwdreset = SqlFunction::NOW(); $this->passwdreset = SqlFunction::NOW();
// Clean sessions
Signal::send('auth.clean', $this, $thisstaff);
return $rv; return $rv;
} }
......
...@@ -1033,6 +1033,8 @@ class UserAccount extends VerySimpleModel { ...@@ -1033,6 +1033,8 @@ class UserAccount extends VerySimpleModel {
function setPassword($new) { function setPassword($new) {
$this->set('passwd', Passwd::hash($new)); $this->set('passwd', Passwd::hash($new));
// Clean sessions
Signal::send('auth.clean', $this->getUser());
} }
protected function sendUnlockEmail($template) { protected function sendUnlockEmail($template) {
......
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