Commit a33671a3 authored by Sven Greiner's avatar Sven Greiner
Browse files

Just copy & paste without testing

parent 2c761cce
...@@ -16,32 +16,36 @@ namespace OCA\user_wcf; ...@@ -16,32 +16,36 @@ namespace OCA\user_wcf;
* $wcfPath parameter. * $wcfPath parameter.
*/ */
class Group_WCF extends \OC_Group_Backend { class Group_WCF implements \OCP\GroupInterface {
protected $db; protected $db;
public function __construct() { public function __construct() {
require(\OC_App::getAppPath('user_wcf').'/config/config.php'); require(\OC_App::getAppPath('user_wcf').'/config/config.php');
if (!file_exists($wcfPath) || !is_dir($wcfPath)) throw new \Exception('Not a valid WCF path: "'.$wcfPath.'"'); if (!file_exists($wcfPath) || !is_dir($wcfPath)) throw new \Exception('Not a valid WCF path: "'.$wcfPath.'"');
$this->db = lib\WCF_DB::getInstance($wcfPath); $this->db = lib\WCF_DB::getInstance($wcfPath);
$this->db->setAuthorizedGroups($authorizedGroups); $this->db->setAuthorizedGroups($authorizedGroups);
} }
/** /**
* @brief Check if backend implements actions * Check if backend implements actions
* @param int $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* * @since 4.5.0
* Returns the supported actions as int to be *
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc. * Returns the supported actions as int to be
*/ * compared with \OC_Group_Backend::CREATE_GROUP etc.
public function getSupportedActions() { */
return OC_GROUP_BACKEND_GET_DISPLAYNAME; public function implementsActions($actions) {
return (bool)(GROUP_DETAILS
& $actions);
} }
/** /**
* @brief is user in group? * is user in group?
* @param string $uid uid of the user * @param string $uid uid of the user
* @param string $gid gid of the group * @param string $gid gid of the group
* @return bool * @return bool
* @since 4.5.0
* *
* Checks whether the user is member of a group or not. * Checks whether the user is member of a group or not.
*/ */
...@@ -59,9 +63,10 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -59,9 +63,10 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief Get all groups a user belongs to * Get all groups a user belongs to
* @param string $uid Name of the user * @param string $uid Name of the user
* @return array with group names * @return array an array of group names
* @since 4.5.0
* *
* This function fetches all groups a user belongs to. It does not check * This function fetches all groups a user belongs to. It does not check
* if the user exists at all. * if the user exists at all.
...@@ -80,15 +85,16 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -80,15 +85,16 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief get a list of all groups * get a list of all groups
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array with group names * @return array an array of group names
* @since 4.5.0
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public function getGroups($search = '', $limit=null, $offset=null) { public function getGroups($search = '', $limit = -1, $offset = 0) {
$groups = array(); $groups = array();
$params = array(); $params = array();
$where = NULL; $where = NULL;
...@@ -122,11 +128,12 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -122,11 +128,12 @@ class Group_WCF extends \OC_Group_Backend {
} }
return $groups; return $groups;
} }
/** /**
* check if a group exists * check if a group exists
* @param string $gid * @param string $gid
* @return bool * @return bool
* @since 4.5.0
*/ */
public function groupExists($gid) { public function groupExists($gid) {
$exists = FALSE; $exists = FALSE;
...@@ -140,12 +147,13 @@ class Group_WCF extends \OC_Group_Backend { ...@@ -140,12 +147,13 @@ class Group_WCF extends \OC_Group_Backend {
} }
/** /**
* @brief get a list of all users in a group * get a list of all users in a group
* @param string $gid * @param string $gid
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return array with user ids * @return array an array of user ids
* @since 4.5.0
*/ */
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$users = array(); $users = array();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace OCA\user_wcf; namespace OCA\user_wcf;
use OC\User\Backend;
/** /**
* This class authenticates users against a WCF database if they belong to * This class authenticates users against a WCF database if they belong to
...@@ -15,7 +16,7 @@ namespace OCA\user_wcf; ...@@ -15,7 +16,7 @@ namespace OCA\user_wcf;
* database configuration is imported from the WCF configuration file of * database configuration is imported from the WCF configuration file of
* the WCF installation given in the $wcfPath paramter. * the WCF installation given in the $wcfPath paramter.
*/ */
class User_WCF extends \OC_User_Backend { class User_WCF implements \OCP\IUserBackend, \OCP\UserInterface {
protected $authorizedGroups; protected $authorizedGroups;
protected $groupsCondition; protected $groupsCondition;
protected $db = NULL; protected $db = NULL;
...@@ -28,8 +29,127 @@ class User_WCF extends \OC_User_Backend { ...@@ -28,8 +29,127 @@ class User_WCF extends \OC_User_Backend {
$this->db->setAuthorizedGroups($authorizedGroups); $this->db->setAuthorizedGroups($authorizedGroups);
} }
public function getSupportedActions() { /**
return OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME; * Backend name to be shown in user management
* @return string the name of the backend to be shown
* @since 8.0.0
*/
public function getBackendName() {
return "WCF";
}
/**
* Check if backend implements 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.
* @since 4.5.0
*/
public function implementsActions($actions) {
return (bool)((Backend::CHECK_PASSWORD
| Backend::GET_DISPLAYNAME)
& $actions);
}
/**
* delete a user
* @param string $uid The username of the user to delete
* @return bool
* @since 4.5.0
* @todo
*/
public function deleteUser($uid);
/**
* Get a list of all users
*
* @param string $search
* @param null|int $limit
* @param null|int $offset
* @return string[] an array of all uids
* @since 4.5.0
*/
public function getUsers($search = '', $limit = null, $offset = null) {
$users = array();
$params = array();
$where = NULL;
$append = 'ORDER BY username';
if ($search !== '') {
$where = 'username LIKE ?';
$params[] = '%'.$search.'%';
}
if ($limit !== NULL) {
$append .= ' LIMIT '.intval($limit);
}
if ($offset !== NULL) {
$append .= ' OFFSET '.intval($offset);;
}
$result = $this->db->prepare('username', $where, $append);
if ($result !== FALSE and $result->execute($params)) {
if ($result->rowCount() <= 0) {
$this->warn('No users returned from database.');
}
foreach ($result as $row) {
$users[] = $row['username'];
}
$result->closeCursor();
}
else {
$this->warn('Error executing statement to get user list.');
}
return $users;
}
/**
* check if a user exists
* @param string $uid the username
* @return boolean
* @since 4.5.0
*/
public function userExists($uid) {
$exists = FALSE;
$result = $this->db->prepare('1', 'username=?');
if ($result !== FALSE and $result->execute(array($uid))) {
$exists = ($result->fetch() !== FALSE);
$result->closeCursor();
}
return $exists;
}
/**
* get display name of the user
* @param string $uid user ID of the user
* @return string display name
* @since 4.5.0
* @todo
*/
public function getDisplayName($uid);
/**
* Get a list of all display names and user ids.
*
* @param string $search
* @param string|null $limit
* @param string|null $offset
* @return array an array of all displayNames (value) and the corresponding uids (key)
* @since 4.5.0
* @todo
*/
public function getDisplayNames($search = '', $limit = null, $offset = null);
/**
* Check if a user list is available or not
* @return boolean if users can be listed or not
* @since 4.5.0
*/
public function hasUserListings() {
return true;
} }
/** /**
...@@ -73,51 +193,6 @@ class User_WCF extends \OC_User_Backend { ...@@ -73,51 +193,6 @@ class User_WCF extends \OC_User_Backend {
return $authenticatedAs; return $authenticatedAs;
} }
public function userExists($uid) {
$exists = FALSE;
$result = $this->db->prepare('1', 'username=?');
if ($result !== FALSE and $result->execute(array($uid))) {
$exists = ($result->fetch() !== FALSE);
$result->closeCursor();
}
return $exists;
}
public function getUsers($search='', $limit=null, $offset=null) {
$users = array();
$params = array();
$where = NULL;
$append = 'ORDER BY username';
if ($search !== '') {
$where = 'username LIKE ?';
$params[] = '%'.$search.'%';
}
if ($limit !== NULL) {
$append .= ' LIMIT '.intval($limit);
}
if ($offset !== NULL) {
$append .= ' OFFSET '.intval($offset);;
}
$result = $this->db->prepare('username', $where, $append);
if ($result !== FALSE and $result->execute($params)) {
if ($result->rowCount() <= 0) {
$this->warn('No users returned from database.');
}
foreach ($result as $row) {
$users[] = $row['username'];
}
$result->closeCursor();
}
else {
$this->warn('Error executing statement to get user list.');
}
return $users;
}
public static function info($text) { public static function info($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO); \OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO);
} }
...@@ -129,21 +204,4 @@ class User_WCF extends \OC_User_Backend { ...@@ -129,21 +204,4 @@ class User_WCF extends \OC_User_Backend {
public static function debug($text) { public static function debug($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG);
} }
/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
*/
public function getBackendName(){
return 'WCF';
}
/**
* Check if a user list is available or not
* @return boolean if users can be listed or not
*/
public function hasUserListings() {
return true;
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment