Rename plugin as it does not depend on virtuser_query and update config strings

This commit is contained in:
Alice Gaudon 2019-06-01 16:15:49 +02:00
parent 23fcd9cb96
commit 53b951a3b6
3 changed files with 15 additions and 14 deletions

View File

@ -1,7 +1,7 @@
{
"name": "arisuongaku/virtuser_identity_autoupdate",
"name": "arisuongaku/identity_db",
"type": "roundcube-plugin",
"description": "Updates user's identities on login based on aliases from virtuser_query. Update rules are configurable.",
"description": "Updates user's identities on login based on a database query. Some update rules are configurable.",
"license": "MIT",
"version": "0.1",
"authors": [

View File

@ -1,15 +1,18 @@
<?php
$conf = $config['virtuser_identity_autoupdate'] = array();
$conf = array();
// Enables (true) or disables (false) the plugin
$conf['update_on_login'] = true;
// Remove identities for which the email address is unknown for this user
$conf['remove_unknown_alias_identities'] = true;
$conf['remove_unknown_identities'] = true;
// Connection to the database which holds user aliases information
$conf['dsn'] = '';
// Query all aliases for a given user. '%u' will be replaced with the username.
// Example : SELECT aliases.email FROM aliases LEFT JOIN users ON aliases.user_id=users.id WHERE users.name="%u"
$conf['user_aliases_query'] = '';
$conf['identities_query'] = '';
// Finally register to the global config
$config['identity_db'] = $conf;

View File

@ -1,15 +1,13 @@
<?php
/**
* Virtuser Identity Auto Update
* Identity DB
*
* Updates user's identities on each login
* Updates user's identities on each login from a database request
*
* This plugin requires virtuser_query to work.
*
* @author Alice Gaudon
* @license MIT
*/
class virtuser_identities_autoupdate extends rcube_plugin
class identity_db extends rcube_plugin
{
private $rc;
private $config;
@ -19,7 +17,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
{
$this->rc = rcmail::get_instance();
$this->load_config();
$this->config = $this->rc->config->get('virtuser_identity_autoupdate');
$this->config = $this->rc->config->get('identity_db');
$this->add_hook('login_after', array($this, 'login_after'));
}
@ -36,7 +34,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
$target_identities = $this->fetch_aliases($user->data['username']);
// If enabled, remove unknown identities
if ($this->config['remove_unknown_alias_identities']) {
if ($this->config['remove_unknown_identities']) {
foreach ($current_identities as $existing_identity) {
if (!in_array($existing_identity['email'], $target_identities)) {
// Remove
@ -76,7 +74,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
));
if (!$hook_result['abort'] && $hook_result['record']['email']) {
$insert_result = $user->insert_identity($hook_result['record']);
$user->insert_identity($hook_result['record']);
}
}
@ -88,7 +86,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
$dbh = $this->get_dbh();
$result = $dbh->query(preg_replace('/%u/', $dbh->escape($username), $this->config['user_aliases_query']));
$result = $dbh->query(preg_replace('/%u/', $dbh->escape($username), $this->config['identities_query']));
while ($row = $dbh->fetch_array($result)) {
array_push($aliases, $row[0]);