Skip to content
Snippets Groups Projects
Commit 0ed86c09 authored by Joas Schilling's avatar Joas Schilling
Browse files

Move OC_USER_BACKEND_* constants to OC_User_Backend class

parent 24511c6f
No related branches found
No related tags found
No related merge requests found
...@@ -25,19 +25,28 @@ ...@@ -25,19 +25,28 @@
/** /**
* error code for functions not provided by the user backend * error code for functions not provided by the user backend
* @deprecated Use \OC_User_Backend::NOT_IMPLEMENTED instead
*/ */
define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501); define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
/** /**
* actions that user backends can define * actions that user backends can define
*/ */
/** @deprecated Use \OC_User_Backend::CREATE_USER instead */
define('OC_USER_BACKEND_CREATE_USER', 1 << 0); define('OC_USER_BACKEND_CREATE_USER', 1 << 0);
/** @deprecated Use \OC_User_Backend::SET_PASSWORD instead */
define('OC_USER_BACKEND_SET_PASSWORD', 1 << 4); define('OC_USER_BACKEND_SET_PASSWORD', 1 << 4);
/** @deprecated Use \OC_User_Backend::CHECK_PASSWORD instead */
define('OC_USER_BACKEND_CHECK_PASSWORD', 1 << 8); define('OC_USER_BACKEND_CHECK_PASSWORD', 1 << 8);
/** @deprecated Use \OC_User_Backend::GET_HOME instead */
define('OC_USER_BACKEND_GET_HOME', 1 << 12); define('OC_USER_BACKEND_GET_HOME', 1 << 12);
/** @deprecated Use \OC_User_Backend::GET_DISPLAYNAME instead */
define('OC_USER_BACKEND_GET_DISPLAYNAME', 1 << 16); define('OC_USER_BACKEND_GET_DISPLAYNAME', 1 << 16);
/** @deprecated Use \OC_User_Backend::SET_DISPLAYNAME instead */
define('OC_USER_BACKEND_SET_DISPLAYNAME', 1 << 20); define('OC_USER_BACKEND_SET_DISPLAYNAME', 1 << 20);
/** @deprecated Use \OC_User_Backend::PROVIDE_AVATAR instead */
define('OC_USER_BACKEND_PROVIDE_AVATAR', 1 << 24); define('OC_USER_BACKEND_PROVIDE_AVATAR', 1 << 24);
/** @deprecated Use \OC_User_Backend::COUNT_USERS instead */
define('OC_USER_BACKEND_COUNT_USERS', 1 << 28); define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
/** /**
...@@ -47,16 +56,32 @@ define('OC_USER_BACKEND_COUNT_USERS', 1 << 28); ...@@ -47,16 +56,32 @@ define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
* Subclass this for your own backends, and see OC_User_Example for descriptions * Subclass this for your own backends, and see OC_User_Example for descriptions
*/ */
abstract class OC_User_Backend implements OC_User_Interface { abstract class OC_User_Backend implements OC_User_Interface {
/**
* error code for functions not provided by the user backend
*/
const NOT_IMPLEMENTED = -501;
/**
* actions that user backends can define
*/
const CREATE_USER = 1; // 1 << 0
const SET_PASSWORD = 16; // 1 << 4
const CHECK_PASSWORD = 256; // 1 << 8
const GET_HOME = 4096; // 1 << 12
const GET_DISPLAYNAME = 65536; // 1 << 16
const SET_DISPLAYNAME = 1048576; // 1 << 20
const PROVIDE_AVATAR = 16777216; // 1 << 24
const COUNT_USERS = 268435456; // 1 << 28
protected $possibleActions = array( protected $possibleActions = array(
OC_USER_BACKEND_CREATE_USER => 'createUser', self::CREATE_USER => 'createUser',
OC_USER_BACKEND_SET_PASSWORD => 'setPassword', self::SET_PASSWORD => 'setPassword',
OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword', self::CHECK_PASSWORD => 'checkPassword',
OC_USER_BACKEND_GET_HOME => 'getHome', self::GET_HOME => 'getHome',
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName', self::GET_DISPLAYNAME => 'getDisplayName',
OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName', self::SET_DISPLAYNAME => 'setDisplayName',
OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar', self::PROVIDE_AVATAR => 'canChangeAvatar',
OC_USER_BACKEND_COUNT_USERS => 'countUsers', self::COUNT_USERS => 'countUsers',
); );
/** /**
...@@ -64,7 +89,7 @@ abstract class OC_User_Backend implements OC_User_Interface { ...@@ -64,7 +89,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
* @return int bitwise-or'ed actions * @return int bitwise-or'ed actions
* *
* Returns the supported actions as int to be * Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc. * compared with self::CREATE_USER etc.
*/ */
public function getSupportedActions() { public function getSupportedActions() {
$actions = 0; $actions = 0;
...@@ -83,7 +108,7 @@ abstract class OC_User_Backend implements OC_User_Interface { ...@@ -83,7 +108,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
* @return boolean * @return boolean
* *
* Returns the supported actions as int to be * Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc. * compared with self::CREATE_USER etc.
*/ */
public function implementsActions($actions) { public function implementsActions($actions) {
return (bool)($this->getSupportedActions() & $actions); return (bool)($this->getSupportedActions() & $actions);
......
...@@ -25,11 +25,11 @@ interface OC_User_Interface { ...@@ -25,11 +25,11 @@ interface OC_User_Interface {
/** /**
* Check if backend implements actions * Check if backend implements actions
* @param $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* *
* Returns the supported actions as int to be * Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc. * compared with \OC_User_Backend::CREATE_USER etc.
*/ */
public function implementsActions($actions); public function implementsActions($actions);
......
...@@ -143,7 +143,7 @@ class Manager extends PublicEmitter implements IUserManager { ...@@ -143,7 +143,7 @@ class Manager extends PublicEmitter implements IUserManager {
*/ */
public function checkPassword($loginname, $password) { public function checkPassword($loginname, $password) {
foreach ($this->backends as $backend) { 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); $uid = $backend->checkPassword($loginname, $password);
if ($uid !== false) { if ($uid !== false) {
return $this->getUserObject($uid, $backend); return $this->getUserObject($uid, $backend);
...@@ -246,7 +246,7 @@ class Manager extends PublicEmitter implements IUserManager { ...@@ -246,7 +246,7 @@ class Manager extends PublicEmitter implements IUserManager {
$this->emit('\OC\User', 'preCreateUser', array($uid, $password)); $this->emit('\OC\User', 'preCreateUser', array($uid, $password));
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_CREATE_USER)) { if ($backend->implementsActions(\OC_User_Backend::CREATE_USER)) {
$backend->createUser($uid, $password); $backend->createUser($uid, $password);
$user = $this->getUserObject($uid, $backend); $user = $this->getUserObject($uid, $backend);
$this->emit('\OC\User', 'postCreateUser', array($user, $password)); $this->emit('\OC\User', 'postCreateUser', array($user, $password));
...@@ -264,7 +264,7 @@ class Manager extends PublicEmitter implements IUserManager { ...@@ -264,7 +264,7 @@ class Manager extends PublicEmitter implements IUserManager {
public function countUsers() { public function countUsers() {
$userCountStatistics = array(); $userCountStatistics = array();
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) { if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
$backendusers = $backend->countUsers(); $backendusers = $backend->countUsers();
if($backendusers !== false) { if($backendusers !== false) {
if(isset($userCountStatistics[get_class($backend)])) { if(isset($userCountStatistics[get_class($backend)])) {
......
...@@ -90,7 +90,7 @@ class User implements IUser { ...@@ -90,7 +90,7 @@ class User implements IUser {
public function getDisplayName() { public function getDisplayName() {
if (!isset($this->displayName)) { if (!isset($this->displayName)) {
$displayName = ''; $displayName = '';
if ($this->backend and $this->backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { if ($this->backend and $this->backend->implementsActions(\OC_User_Backend::GET_DISPLAYNAME)) {
// get display name and strip whitespace from the beginning and end of it // get display name and strip whitespace from the beginning and end of it
$backendDisplayName = $this->backend->getDisplayName($this->uid); $backendDisplayName = $this->backend->getDisplayName($this->uid);
if (is_string($backendDisplayName)) { if (is_string($backendDisplayName)) {
...@@ -115,7 +115,7 @@ class User implements IUser { ...@@ -115,7 +115,7 @@ class User implements IUser {
*/ */
public function setDisplayName($displayName) { public function setDisplayName($displayName) {
$displayName = trim($displayName); $displayName = trim($displayName);
if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME) && !empty($displayName)) { if ($this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME) && !empty($displayName)) {
$this->displayName = $displayName; $this->displayName = $displayName;
$result = $this->backend->setDisplayName($this->uid, $displayName); $result = $this->backend->setDisplayName($this->uid, $displayName);
return $result !== false; return $result !== false;
...@@ -170,7 +170,7 @@ class User implements IUser { ...@@ -170,7 +170,7 @@ class User implements IUser {
if ($this->emitter) { if ($this->emitter) {
$this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
} }
if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD)) { if ($this->backend->implementsActions(\OC_User_Backend::SET_PASSWORD)) {
$result = $this->backend->setPassword($this->uid, $password); $result = $this->backend->setPassword($this->uid, $password);
if ($this->emitter) { if ($this->emitter) {
$this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
...@@ -188,7 +188,7 @@ class User implements IUser { ...@@ -188,7 +188,7 @@ class User implements IUser {
*/ */
public function getHome() { public function getHome() {
if (!$this->home) { if (!$this->home) {
if ($this->backend->implementsActions(\OC_USER_BACKEND_GET_HOME) and $home = $this->backend->getHome($this->uid)) { if ($this->backend->implementsActions(\OC_User_Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
$this->home = $home; $this->home = $home;
} elseif ($this->config) { } elseif ($this->config) {
$this->home = $this->config->getSystemValue('datadirectory') . '/' . $this->uid; $this->home = $this->config->getSystemValue('datadirectory') . '/' . $this->uid;
...@@ -205,7 +205,7 @@ class User implements IUser { ...@@ -205,7 +205,7 @@ class User implements IUser {
* @return bool * @return bool
*/ */
public function canChangeAvatar() { public function canChangeAvatar() {
if ($this->backend->implementsActions(\OC_USER_BACKEND_PROVIDE_AVATAR)) { if ($this->backend->implementsActions(\OC_User_Backend::PROVIDE_AVATAR)) {
return $this->backend->canChangeAvatar($this->uid); return $this->backend->canChangeAvatar($this->uid);
} }
return true; return true;
...@@ -217,7 +217,7 @@ class User implements IUser { ...@@ -217,7 +217,7 @@ class User implements IUser {
* @return bool * @return bool
*/ */
public function canChangePassword() { public function canChangePassword() {
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD); return $this->backend->implementsActions(\OC_User_Backend::SET_PASSWORD);
} }
/** /**
...@@ -229,7 +229,7 @@ class User implements IUser { ...@@ -229,7 +229,7 @@ class User implements IUser {
if ($this->config and $this->config->getSystemValue('allow_user_to_change_display_name') === false) { if ($this->config and $this->config->getSystemValue('allow_user_to_change_display_name') === false) {
return false; return false;
} else { } else {
return $this->backend->implementsActions(\OC_USER_BACKEND_SET_DISPLAYNAME); return $this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment