From 9c9fec36dd469494738b57c691338cbe71926c10 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 7 Apr 2016 15:39:34 +0200 Subject: Add occ commands to enable and disable a user + a disabled user can no longer login - fixes #23838 --- lib/private/legacy/user.php | 14 ++++++-------- lib/private/user/session.php | 46 ++++++++++++++++++++++++-------------------- lib/private/user/user.php | 1 - lib/public/iuser.php | 1 + 4 files changed, 32 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php index 11c35daa0de..34ce68e989f 100644 --- a/lib/private/legacy/user.php +++ b/lib/private/legacy/user.php @@ -63,8 +63,6 @@ class OC_User { return OC::$server->getUserSession(); } - private static $_backends = array(); - private static $_usedBackends = array(); private static $_setupedBackends = array(); @@ -105,7 +103,7 @@ class OC_User { break; default: \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); - $className = 'OC_USER_' . strToUpper($backend); + $className = 'OC_USER_' . strtoupper($backend); self::$_usedBackends[$backend] = new $className(); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); break; @@ -175,6 +173,7 @@ class OC_User { /** * Try to login a user using the magic cookie (remember login) * + * @deprecated use \OCP\IUserSession::loginWithCookie() * @param string $uid The username of the user to log in * @param string $token * @return bool @@ -241,6 +240,8 @@ class OC_User { /** * Sets user id for session and triggers emit + * + * @param string $uid */ public static function setUserId($uid) { $userSession = \OC::$server->getUserSession(); @@ -296,14 +297,11 @@ class OC_User { /** * Check if the user is logged in, considers also the HTTP basic credentials * + * @deprecated use \OC::$server->getUserSession()->isLoggedIn() * @return bool */ public static function isLoggedIn() { - if (\OC::$server->getSession()->get('user_id') !== null && self::$incognitoMode === false) { - return self::userExists(\OC::$server->getSession()->get('user_id')); - } - - return false; + return \OC::$server->getUserSession()->isLoggedIn(); } /** diff --git a/lib/private/user/session.php b/lib/private/user/session.php index 5402c5cf74f..c7f8a6920de 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -32,6 +32,8 @@ namespace OC\User; use OC\Hooks\Emitter; +use OCP\ISession; +use OCP\IUserManager; use OCP\IUserSession; /** @@ -53,26 +55,20 @@ use OCP\IUserSession; * @package OC\User */ class Session implements IUserSession, Emitter { - /** - * @var \OC\User\Manager $manager - */ + /** @var \OC\User\Manager $manager */ private $manager; - /** - * @var \OC\Session\Session $session - */ + /** @var \OC\Session\Session $session */ private $session; - /** - * @var \OC\User\User $activeUser - */ + /** @var \OC\User\User $activeUser */ protected $activeUser; /** - * @param \OCP\IUserManager $manager - * @param \OCP\ISession $session + * @param IUserManager $manager + * @param ISession $session */ - public function __construct(\OCP\IUserManager $manager, \OCP\ISession $session) { + public function __construct(IUserManager $manager, ISession $session) { $this->manager = $manager; $this->session = $session; } @@ -107,7 +103,7 @@ class Session implements IUserSession, Emitter { /** * get the session object * - * @return \OCP\ISession + * @return ISession */ public function getSession() { return $this->session; @@ -116,10 +112,10 @@ class Session implements IUserSession, Emitter { /** * set the session object * - * @param \OCP\ISession $session + * @param ISession $session */ - public function setSession(\OCP\ISession $session) { - if ($this->session instanceof \OCP\ISession) { + public function setSession(ISession $session) { + if ($this->session instanceof ISession) { $this->session->close(); } $this->session = $session; @@ -170,7 +166,12 @@ class Session implements IUserSession, Emitter { * @return bool if logged in */ public function isLoggedIn() { - return $this->getUser() !== null; + $user = $this->getUser(); + if (is_null($user)) { + return false; + } + + return $user->isEnabled(); } /** @@ -226,15 +227,18 @@ class Session implements IUserSession, Emitter { if ($this->isLoggedIn()) { return true; } else { - throw new LoginException('Login canceled by app'); + // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory + $message = \OC::$server->getL10N('lib')->t('Login canceled by app'); + throw new LoginException($message); } } else { - return false; + // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory + $message = \OC::$server->getL10N('lib')->t('User disabled'); + throw new LoginException($message); } } - } else { - return false; } + return false; } /** diff --git a/lib/private/user/user.php b/lib/private/user/user.php index 3199790dba0..36680436769 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -417,5 +417,4 @@ class User implements IUser { $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value)); } } - } diff --git a/lib/public/iuser.php b/lib/public/iuser.php index b0dd8dc35b2..16617a2f2f6 100644 --- a/lib/public/iuser.php +++ b/lib/public/iuser.php @@ -32,6 +32,7 @@ namespace OCP; * @since 8.0.0 */ interface IUser { + /** * get the user id * -- cgit v1.2.3