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

Just copy & paste without testing

parent 2c761cce
......@@ -16,7 +16,7 @@ namespace OCA\user_wcf;
* $wcfPath parameter.
*/
class Group_WCF extends \OC_Group_Backend {
class Group_WCF implements \OCP\GroupInterface {
protected $db;
public function __construct() {
......@@ -25,23 +25,27 @@ class Group_WCF extends \OC_Group_Backend {
$this->db = lib\WCF_DB::getInstance($wcfPath);
$this->db->setAuthorizedGroups($authorizedGroups);
}
/**
* @brief Check if backend implements actions
* Check if backend implements actions
* @param int $actions bitwise-or'ed actions
* @return boolean
* @since 4.5.0
*
* Returns the supported actions as int to be
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
* 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 $gid gid of the group
* @return bool
* @since 4.5.0
*
* Checks whether the user is member of a group or not.
*/
......@@ -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
* @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
* if the user exists at all.
......@@ -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 int $limit
* @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
*/
public function getGroups($search = '', $limit=null, $offset=null) {
public function getGroups($search = '', $limit = -1, $offset = 0) {
$groups = array();
$params = array();
$where = NULL;
......@@ -127,6 +133,7 @@ class Group_WCF extends \OC_Group_Backend {
* check if a group exists
* @param string $gid
* @return bool
* @since 4.5.0
*/
public function groupExists($gid) {
$exists = FALSE;
......@@ -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 $search
* @param int $limit
* @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) {
$users = array();
......
......@@ -8,6 +8,7 @@
namespace OCA\user_wcf;
use OC\User\Backend;
/**
* This class authenticates users against a WCF database if they belong to
......@@ -15,7 +16,7 @@ namespace OCA\user_wcf;
* database configuration is imported from the WCF configuration file of
* 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 $groupsCondition;
protected $db = NULL;
......@@ -28,63 +29,49 @@ class User_WCF extends \OC_User_Backend {
$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";
}
/**
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns string
* Check if backend implements actions
* @param int $actions bitwise-or'ed actions
* @return boolean
*
* Check if the password is correct without logging in the user
* returns the user id or false
* Returns the supported actions as int to be
* compared with \OC_User_Backend::CREATE_USER etc.
* @since 4.5.0
*/
public function checkPassword($uid, $password) {
$authenticatedAs = FALSE;
$where = 'LOWER(username)=LOWER(?)';
$result = $this->db->prepare('username, password, salt', $where);
if ($result !== FALSE and $result->execute(array($uid))) {
if (($row = $result->fetch()) !== FALSE) {
$doubleSalted = lib\StringUtil::getDoubleSaltedHash(
$password, $row['salt']);
if ($doubleSalted === $row['password']) {
$authenticatedAs = $row['username'];
$this->debug('User "'.$authenticatedAs.
'" logged in successfully.');
}
else {
$this->info('Invalid password for user '.$uid.'.');
}
}
else {
$this->info('User '.$uid.' is not in any authorized group.');
}
$result->closeCursor();
}
else {
$this->warn('Error while checking password for user '.$uid);
public function implementsActions($actions) {
return (bool)((Backend::CHECK_PASSWORD
| Backend::GET_DISPLAYNAME)
& $actions);
}
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;
}
/**
* delete a user
* @param string $uid The username of the user to delete
* @return bool
* @since 4.5.0
* @todo
*/
public function deleteUser($uid);
public function getUsers($search='', $limit=null, $offset=null) {
/**
* 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;
......@@ -118,32 +105,103 @@ class User_WCF extends \OC_User_Backend {
return $users;
}
public static function info($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO);
}
/**
* 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=?');
public static function warn($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::WARN);
if ($result !== FALSE and $result->execute(array($uid))) {
$exists = ($result->fetch() !== FALSE);
$result->closeCursor();
}
public static function debug($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG);
return $exists;
}
/**
* Backend name to be shown in user management
* @return string the name of the backend to be shown
* 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 getBackendName(){
return 'WCF';
}
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;
}
/**
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns string
*
* Check if the password is correct without logging in the user
* returns the user id or false
*/
public function checkPassword($uid, $password) {
$authenticatedAs = FALSE;
$where = 'LOWER(username)=LOWER(?)';
$result = $this->db->prepare('username, password, salt', $where);
if ($result !== FALSE and $result->execute(array($uid))) {
if (($row = $result->fetch()) !== FALSE) {
$doubleSalted = lib\StringUtil::getDoubleSaltedHash(
$password, $row['salt']);
if ($doubleSalted === $row['password']) {
$authenticatedAs = $row['username'];
$this->debug('User "'.$authenticatedAs.
'" logged in successfully.');
}
else {
$this->info('Invalid password for user '.$uid.'.');
}
}
else {
$this->info('User '.$uid.' is not in any authorized group.');
}
$result->closeCursor();
}
else {
$this->warn('Error while checking password for user '.$uid);
}
return $authenticatedAs;
}
public static function info($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::INFO);
}
public static function warn($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::WARN);
}
public static function debug($text) {
\OCP\Util::writeLog('user_wcf', $text, \OCP\Util::DEBUG);
}
}
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