👌 IMPROVE: move group creation to imap class && check for two additional parameters wheter to stripe domain and create group based on domain or not
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
@@ -173,10 +173,8 @@ abstract class Base extends \OC\User\Backend{
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function storeUser($uid)
|
protected function storeUser($uid) {
|
||||||
{
|
|
||||||
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')
|
||||||
->values([
|
->values([
|
||||||
@@ -184,13 +182,7 @@ abstract class Base extends \OC\User\Backend{
|
|||||||
'backend' => $query->createNamedParameter($this->backend),
|
'backend' => $query->createNamedParameter($this->backend),
|
||||||
]);
|
]);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$pieces = explode('@',$uid,2);
|
|
||||||
if($pieces[1]) {
|
|
||||||
$createduser = \OC::$server->getUserManager()->get($uid);
|
|
||||||
\OC::$server->getGroupManager()->createGroup($pieces[1])->addUser($createduser);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
33
lib/imap.php
33
lib/imap.php
@@ -24,6 +24,8 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
private $port;
|
private $port;
|
||||||
private $sslmode;
|
private $sslmode;
|
||||||
private $domain;
|
private $domain;
|
||||||
|
private $stripeDomain;
|
||||||
|
private $groupDomain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new IMAP authentication provider
|
* Create new IMAP authentication provider
|
||||||
@@ -33,12 +35,14 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
* @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
|
||||||
*/
|
*/
|
||||||
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null) {
|
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) {
|
||||||
parent::__construct($mailbox);
|
parent::__construct($mailbox);
|
||||||
$this->mailbox = $mailbox;
|
$this->mailbox = $mailbox;
|
||||||
$this->port = $port === null ? 143 : $port;
|
$this->port = $port === null ? 143 : $port;
|
||||||
$this->sslmode = $sslmode;
|
$this->sslmode = $sslmode;
|
||||||
$this->domain= $domain === null ? '' : $domain;
|
$this->domain = $domain === null ? '' : $domain;
|
||||||
|
$this->stripeDomain = $stripeDomain;
|
||||||
|
$this->groupDomain = $groupDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,13 +60,15 @@ class OC_User_IMAP extends \OCA\user_external\Base {
|
|||||||
$uid = str_replace("%40","@",$uid);
|
$uid = str_replace("%40","@",$uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pieces = explode('@', $uid);
|
||||||
if ($this->domain !== '') {
|
if ($this->domain !== '') {
|
||||||
$pieces = explode('@', $uid);
|
|
||||||
if (count($pieces) === 1) {
|
if (count($pieces) === 1) {
|
||||||
$username = $uid . '@' . $this->domain;
|
$username = $uid . '@' . $this->domain;
|
||||||
} else if(count($pieces) === 2 && $pieces[1] === $this->domain) {
|
} else if(count($pieces) === 2 && $pieces[1] === $this->domain) {
|
||||||
$username = $uid;
|
$username = $uid;
|
||||||
$uid = $pieces[0];
|
if ($this->stripeDomain) {
|
||||||
|
$uid = $pieces[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -87,9 +93,26 @@ 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);
|
$this->storeUser($uid, $pieces[1]);
|
||||||
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($groupDomain && $group) {
|
||||||
|
$createduser = \OC::$server->getUserManager()->get($uid);
|
||||||
|
\OC::$server->getGroupManager()->createGroup($group)->addUser($createduser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user