👌 IMPROVE: make it possible to add the user to an array of groups (for later extendability e.g. #69)
Signed-off-by: Jonas Sulzer <jonas@violoncello.ch> Signed-off-by: none <vlad@teksperts.nyc>
This commit is contained in:
10
lib/base.php
10
lib/base.php
@@ -170,10 +170,11 @@ abstract class Base extends \OC\User\Backend{
|
|||||||
* Create user record in database
|
* Create user record in database
|
||||||
*
|
*
|
||||||
* @param string $uid The username
|
* @param string $uid The username
|
||||||
|
* @param array $groups Groups to add the user to on creation
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function storeUser($uid) {
|
protected function storeUser($uid, $groups) {
|
||||||
if (!$this->userExists($uid)) {
|
if (!$this->userExists($uid)) {
|
||||||
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||||
$query->insert('users_external')
|
$query->insert('users_external')
|
||||||
@@ -182,6 +183,13 @@ abstract class Base extends \OC\User\Backend{
|
|||||||
'backend' => $query->createNamedParameter($this->backend),
|
'backend' => $query->createNamedParameter($this->backend),
|
||||||
]);
|
]);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
|
if ($groups) {
|
||||||
|
$createduser = \OC::$server->getUserManager()->get($uid);
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
\OC::$server->getGroupManager()->createGroup($group)->addUser($createduser);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
lib/imap.php
27
lib/imap.php
@@ -31,9 +31,11 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
* Create new IMAP authentication provider
|
* Create new IMAP authentication provider
|
||||||
*
|
*
|
||||||
* @param string $mailbox IMAP server domain/IP
|
* @param string $mailbox IMAP server domain/IP
|
||||||
* @param string $port IMAP server $port
|
* @param int $port IMAP server $port
|
||||||
* @param string $sslmode
|
* @param string $sslmode
|
||||||
* @param string $domain If provided, loging will be restricted to this domain
|
* @param string $domain If provided, loging will be restricted to this domain
|
||||||
|
* @param boolean $stripeDomain (whether to stripe the domain part from the username or not)
|
||||||
|
* @param boolean $groupDomain (whether to add the usere to a group corresponding to the domain of the address)
|
||||||
*/
|
*/
|
||||||
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) {
|
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) {
|
||||||
parent::__construct($mailbox);
|
parent::__construct($mailbox);
|
||||||
@@ -76,6 +78,10 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
$username = $uid;
|
$username = $uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->groupDomain && $pieces[1]) {
|
||||||
|
$groups[] = $pieces[1];
|
||||||
|
}
|
||||||
|
|
||||||
$rcube = new imap_rcube();
|
$rcube = new imap_rcube();
|
||||||
|
|
||||||
$params = ["port"=>$this->port, "timeout"=>10];
|
$params = ["port"=>$this->port, "timeout"=>10];
|
||||||
@@ -93,26 +99,9 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
if($canconnect) {
|
if($canconnect) {
|
||||||
$rcube->closeConnection();
|
$rcube->closeConnection();
|
||||||
$uid = mb_strtolower($uid);
|
$uid = mb_strtolower($uid);
|
||||||
$this->storeUser($uid, $pieces[1]);
|
$this->storeUser($uid, $groups);
|
||||||
return $uid;
|
return $uid;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function storeUser($uid, $group) {
|
|
||||||
if (!$this->userExists($uid)) {
|
|
||||||
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
|
||||||
$query->insert('users_external')
|
|
||||||
->values([
|
|
||||||
'uid' => $query->createNamedParameter($uid),
|
|
||||||
'backend' => $query->createNamedParameter($this->backend),
|
|
||||||
]);
|
|
||||||
$query->execute();
|
|
||||||
|
|
||||||
if($this->groupDomain && $group) {
|
|
||||||
$createduser = \OC::$server->getUserManager()->get($uid);
|
|
||||||
\OC::$server->getGroupManager()->createGroup($group)->addUser($createduser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user