0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-20 03:36:20 +02:00

Adds an ability to update password_expity field when user changes own password

This commit is contained in:
Andrey Miroshnichenko 2021-05-13 00:23:05 +03:00 committed by David Goodwin
parent 51d97d7bad
commit a00a24901b

View File

@ -87,6 +87,32 @@ class Login {
return false;
}
/**
* returns user's domain name
* @param $username
* @return mixed|null
* @throws Exception
*/
protected function getUserDomain($username)
{
$sql = "SELECT domain FROM {$this->table} WHERE username = :username AND active = :active";
$active = db_get_boolean(true);
$values = [
'username' => $username,
'active' => $active,
];
// Fetch the domain
$result = db_query_one($sql, $values);
if (is_array($result) && isset($result['domain'])) {
return $result['domain'];
} else {
return NULL;
}
}
/**
* @param string $username
@ -110,6 +136,14 @@ class Login {
'password' => pacrypt($new_password),
);
if (Config::bool('password_expiration')) {
$domain = $this->getUserDomain($username);
if (!is_null($domain)) {
$password_expiration_value = (int)get_password_expiration_value($domain);
$set['password_expiry'] = date('Y-m-d H:i', strtotime("+$password_expiration_value day"));
}
}
$result = db_update($this->table, 'username', $username, $set);
if ($result != 1) {