From 7f012ee652e0c62c6b73bfa3fc029b7749520b6c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 13 Jul 2016 21:35:22 +0200 Subject: controllers/user: Deduplicate email verification Signed-off-by: Florian Pritz --- application/controllers/user.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/application/controllers/user.php b/application/controllers/user.php index 4ff9ae530..e1c01051a 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -208,8 +208,7 @@ class User extends MY_Controller { } } - $this->load->helper("email"); - if (!valid_email($email)) { + if (!$this->valid_email($email)) { $error[]= "Invalid email."; } @@ -628,6 +627,18 @@ class User extends MY_Controller { return !$username || strlen($username) > 32 || !preg_match("/^[a-z0-9]+$/", $username); } + /** + * Check if a given email is valid. Only perform minimal checking since + * verifying emails is very very difficuly. + * + * @return boolean + */ + private function valid_email($email) + { + $this->load->helper("email"); + return valid_email($email); + } + function add_user() { if (!$this->input->is_cli_request()) return; @@ -635,7 +646,6 @@ class User extends MY_Controller { $error = array(); - // FIXME: deduplicate username/email verification with register() $username = $this->_get_line_cli("Username", function($username) { if (!$this->valid_username($username)) { echo "Invalid username (only up to 32 chars of a-z0-9 are allowed).\n"; @@ -649,9 +659,8 @@ class User extends MY_Controller { return true; }); - $this->load->helper("email"); $email = $this->_get_line_cli("Email", function($email) { - if (!valid_email($email)) { + if (!$this->valid_email($email)) { echo "Invalid email.\n"; return false; } -- cgit v1.2.3-24-g4f1b