Move OC_USER_BACKEND_* constants to OC_User_Backend class
This commit is contained in:
parent
24511c6f00
commit
0ed86c0993
|
@ -25,19 +25,28 @@
|
|||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* actions that user backends can define
|
||||
*/
|
||||
/** @deprecated Use \OC_User_Backend::CREATE_USER instead */
|
||||
define('OC_USER_BACKEND_CREATE_USER', 1 << 0);
|
||||
/** @deprecated Use \OC_User_Backend::SET_PASSWORD instead */
|
||||
define('OC_USER_BACKEND_SET_PASSWORD', 1 << 4);
|
||||
/** @deprecated Use \OC_User_Backend::CHECK_PASSWORD instead */
|
||||
define('OC_USER_BACKEND_CHECK_PASSWORD', 1 << 8);
|
||||
/** @deprecated Use \OC_User_Backend::GET_HOME instead */
|
||||
define('OC_USER_BACKEND_GET_HOME', 1 << 12);
|
||||
/** @deprecated Use \OC_User_Backend::GET_DISPLAYNAME instead */
|
||||
define('OC_USER_BACKEND_GET_DISPLAYNAME', 1 << 16);
|
||||
/** @deprecated Use \OC_User_Backend::SET_DISPLAYNAME instead */
|
||||
define('OC_USER_BACKEND_SET_DISPLAYNAME', 1 << 20);
|
||||
/** @deprecated Use \OC_User_Backend::PROVIDE_AVATAR instead */
|
||||
define('OC_USER_BACKEND_PROVIDE_AVATAR', 1 << 24);
|
||||
/** @deprecated Use \OC_User_Backend::COUNT_USERS instead */
|
||||
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
|
||||
*/
|
||||
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(
|
||||
OC_USER_BACKEND_CREATE_USER => 'createUser',
|
||||
OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
|
||||
OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
|
||||
OC_USER_BACKEND_GET_HOME => 'getHome',
|
||||
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
|
||||
OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
|
||||
OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar',
|
||||
OC_USER_BACKEND_COUNT_USERS => 'countUsers',
|
||||
self::CREATE_USER => 'createUser',
|
||||
self::SET_PASSWORD => 'setPassword',
|
||||
self::CHECK_PASSWORD => 'checkPassword',
|
||||
self::GET_HOME => 'getHome',
|
||||
self::GET_DISPLAYNAME => 'getDisplayName',
|
||||
self::SET_DISPLAYNAME => 'setDisplayName',
|
||||
self::PROVIDE_AVATAR => 'canChangeAvatar',
|
||||
self::COUNT_USERS => 'countUsers',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -64,7 +89,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
|
|||
* @return int bitwise-or'ed actions
|
||||
*
|
||||
* 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() {
|
||||
$actions = 0;
|
||||
|
@ -83,7 +108,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
|
|||
* @return boolean
|
||||
*
|
||||
* 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) {
|
||||
return (bool)($this->getSupportedActions() & $actions);
|
||||
|
|
|
@ -25,11 +25,11 @@ interface OC_User_Interface {
|
|||
|
||||
/**
|
||||
* Check if backend implements actions
|
||||
* @param $actions bitwise-or'ed actions
|
||||
* @param int $actions bitwise-or'ed actions
|
||||
* @return boolean
|
||||
*
|
||||
* 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);
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
*/
|
||||
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);
|
||||
|
@ -246,7 +246,7 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
|
||||
$this->emit('\OC\User', 'preCreateUser', array($uid, $password));
|
||||
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);
|
||||
$user = $this->getUserObject($uid, $backend);
|
||||
$this->emit('\OC\User', 'postCreateUser', array($user, $password));
|
||||
|
@ -264,7 +264,7 @@ class Manager extends PublicEmitter implements IUserManager {
|
|||
public function countUsers() {
|
||||
$userCountStatistics = array();
|
||||
foreach ($this->backends as $backend) {
|
||||
if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) {
|
||||
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
|
||||
$backendusers = $backend->countUsers();
|
||||
if($backendusers !== false) {
|
||||
if(isset($userCountStatistics[get_class($backend)])) {
|
||||
|
|
|
@ -90,7 +90,7 @@ class User implements IUser {
|
|||
public function getDisplayName() {
|
||||
if (!isset($this->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
|
||||
$backendDisplayName = $this->backend->getDisplayName($this->uid);
|
||||
if (is_string($backendDisplayName)) {
|
||||
|
@ -115,7 +115,7 @@ class User implements IUser {
|
|||
*/
|
||||
public function setDisplayName($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;
|
||||
$result = $this->backend->setDisplayName($this->uid, $displayName);
|
||||
return $result !== false;
|
||||
|
@ -170,7 +170,7 @@ class User implements IUser {
|
|||
if ($this->emitter) {
|
||||
$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);
|
||||
if ($this->emitter) {
|
||||
$this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
|
||||
|
@ -188,7 +188,7 @@ class User implements IUser {
|
|||
*/
|
||||
public function getHome() {
|
||||
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;
|
||||
} elseif ($this->config) {
|
||||
$this->home = $this->config->getSystemValue('datadirectory') . '/' . $this->uid;
|
||||
|
@ -205,7 +205,7 @@ class User implements IUser {
|
|||
* @return bool
|
||||
*/
|
||||
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 true;
|
||||
|
@ -217,7 +217,7 @@ class User implements IUser {
|
|||
* @return bool
|
||||
*/
|
||||
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 {
|
|||
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);
|
||||
return $this->backend->implementsActions(\OC_User_Backend::SET_DISPLAYNAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue