From 78259c85ef90c208669cdc357140152985f9fbcb Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 10 Jan 2013 12:02:19 +0100 Subject: [PATCH] fixed a bug in user add/edit if empty line among the email addresses --- webui/controller/user/add.php | 6 ++++-- webui/controller/user/edit.php | 7 +++++-- webui/model/user/user.php | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/webui/controller/user/add.php b/webui/controller/user/add.php index 3534b668..e9ae3108 100644 --- a/webui/controller/user/add.php +++ b/webui/controller/user/add.php @@ -103,12 +103,14 @@ class ControllerUserAdd extends Controller { $emails = explode("\n", $this->request->post['email']); foreach ($emails as $email) { $email = rtrim($email); + if($email == '') { continue; } + $ret = checkemail($email, $this->domains); if($ret == 0) { - $this->error['email'] = $this->data['text_invalid_email'] . ": $email"; + $this->error['email'] = $this->data['text_invalid_email'] . ": *$email*"; } else if($ret == -1) { - $this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": $email"; + $this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": *$email*"; } } } diff --git a/webui/controller/user/edit.php b/webui/controller/user/edit.php index f6b5d120..f31effed 100644 --- a/webui/controller/user/edit.php +++ b/webui/controller/user/edit.php @@ -117,12 +117,15 @@ class ControllerUserEdit extends Controller { $emails = explode("\n", $this->request->post['email']); foreach ($emails as $email) { $email = rtrim($email); + + if($email == '') { continue; } + $ret = checkemail($email, $this->domains); if($ret == 0) { - $this->error['email'] = $this->data['text_invalid_email'] . ": $email"; + $this->error['email'] = $this->data['text_invalid_email'] . ": *$email*"; } else if($ret == -1) { - $this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": $email"; + $this->error['email'] = $this->data['text_email_in_unknown_domain'] . ": *$email*"; } } } diff --git a/webui/model/user/user.php b/webui/model/user/user.php index d2a9b410..ddf7d9dc 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -314,6 +314,8 @@ class ModelUserUser extends Model { foreach ($emails as $email) { $email = rtrim($email); + if(validemail($email) == 0) { continue; } + $query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_EMAIL . " WHERE email=?", array($email)); /* remove from memcached */ @@ -346,6 +348,8 @@ class ModelUserUser extends Model { foreach ($emails as $email) { $email = rtrim($email); + if(validemail($email) == 0) { continue; } + $ret = $this->add_email((int)$user['uid'], $email); if($ret == 0) { return -2; } } @@ -391,6 +395,8 @@ class ModelUserUser extends Model { foreach ($emails as $email) { $email = rtrim($email); + if(validemail($email) == 0) { continue; } + $query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_EMAIL . " WHERE uid!=? AND email=?", array((int)$user['uid'], $email)); if($query->row['count'] > 0) { @@ -417,6 +423,9 @@ class ModelUserUser extends Model { foreach ($emails as $email) { $email = rtrim($email); + + if(validemail($email) == 0) { continue; } + $query = $this->db->query("INSERT INTO " . TABLE_EMAIL . " (uid, email) VALUES(?,?)", array((int)$user['uid'], $email)); /* remove from memcached */