return new Root($manager, $view, $user);
});
$this->registerService('UserManager', function($c) {
- return new \OC\User\Manager();
+ /**
+ * @var SimpleContainer $c
+ * @var \OC\AllConfig $config
+ */
+ $config = $c->query('AllConfig');
+ return new \OC\User\Manager($config);
});
$this->registerService('UserSession', function($c) {
- /** @var $c SimpleContainer */
+ /**
+ * @var SimpleContainer $c
+ * @var \OC\User\Manager $manager
+ */
$manager = $c->query('UserManager');
$userSession = new \OC\User\Session($manager, \OC::$session);
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
*/
private $cachedUsers = array();
- public function __construct() {
+ /**
+ * @var \OC\AllConfig $config
+ */
+ private $config;
+
+ /**
+ * @param \OC\AllConfig $config
+ */
+ public function __construct($config = null) {
+ $this->config = $config;
$cachedUsers = $this->cachedUsers;
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
$i = array_search($user, $cachedUsers);
if (isset($this->cachedUsers[$uid])) {
return $this->cachedUsers[$uid];
}
- $this->cachedUsers[$uid] = new User($uid, $backend, $this);
+ $this->cachedUsers[$uid] = new User($uid, $backend, $this, $this->config);
return $this->cachedUsers[$uid];
}
*/
public function checkPassword($loginname, $password) {
foreach ($this->backends as $backend) {
- if($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
+ if ($backend->implementsActions(\OC_USER_BACKEND_CHECK_PASSWORD)) {
$uid = $backend->checkPassword($loginname, $password);
if ($uid !== false) {
return $this->getUserObject($uid, $backend);
// Allowed are: "a-z", "A-Z", "0-9" and "_.@-"
if (preg_match('/[^a-zA-Z0-9 _\.@\-]/', $uid)) {
throw new \Exception('Only the following characters are allowed in a username:'
- . ' "a-z", "A-Z", "0-9", and "_.@-"');
+ . ' "a-z", "A-Z", "0-9", and "_.@-"');
}
// No empty username
if (trim($uid) == '') {
*/
private $home;
+ /**
+ * @var \OC\AllConfig $config
+ */
+ private $config;
+
/**
* @param string $uid
* @param \OC_User_Backend $backend
- * @param Emitter $emitter
+ * @param \OC\Hooks\Emitter $emitter
+ * @param \OC\AllConfig $config
*/
- public function __construct($uid, $backend, $emitter = null) {
+ public function __construct($uid, $backend, $emitter = null, $config = null) {
$this->uid = $uid;
if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
$this->displayName = $backend->getDisplayName($uid);
$this->emitter = $emitter;
$enabled = \OC_Preferences::getValue($uid, 'core', 'enabled', 'true'); //TODO: DI for OC_Preferences
$this->enabled = ($enabled === 'true');
+ $this->config = $config;
}
/**
* @return bool
*/
public function canChangeDisplayName() {
- return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
+ if ($this->config and $this->config->getSystemValue('allow_user_to_change_display_name') === false) {
+ return false;
+ } else {
+ return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME);
+ }
}
/**