diff --git a/group_sql.php b/group_sql.php new file mode 100644 index 0000000..641beff --- /dev/null +++ b/group_sql.php @@ -0,0 +1,79 @@ + helper = new \OCA\user_sql\lib\Helper(); + $domain = \OC::$server->getRequest()->getServerHost(); + $this -> settings = $this -> helper -> loadSettingsForDomain($domain); + $this -> helper -> connectToDb($this -> settings); + return false; + } + + public function getUserGroups($uid) { + if(empty($this -> settings['sql_group_table'])) + { + \OCP\Util::writeLog('OC_USER_SQL', "Group table not configured", \OCP\Util::DEBUG); + return []; + } + $rows = $this -> helper -> runQuery('getUserGroups', array('uid' => $uid), false, true); + if($rows === false) + { + \OCP\Util::writeLog('OC_USER_SQL', "Found no group", \OCP\Util::DEBUG); + return []; + } + $groups = array(); + foreach($rows as $row) + { + $groups[] = $row[$this -> settings['col_group_name']]; + } + return $groups; + } + + public function getGroups($search = '', $limit = null, $offset = null) { + if(empty($this -> settings['sql_group_table'])) + { + return []; + } + $rows = $this -> helper -> runQuery('getGroups', array(), false, true); + if($rows === false) + { + return []; + } + $groups = array(); + foreach($rows as $row) + { + $groups[] = $row[$this -> settings['col_group_name']]; + } + return $groups; + } + + public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { + if(empty($this -> settings['sql_group_table'])) + { + \OCP\Util::writeLog('OC_USER_SQL', "Group table not configured", \OCP\Util::DEBUG); + return []; + } + $rows = $this -> helper -> runQuery('getGroupUsers', array('gid' => $gid), false, true); + if($rows === false) + { + \OCP\Util::writeLog('OC_USER_SQL', "Found no users for group", \OCP\Util::DEBUG); + return []; + } + $users = array(); + foreach($rows as $row) + { + $users[] = $row[$this -> settings['col_group_username']]; + } + return $users; + } +} +?> diff --git a/user_sql.php b/user_sql.php index 9283c66..f824a8d 100644 --- a/user_sql.php +++ b/user_sql.php @@ -31,7 +31,13 @@ namespace OCA\user_sql; use \OCA\user_sql\lib\Helper; -class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\UserInterface +if(!interface_exists('OCP\\User\\IProvidesEMailBackend')) +{ + // hack for nextcloud + eval("namespace OCP\User; interface IProvidesEMailBackend {}"); +} + +class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\UserInterface, \OCP\User\IProvidesEMailBackend { protected $cache; protected $settings; @@ -116,6 +122,15 @@ class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\Us return true; } + /** + * Only used by OwnCloud to get the email address + */ + public function getEMailAddress($uid) { + $this->doEmailSync($uid); + $email = $this->ocConfig->getUserValue($uid, 'settings', 'email', ''); + return $email; + } + /** * This maps the username to the specified domain name. * It can only append a default domain name.