summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-03 15:22:41 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-03 15:22:41 +0200
commit4b2544925f7f51d7e5cb1329166451f4fbd9e6bf (patch)
treece9a58e2532ec0301dc7e0c266f8256eb79826f9 /lib
parentdf2eb96cc40893f60a1b63abbe585c448e0a6d9f (diff)
parent661ab1a8c51ec251c44f76c7d58484ff14003336 (diff)
downloadnextcloud-server-4b2544925f7f51d7e5cb1329166451f4fbd9e6bf.tar.gz
nextcloud-server-4b2544925f7f51d7e5cb1329166451f4fbd9e6bf.zip
Merge pull request #23844 from owncloud/disable-user
Add occ commands to enable and disable a user + a disabled user can n…
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/api.php6
-rw-r--r--lib/private/legacy/user.php14
-rw-r--r--lib/private/user/session.php46
-rw-r--r--lib/private/user/user.php1
-rw-r--r--lib/public/iuser.php1
5 files changed, 37 insertions, 31 deletions
diff --git a/lib/private/legacy/api.php b/lib/private/legacy/api.php
index bab879c95f8..702b9df1927 100644
--- a/lib/private/legacy/api.php
+++ b/lib/private/legacy/api.php
@@ -356,7 +356,11 @@ class OC_API {
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) ) {
$authUser = $_SERVER['PHP_AUTH_USER'];
$authPw = $_SERVER['PHP_AUTH_PW'];
- $return = OC_User::login($authUser, $authPw);
+ try {
+ $return = OC_User::login($authUser, $authPw);
+ } catch (\OC\User\LoginException $e) {
+ return false;
+ }
if ($return === true) {
self::$logoutRequired = true;
diff --git a/lib/private/legacy/user.php b/lib/private/legacy/user.php
index 78eb4bab126..18a4c369d5e 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;
@@ -183,6 +181,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
@@ -249,6 +248,8 @@ class OC_User {
/**
* Sets user id for session and triggers emit
+ *
+ * @param string $uid
*/
public static function setUserId($uid) {
$userSession = \OC::$server->getUserSession();
@@ -304,14 +305,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
*