Skip to content

Commit

Permalink
Ignore adding group if its invalid (#3436)
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen authored Sep 8, 2023
1 parent 1d60fcc commit 1a24865
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions core/classes/Core/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,21 @@ public function addGroup(int $group_id, int $expire = 0): bool {
return false;
}

$group = Group::find($group_id);
if (!$group) {
ErrorHandler::logWarning('Could not add invalid group ' . $group_id . ' to user ' . $this->data()->id);
return false;
}

$this->_db->query('INSERT INTO `nl2_users_groups` (`user_id`, `group_id`, `received`, `expire`) VALUES (?, ?, ?, ?)', [
$this->data()->id,
$group_id,
date('U'),
$expire
]);

$group = Group::find($group_id);
if ($group) {
$this->_groups[$group_id] = $group;
self::$_group_cache[$this->data()->id][$group_id] = $group;
}
$this->_groups[$group_id] = $group;
self::$_group_cache[$this->data()->id][$group_id] = $group;

EventHandler::executeEvent(new UserGroupAddedEvent(
$this,
Expand Down Expand Up @@ -658,6 +661,12 @@ public function getMainGroup(): Group {
* @return false|void
*/
public function setGroup(int $group_id, int $expire = 0) {
$group = Group::find($group_id);
if (!$group) {
ErrorHandler::logWarning('Could not set invalid group ' . $group_id . ' to user ' . $this->data()->id);
return false;
}

if ($this->data()->id == 1) {
return false;
}
Expand All @@ -672,11 +681,9 @@ public function setGroup(int $group_id, int $expire = 0) {
]);

$this->_groups = [];
$group = Group::find($group_id);
if ($group) {
$this->_groups[$group_id] = $group;
self::$_group_cache[$this->data()->id] = $this->_groups;
}
$this->_groups[$group_id] = $group;
self::$_group_cache[$this->data()->id] = $this->_groups;

}

/**
Expand Down

0 comments on commit 1a24865

Please sign in to comment.