fixed a bug in user add/edit if empty line among the email addresses

This commit is contained in:
SJ 2013-01-10 12:02:19 +01:00
parent 654a5700fa
commit 78259c85ef
3 changed files with 18 additions and 4 deletions

View File

@ -103,12 +103,14 @@ class ControllerUserAdd extends Controller {
$emails = explode("\n", $this->request->post['email']); $emails = explode("\n", $this->request->post['email']);
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if($email == '') { continue; }
$ret = checkemail($email, $this->domains); $ret = checkemail($email, $this->domains);
if($ret == 0) { 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) { 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*";
} }
} }
} }

View File

@ -117,12 +117,15 @@ class ControllerUserEdit extends Controller {
$emails = explode("\n", $this->request->post['email']); $emails = explode("\n", $this->request->post['email']);
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if($email == '') { continue; }
$ret = checkemail($email, $this->domains); $ret = checkemail($email, $this->domains);
if($ret == 0) { 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) { 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*";
} }
} }
} }

View File

@ -314,6 +314,8 @@ class ModelUserUser extends Model {
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if(validemail($email) == 0) { continue; }
$query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_EMAIL . " WHERE email=?", array($email)); $query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_EMAIL . " WHERE email=?", array($email));
/* remove from memcached */ /* remove from memcached */
@ -346,6 +348,8 @@ class ModelUserUser extends Model {
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($email); $email = rtrim($email);
if(validemail($email) == 0) { continue; }
$ret = $this->add_email((int)$user['uid'], $email); $ret = $this->add_email((int)$user['uid'], $email);
if($ret == 0) { return -2; } if($ret == 0) { return -2; }
} }
@ -391,6 +395,8 @@ class ModelUserUser extends Model {
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($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)); $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) { if($query->row['count'] > 0) {
@ -417,6 +423,9 @@ class ModelUserUser extends Model {
foreach ($emails as $email) { foreach ($emails as $email) {
$email = rtrim($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)); $query = $this->db->query("INSERT INTO " . TABLE_EMAIL . " (uid, email) VALUES(?,?)", array((int)$user['uid'], $email));
/* remove from memcached */ /* remove from memcached */