diff --git a/lib/base.php b/lib/base.php index a6c5f89..cbf144c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -173,10 +173,8 @@ public function setDisplayName($uid, $displayName) { * * @return void */ - protected function storeUser($uid) - { + protected function storeUser($uid) { if (!$this->userExists($uid)) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $query->insert('users_external') ->values([ @@ -184,13 +182,7 @@ protected function storeUser($uid) 'backend' => $query->createNamedParameter($this->backend), ]); $query->execute(); - $pieces = explode('@',$uid,2); - if($pieces[1]) { - $createduser = \OC::$server->getUserManager()->get($uid); - \OC::$server->getGroupManager()->createGroup($pieces[1])->addUser($createduser); - } } - } /** diff --git a/lib/imap.php b/lib/imap.php index 7b17ed7..e170e85 100644 --- a/lib/imap.php +++ b/lib/imap.php @@ -24,6 +24,8 @@ class OC_User_IMAP extends \OCA\user_external\Base { private $port; private $sslmode; private $domain; + private $stripeDomain; + private $groupDomain; /** * Create new IMAP authentication provider @@ -33,12 +35,14 @@ class OC_User_IMAP extends \OCA\user_external\Base { * @param string $sslmode * @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); $this->mailbox = $mailbox; $this->port = $port === null ? 143 : $port; $this->sslmode = $sslmode; - $this->domain= $domain === null ? '' : $domain; + $this->domain = $domain === null ? '' : $domain; + $this->stripeDomain = $stripeDomain; + $this->groupDomain = $groupDomain; } /** @@ -56,13 +60,15 @@ public function checkPassword($uid, $password) { $uid = str_replace("%40","@",$uid); } + $pieces = explode('@', $uid); if ($this->domain !== '') { - $pieces = explode('@', $uid); if (count($pieces) === 1) { $username = $uid . '@' . $this->domain; } else if(count($pieces) === 2 && $pieces[1] === $this->domain) { $username = $uid; - $uid = $pieces[0]; + if ($this->stripeDomain) { + $uid = $pieces[0]; + } } else { return false; } @@ -86,9 +92,26 @@ public function checkPassword($uid, $password) { if($canconnect) { $uid = mb_strtolower($uid); - $this->storeUser($uid); + $this->storeUser($uid, $pieces[1]); return $uid; } 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); + } + } + } }