From f879f4e2f8c81f67b0a0c471c94ebed686939c49 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Thu, 14 May 2009 15:26:34 -0400 Subject: [PATCH] Trigger 'create_identity' when creating a new user; Allow 'create_user' hook to abort the operation --- program/include/rcube_user.php | 35 ++++++++++++++++++++++++----------- 1 files changed, 24 insertions(+), 11 deletions(-) diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php index 9d5cc5f..da819c7 100644 --- a/program/include/rcube_user.php +++ b/program/include/rcube_user.php @@ -353,6 +353,10 @@ $data = $rcmail->plugins->exec_hook('create_user', array('user'=>$user, 'user_name'=>$user_name, 'user_email'=>$user_email)); $user_name = $data['user_name']; $user_email = $data['user_email']; + + // plugin aborted this operation + if ($data['abort']) + return false; $dbh = $rcmail->get_dbh(); @@ -392,14 +396,23 @@ // create new identities records $standard = 1; foreach ($email_list as $email) { - $dbh->query( - "INSERT INTO ".get_table_name('identities')." - (user_id, del, standard, name, email) - VALUES (?, 0, ?, ?, ?)", - $user_id, - $standard, - strip_newlines($user_name), - preg_replace('/^@/', $user . '@', $email)); + $plugin = $RCMAIL->plugins->exec_hook('create_identity', array('record' => array( + 'login' => true, + 'user_id' => $user_id, + 'name' => strip_newlines($user_name), + 'email' => $email, + 'standard' => $standard))); + + if (!$plugin['abort'] && $plugin['record']['name'] && $plugin['record']['email']) { + $dbh->query( + "INSERT INTO ".get_table_name('identities')." + (user_id, del, standard, name, email) + VALUES (?, 0, ?, ?, ?)", + $user_id, + $plugin['record']['standard'], + $plugin['record']['name'], + $plugin['record']['email']); + } $standard = 0; } } @@ -425,7 +438,7 @@ */ static function email2user($email) { - $r = self::findinvirtual('^' . quotemeta($email) . '[[:space:]]'); + $r = self::findinvirtual('/^' . preg_quote($email, '/') . '\s/'); for ($i=0; $i<count($r); $i++) { @@ -463,7 +476,7 @@ } } // File lookup - $r = self::findinvirtual('[[:space:]]' . quotemeta($user) . '[[:space:]]*$'); + $r = self::findinvirtual('/\s' . preg_quote($user, '/') . '\s*$/'); for ($i=0; $i<count($r); $i++) { $data = $r[$i]; @@ -505,7 +518,7 @@ if (empty($line) || $line{0}=='#') continue; - if (eregi($pattern, $line)) + if (preg_match($pattern, $line)) $result[] = $line; } -- Gitblit v1.9.1