summaryrefslogtreecommitdiff
path: root/program/include/rcube_user.php
diff options
context:
space:
mode:
Diffstat (limited to 'program/include/rcube_user.php')
-rw-r--r--program/include/rcube_user.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index 1a54b91a2..644d24bd9 100644
--- a/program/include/rcube_user.php
+++ b/program/include/rcube_user.php
@@ -397,15 +397,22 @@ class rcube_user
*/
static function query($user, $host)
{
- $dbh = rcube::get_instance()->get_dbh();
+ $dbh = rcube::get_instance()->get_dbh();
+ $config = rcube::get_instance()->config;
// query for matching user name
- $query = "SELECT * FROM ".$dbh->table_name('users')." WHERE mail_host = ? AND %s = ?";
- $sql_result = $dbh->query(sprintf($query, 'username'), $host, $user);
+ $sql_result = $dbh->query("SELECT * FROM " . $dbh->table_name('users')
+ ." WHERE mail_host = ? AND username = ?", $host, $user);
+
+ $sql_arr = $dbh->fetch_assoc($sql_result);
+
+ // username not found, try aliases from identities
+ if (empty($sql_arr) && $config->get('user_aliases') && strpos($user, '@')) {
+ $sql_result = $dbh->limitquery("SELECT u.*"
+ ." FROM " . $dbh->table_name('users') . " u"
+ ." JOIN " . $dbh->table_name('identities') . " i ON (i.user_id = u.user_id)"
+ ." WHERE email = ? AND del <> 1", 0, 1, $user);
- // query for matching alias
- if (!($sql_arr = $dbh->fetch_assoc($sql_result))) {
- $sql_result = $dbh->query(sprintf($query, 'alias'), $host, $user);
$sql_arr = $dbh->fetch_assoc($sql_result);
}
@@ -449,11 +456,10 @@ class rcube_user
$dbh->query(
"INSERT INTO ".$dbh->table_name('users').
- " (created, last_login, username, mail_host, alias, language)".
- " VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?, ?)",
+ " (created, last_login, username, mail_host, language)".
+ " VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?)",
strip_newlines($user),
strip_newlines($host),
- strip_newlines($data['alias'] ? $data['alias'] : $user_email),
strip_newlines($data['language'] ? $data['language'] : $_SESSION['language']));
if ($user_id = $dbh->insert_id('users')) {
@@ -479,23 +485,23 @@ class rcube_user
// create new identities records
$standard = 1;
foreach ($email_list as $row) {
- $record = array();
+ $record = array();
if (is_array($row)) {
- $record = $row;
+ $record = $row;
}
else {
$record['email'] = $row;
}
- if (empty($record['name']))
- $record['name'] = $user_name;
+ if (empty($record['name']))
+ $record['name'] = $user_name;
$record['name'] = strip_newlines($record['name']);
$record['user_id'] = $user_id;
$record['standard'] = $standard;
$plugin = $rcube->plugins->exec_hook('identity_create',
- array('login' => true, 'record' => $record));
+ array('login' => true, 'record' => $record));
if (!$plugin['abort'] && $plugin['record']['email']) {
$rcube->user->insert_identity($plugin['record']);