summaryrefslogtreecommitdiff
path: root/lib/Kolab
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-05-29 09:40:01 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-05-29 09:45:27 (GMT)
commit6ed619604322c1af128d7174b85088203e4798d0 (patch)
tree6902f3c5d21fe65d52ed496d3c278b56a0113a77 /lib/Kolab
parent7ac7e52d452cc82cfb9482de8b5ca842c5ee3f45 (diff)
downloadiRony-6ed619604322c1af128d7174b85088203e4798d0.tar.gz
Create user records in database - enables IMAP cache (Bug #1893)
Diffstat (limited to 'lib/Kolab')
-rw-r--r--lib/Kolab/DAV/Auth/HTTPBasic.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/Kolab/DAV/Auth/HTTPBasic.php b/lib/Kolab/DAV/Auth/HTTPBasic.php
index 3095119..e16c894 100644
--- a/lib/Kolab/DAV/Auth/HTTPBasic.php
+++ b/lib/Kolab/DAV/Auth/HTTPBasic.php
@@ -82,11 +82,39 @@ class HTTPBasic extends \Sabre\DAV\Auth\Backend\AbstractBasic
'pass' => $password,
));
+ // user already registered?
+ if ($user_object = rcube_user::query($auth['user'], $auth['host'])) {
+ $auth['user'] = $user_object->data['username'];
+ }
+
// authenticate user against the IMAP server
$imap = $rcube->get_storage();
$success = $imap->connect($auth['host'], $auth['user'], $auth['pass'], $port, $ssl);
if ($success) {
+ // No user in database, but IMAP auth works
+ if (!is_object($user_object)) {
+ if ($rcube->config->get('auto_create_user')) {
+ // create a new user record
+ $user_object = rcube_user::create($auth['user'], $auth['host']);
+
+ if (!$user_object) {
+ rcube::raise_error(array(
+ 'code' => 620, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Failed to create a user record",
+ ), true, false);
+ return false;
+ }
+ }
+ else {
+ rcube::raise_error(array(
+ 'code' => 620, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Access denied for new user $user. 'auto_create_user' is disabled",
+ ), true, false);
+ return false;
+ }
+ }
+
self::$current_user = $auth['user'];
self::$current_pass = $rcube->password = $password;
if (!$auth_user) {
@@ -94,7 +122,7 @@ class HTTPBasic extends \Sabre\DAV\Auth\Backend\AbstractBasic
}
// register a rcube_user object for global access
- $rcube->user = new rcube_user(null, array('username' => $auth['user'], 'mail_host' => $auth['host']));
+ $rcube->user = $user_object;
$_SESSION['imap_host'] = $auth['host'];
}