Skip to content
Snippets Groups Projects
Commit 05bd7c02 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

implement User::isBlocked() and User::isExpired() and use them across the system, fixes #2025

Closes #2025

Merge request studip/studip!1318
parent ec43f9bf
No related branches found
No related tags found
No related merge requests found
...@@ -108,17 +108,6 @@ class ForumAbo ...@@ -108,17 +108,6 @@ class ForumAbo
$user = User::find($user_id); $user = User::find($user_id);
// check if user wants an email for all or selected messages only
$force_email = false;
if ($messaging->user_wants_email($user_id)) {
$force_email = true;
}
// do not send mails when account is locked or expired
$expiration = UserConfig::get($user->id)->EXPIRATION_DATE;
if ($user->locked || ($expiration > 0 && $expiration < time())) {
$force_email = false;
}
setTempLanguage($data['user_id']); setTempLanguage($data['user_id']);
$notification = sprintf( $notification = sprintf(
_('%s hat einen Beitrag geschrieben'), _('%s hat einen Beitrag geschrieben'),
...@@ -138,7 +127,8 @@ class ForumAbo ...@@ -138,7 +127,8 @@ class ForumAbo
Icon::create('forum', 'clickable') Icon::create('forum', 'clickable')
); );
if ($force_email) { // check if user wants an email for all or selected messages only
if (!$user->isBlocked() && $messaging->user_wants_email($user_id)) {
$title = implode(' >> ', ForumEntry::getFlatPathToPosting($topic_id)); $title = implode(' >> ', ForumEntry::getFlatPathToPosting($topic_id));
$subject = _('[Forum]') . ' ' . ($title ?: _('Neuer Beitrag')); $subject = _('[Forum]') . ' ' . ($title ?: _('Neuer Beitrag'));
......
...@@ -149,9 +149,7 @@ class StudipAuthAbstract ...@@ -149,9 +149,7 @@ class StudipAuthAbstract
$checkIPRange = ($GLOBALS['ENABLE_ADMIN_IP_CHECK'] && $user['perms'] === 'admin') $checkIPRange = ($GLOBALS['ENABLE_ADMIN_IP_CHECK'] && $user['perms'] === 'admin')
|| ($GLOBALS['ENABLE_ROOT_IP_CHECK'] && $user['perms'] === 'root'); || ($GLOBALS['ENABLE_ROOT_IP_CHECK'] && $user['perms'] === 'root');
$exp_d = UserConfig::get($user['user_id'])->EXPIRATION_DATE; if ($user->isExpired()) {
if ($exp_d > 0 && $exp_d < time()) {
$error .= _('Dieses Benutzerkonto ist abgelaufen.<br> Wenden Sie sich bitte an die Administration.') . '<BR>'; $error .= _('Dieses Benutzerkonto ist abgelaufen.<br> Wenden Sie sich bitte an die Administration.') . '<BR>';
return ['uid' => false, 'error' => $error]; return ['uid' => false, 'error' => $error];
} else if ($locked) { } else if ($locked) {
......
...@@ -106,11 +106,7 @@ class SendMailNotificationsJob extends CronJob ...@@ -106,11 +106,7 @@ class SendMailNotificationsJob extends CronJob
[], [],
function ($user_id) use ($parameters, $notification) { function ($user_id) use ($parameters, $notification) {
$user = User::find($user_id); $user = User::find($user_id);
if ( if (!$user || $user->isBlocked()) {
!$user
|| $user->locked
|| ($user->config->EXPIRATION_DATE > 0 && $user->config->EXPIRATION_DATE < time())
) {
return; return;
} }
......
...@@ -166,9 +166,9 @@ class messaging ...@@ -166,9 +166,9 @@ class messaging
if (!$to) { if (!$to) {
return; return;
} }
// do not send mails when account is locked or expired // do not send mails when account is locked or expired
$expiration = UserConfig::get($receiver->id)->EXPIRATION_DATE; if ($receiver->isBlocked()) {
if ($receiver->locked || ($expiration > 0 && $expiration < time())) {
return; return;
} }
......
...@@ -1474,4 +1474,28 @@ class User extends AuthUserMd5 implements Range, PrivacyObject ...@@ -1474,4 +1474,28 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
{ {
return $this->getFullName(); return $this->getFullName();
} }
/**
* Returns whether a user is blocked either explicitely due to the "locked"
* property or by a set expiration date.
*
* @return bool
* @since Stud.IP 5.4
*/
public function isBlocked(): bool
{
return $this->locked || $this->isExpired();
}
/**
* Returns whether a user account is expired.
*
* @return bool
* @since Stud.IP 5.4
*/
public function isExpired(): bool
{
return $this->config->EXPIRATION_DATE > 0
&& $this->config->EXPIRATION_DATE < time();
}
} }
...@@ -230,12 +230,11 @@ class Seminar_Auth ...@@ -230,12 +230,11 @@ class Seminar_Auth
if (!empty($this->auth['uid']) && !in_array($this->auth['uid'], ['form', 'nobody'])) { if (!empty($this->auth['uid']) && !in_array($this->auth['uid'], ['form', 'nobody'])) {
$user = null; $user = null;
if (isset($GLOBALS['user']) && $GLOBALS['user']->id == $this->auth['uid']) { if (isset($GLOBALS['user']) && $GLOBALS['user']->id == $this->auth['uid']) {
$user = $GLOBALS['user']; $user = $GLOBALS['user']->getAuthenticatedUser();
} else { } else {
$user = User::find($this->auth['uid']); $user = User::find($this->auth['uid']);
} }
$exp_d = $user->username ? UserConfig::get($user->id)->EXPIRATION_DATE : 0; if (!$user->username || $user->isBlocked()) {
if (!$user->username || $user->locked || ($exp_d > 0 && $exp_d < time())) {
$this->unauth(); $this->unauth();
} }
} elseif ($cfg->getValue('MAINTENANCE_MODE_ENABLE') && Request::username('loginname')) { } elseif ($cfg->getValue('MAINTENANCE_MODE_ENABLE') && Request::username('loginname')) {
...@@ -265,8 +264,7 @@ class Seminar_Auth ...@@ -265,8 +264,7 @@ class Seminar_Auth
$authplugin->authenticateUser('', ''); $authplugin->authenticateUser('', '');
if ($authplugin->getUser()) { if ($authplugin->getUser()) {
$user = $authplugin->getStudipUser($authplugin->getUser()); $user = $authplugin->getStudipUser($authplugin->getUser());
$exp_d = UserConfig::get($user->id)->EXPIRATION_DATE; if ($user->isExpired()) {
if ($exp_d > 0 && $exp_d < time()) {
throw new AccessDeniedException(_('Dieses Benutzerkonto ist abgelaufen. Wenden Sie sich bitte an die Administration.')); throw new AccessDeniedException(_('Dieses Benutzerkonto ist abgelaufen. Wenden Sie sich bitte an die Administration.'));
} }
if ($user->locked == 1) { if ($user->locked == 1) {
......
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