From e90692bc720cf4c520ee36c603395cf1e1b80b45 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 9 Jan 2009 14:21:48 +0000 Subject: Closes #668: Banning now works through a flag in the users_entity table. Database upgrade required. * Added ElggUser::isBanned(); * Added 'banned' column to users_entity * Modified ban() and unban() * Modified pam functions to check $user->isBanned() * Modified login() to check $user->isBanned() * Modified sessions_init() to check isBanned() and destroy session accordingly * Modified profile views to highlight banned users and prevent menus for non-admin users. git-svn-id: https://code.elgg.org/elgg/trunk@2554 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/users.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'engine/lib/users.php') diff --git a/engine/lib/users.php b/engine/lib/users.php index 79e9c9d24..0628f36c7 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -46,7 +46,8 @@ $this->attributes['salt'] = ""; $this->attributes['email'] = ""; $this->attributes['language'] = ""; - $this->attributes['code'] = ""; + $this->attributes['code'] = ""; + $this->attributes['banned'] = "no"; $this->attributes['tables_split'] = 2; } @@ -167,7 +168,14 @@ /** * Unban this user. */ - public function unban() { return unban_user($this->guid); } + public function unban() { return unban_user($this->guid); } + + /** + * Is this user banned or not? + * + * @return bool + */ + public function isBanned() { return $this->banned == 'yes'; } /** * Get sites that this user is a member of @@ -443,6 +451,8 @@ */ function ban_user($user_guid, $reason = "") { + global $CONFIG; + $user_guid = (int)$user_guid; $reason = sanitise_string($reason); @@ -450,8 +460,12 @@ if (($user) && ($user->canEdit()) && ($user instanceof ElggUser)) { - if (disable_user_entities($user_guid)) - return $user->disable($reason); + // Add reason + if ($reason) + create_metadata($user_guid, 'ban_reason', $reason,'', 0, 2); + + // Set ban flag + return update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid"); } return false; @@ -464,13 +478,16 @@ */ function unban_user($user_guid) { + global $CONFIG; + $user_guid = (int)$user_guid; $user = get_entity($user_guid); if (($user) && ($user->canEdit()) && ($user instanceof ElggUser)) { - return enable_entity($user_guid); + create_metadata($user_guid, 'ban_reason', '','', 0, 2); + return update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid=$user_guid"); } return false; -- cgit v1.2.3