From 0836366d8703b2663d11e2989f8dbbb3f7c0c18b Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Sun, 29 Jul 2012 16:07:51 +0000 Subject: [PATCH] Methods to disable and enable users --- lib/user.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/user.php b/lib/user.php index e3c9c23eff..49a0a2a10c 100644 --- a/lib/user.php +++ b/lib/user.php @@ -208,8 +208,9 @@ class OC_User { OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); if( $run ){ - $uid=self::checkPassword( $uid, $password ); - if($uid){ + $uid = self::checkPassword( $uid, $password ); + $enabled = self::isEnabled($uid); + if($uid && $enabled){ session_regenerate_id(true); self::setUserId($uid); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password )); @@ -363,6 +364,38 @@ class OC_User { } return false; } + + /** + * disables a user + * @param string $userid the user to disable + */ + public static function disableUser($userid){ + $query = "INSERT INTO *PREFIX*preferences (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)"; + $query = OC_DB::prepare($query); + $query->execute(array($userid, 'core', 'enabled', 'false')); + } + + /** + * enable a user + * @param string $userid + */ + public static function enableUser($userid){ + $query = "DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ? AND configvalue = ?"; + $query = OC_DB::prepare($query); + $query->execute(array($userid, 'core', 'enabled', 'false')); + } + + /** + * checks if a user is enabled + * @param string $userid + * @return bool + */ + public static function isEnabled($userid){ + $query = "SELECT userid FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ? AND configvalue = ?"; + $query = OC_DB::prepare($query); + $results = $query->execute(array($userid, 'core', 'enabled', 'false')); + return $results->numRows() ? false : true; + } /** * @brief Set cookie value to use in next page load