diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | SQL/mssql.initial.sql | 7 | ||||
-rw-r--r-- | SQL/mssql.upgrade.sql | 9 | ||||
-rw-r--r-- | SQL/mysql.initial.sql | 7 | ||||
-rw-r--r-- | SQL/mysql.update.sql | 4 | ||||
-rw-r--r-- | SQL/postgres.initial.sql | 4 | ||||
-rw-r--r-- | SQL/postgres.update.sql | 3 | ||||
-rw-r--r-- | SQL/sqlite.initial.sql | 3 | ||||
-rw-r--r-- | SQL/sqlite.update.sql | 32 | ||||
-rw-r--r-- | config/main.inc.php.dist | 3 | ||||
-rw-r--r-- | program/include/rcube_user.php | 19 |
11 files changed, 72 insertions, 21 deletions
@@ -1,6 +1,8 @@ CHANGELOG Roundcube Webmail =========================== +- Removed users.alias column, added option ('user_aliases') + to use email address from identities as username (#1488581) - Removed redundant cache.cache_id column (#1488528) - Fix order of attachments in sent mail (#1488423) - Don't show product version on login screen (can be enabled by config) diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql index 9aa6e6321..85b8e4ef6 100644 --- a/SQL/mssql.initial.sql +++ b/SQL/mssql.initial.sql @@ -92,7 +92,6 @@ CREATE TABLE [dbo].[users] ( [user_id] [int] IDENTITY (1, 1) NOT NULL ,
[username] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
[mail_host] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
- [alias] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
[created] [datetime] NOT NULL ,
[last_login] [datetime] NULL ,
[language] [varchar] (5) COLLATE Latin1_General_CI_AI NULL ,
@@ -274,6 +273,8 @@ GO CREATE INDEX [IX_identities_user_id] ON [dbo].[identities]([user_id]) ON [PRIMARY]
GO
+CREATE INDEX [IX_identities_email] ON [dbo].[identities]([email],[del]) ON [PRIMARY]
+GO
ALTER TABLE [dbo].[session] ADD
CONSTRAINT [DF_session_sess_id] DEFAULT ('') FOR [sess_id],
@@ -287,16 +288,12 @@ GO ALTER TABLE [dbo].[users] ADD
CONSTRAINT [DF_users_username] DEFAULT ('') FOR [username],
CONSTRAINT [DF_users_mail_host] DEFAULT ('') FOR [mail_host],
- CONSTRAINT [DF_users_alias] DEFAULT ('') FOR [alias],
CONSTRAINT [DF_users_created] DEFAULT (getdate()) FOR [created]
GO
CREATE UNIQUE INDEX [IX_users_username] ON [dbo].[users]([username],[mail_host]) ON [PRIMARY]
GO
-CREATE INDEX [IX_users_alias] ON [dbo].[users]([alias]) ON [PRIMARY]
-GO
-
CREATE UNIQUE INDEX [IX_dictionary_user_language] ON [dbo].[dictionary]([user_id],[language]) ON [PRIMARY]
GO
diff --git a/SQL/mssql.upgrade.sql b/SQL/mssql.upgrade.sql index d111ef3e7..26001e713 100644 --- a/SQL/mssql.upgrade.sql +++ b/SQL/mssql.upgrade.sql @@ -261,4 +261,13 @@ ALTER TABLE [dbo].[contacts] ALTER COLUMN [email] [varchar] (8000) COLLATE Latin GO
ALTER TABLE [dbo].[contacts] ADD CONSTRAINT [DF_contacts_email] DEFAULT ('') FOR [email]
GO
+
+-- Updates from version 0.8
+
+ALTER TABLE [dbo].[cache] DROP COLUMN [cache_id]
+GO
+ALTER TABLE [dbo].[users] DROP COLUMN [alias]
+GO
+CREATE INDEX [IX_identities_email] ON [dbo].[identities]([email],[del]) ON [PRIMARY]
+GO
\ No newline at end of file diff --git a/SQL/mysql.initial.sql b/SQL/mysql.initial.sql index 46fa2c3cf..47d9db4a2 100644 --- a/SQL/mysql.initial.sql +++ b/SQL/mysql.initial.sql @@ -22,14 +22,12 @@ CREATE TABLE `users` ( `user_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, `username` varchar(128) BINARY NOT NULL, `mail_host` varchar(128) NOT NULL, - `alias` varchar(128) BINARY NOT NULL, `created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `last_login` datetime DEFAULT NULL, `language` varchar(5), `preferences` text, PRIMARY KEY(`user_id`), - UNIQUE `username` (`username`, `mail_host`), - INDEX `alias_index` (`alias`) + UNIQUE `username` (`username`, `mail_host`) ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; @@ -156,7 +154,8 @@ CREATE TABLE `identities` ( PRIMARY KEY(`identity_id`), CONSTRAINT `user_id_fk_identities` FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, - INDEX `user_identities_index` (`user_id`, `del`) + INDEX `user_identities_index` (`user_id`, `del`), + INDEX `email_identities_index` (`email`, `del`) ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; diff --git a/SQL/mysql.update.sql b/SQL/mysql.update.sql index 3be65897d..237aa3e38 100644 --- a/SQL/mysql.update.sql +++ b/SQL/mysql.update.sql @@ -242,4 +242,6 @@ ALTER TABLE `searches` ALTER `user_id` DROP DEFAULT; -- Updates from version 0.8 -ALTER TABLE cache DROP COLUMN cache_id; +ALTER TABLE `cache` DROP COLUMN `cache_id`; +ALTER TABLE `users` DROP COLUMN `alias`; +ALTER TABLE `identities` ADD INDEX `email_identities_index` (`email`, `del`); diff --git a/SQL/postgres.initial.sql b/SQL/postgres.initial.sql index a47bec2ca..f7b2d96d9 100644 --- a/SQL/postgres.initial.sql +++ b/SQL/postgres.initial.sql @@ -20,7 +20,6 @@ CREATE TABLE users ( user_id integer DEFAULT nextval('user_ids'::text) PRIMARY KEY, username varchar(128) DEFAULT '' NOT NULL, mail_host varchar(128) DEFAULT '' NOT NULL, - alias varchar(128) DEFAULT '' NOT NULL, created timestamp with time zone DEFAULT now() NOT NULL, last_login timestamp with time zone DEFAULT NULL, "language" varchar(5), @@ -28,9 +27,7 @@ CREATE TABLE users ( CONSTRAINT users_username_key UNIQUE (username, mail_host) ); -CREATE INDEX users_alias_id_idx ON users (alias); - -- -- Table "session" -- Name: session; Type: TABLE; Schema: public; Owner: postgres @@ -81,6 +78,7 @@ CREATE TABLE identities ( ); CREATE INDEX identities_user_id_idx ON identities (user_id, del); +CREATE INDEX identities_email_idx ON identities (email, del); -- diff --git a/SQL/postgres.update.sql b/SQL/postgres.update.sql index a8a9cdda8..11ab93bfc 100644 --- a/SQL/postgres.update.sql +++ b/SQL/postgres.update.sql @@ -180,3 +180,6 @@ ALTER TABLE contacts ALTER email TYPE text; ALTER TABLE cache DROP COLUMN cache_id; DROP SEQUENCE cache_ids; + +ALTER TABLE users DROP COLUMN alias; +CREATE INDEX identities_email_idx ON identities (email, del); diff --git a/SQL/sqlite.initial.sql b/SQL/sqlite.initial.sql index a3c38b939..f5b5615d8 100644 --- a/SQL/sqlite.initial.sql +++ b/SQL/sqlite.initial.sql @@ -80,6 +80,7 @@ CREATE TABLE identities ( ); CREATE INDEX ix_identities_user_id ON identities(user_id, del); +CREATE INDEX ix_identities_email ON identities(email, del); -- -------------------------------------------------------- @@ -92,7 +93,6 @@ CREATE TABLE users ( user_id integer NOT NULL PRIMARY KEY, username varchar(128) NOT NULL default '', mail_host varchar(128) NOT NULL default '', - alias varchar(128) NOT NULL default '', created datetime NOT NULL default '0000-00-00 00:00:00', last_login datetime DEFAULT NULL, language varchar(5), @@ -100,7 +100,6 @@ CREATE TABLE users ( ); CREATE UNIQUE INDEX ix_users_username ON users(username, mail_host); -CREATE INDEX ix_users_alias ON users(alias); -- -------------------------------------------------------- diff --git a/SQL/sqlite.update.sql b/SQL/sqlite.update.sql index ddadde3ea..72a29e9ae 100644 --- a/SQL/sqlite.update.sql +++ b/SQL/sqlite.update.sql @@ -346,3 +346,35 @@ CREATE TABLE cache ( CREATE INDEX ix_cache_user_cache_key ON cache(user_id, cache_key); CREATE INDEX ix_cache_created ON cache(created); + +CREATE TABLE tmp_users ( + user_id integer NOT NULL PRIMARY KEY, + username varchar(128) NOT NULL default '', + mail_host varchar(128) NOT NULL default '', + created datetime NOT NULL default '0000-00-00 00:00:00', + last_login datetime DEFAULT NULL, + language varchar(5), + preferences text NOT NULL default '' +); + +INSERT INTO tmp_users (user_id, username, mail_host, created, last_login, language, preferences) + SELECT user_id, username, mail_host, created, last_login, language, preferences FROM users; + +DROP TABLE users; + +CREATE TABLE users ( + user_id integer NOT NULL PRIMARY KEY, + username varchar(128) NOT NULL default '', + mail_host varchar(128) NOT NULL default '', + created datetime NOT NULL default '0000-00-00 00:00:00', + last_login datetime DEFAULT NULL, + language varchar(5), + preferences text NOT NULL default '' +); + +INSERT INTO users (user_id, username, mail_host, created, last_login, language, preferences) + SELECT user_id, username, mail_host, created, last_login, language, preferences FROM tmp_users; + +CREATE UNIQUE INDEX ix_users_username ON users(username, mail_host); + +CREATE INDEX ix_identities_email ON identities(email, del); diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist index 8f69ca384..58e59ae6e 100644 --- a/config/main.inc.php.dist +++ b/config/main.inc.php.dist @@ -195,6 +195,9 @@ $rcmail_config['skin_logo'] = null; // set to false if only registered users can use this service $rcmail_config['auto_create_user'] = true; +// Enables possibility to log in using email address from user identities +$rcmail_config['user_aliases'] = false; + // use this folder to store log files (must be writeable for apache user) // This is used by the 'file' log driver. $rcmail_config['log_dir'] = 'logs/'; diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php index 24ded3d2d..d5421526b 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); } |