diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-07-14 15:16:34 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-07-14 15:16:34 +0200 |
commit | 1b462fac46eaf387f47a274a9f6bd9b46cd19981 (patch) | |
tree | 660fab7226d65668ca64bd1643391594cd50cf04 /application | |
parent | 449302a0ac3c9f5127d098927939cf14da3eaa92 (diff) |
Move username/email validation functions to muser
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r-- | application/controllers/user.php | 33 | ||||
-rw-r--r-- | application/models/muser.php | 25 |
2 files changed, 29 insertions, 29 deletions
diff --git a/application/controllers/user.php b/application/controllers/user.php index f0426943b..37cf97fe1 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -200,7 +200,7 @@ class User extends MY_Controller { $password = $this->input->post("password"); $password_confirm = $this->input->post("password_confirm"); - if (!$this->valid_username($username)) { + if (!$this->muser->valid_username($username)) { $error[]= "Invalid username (only up to 32 chars of a-z0-9 are allowed)."; } else { if ($this->muser->username_exists($username)) { @@ -208,7 +208,7 @@ class User extends MY_Controller { } } - if (!$this->valid_email($email)) { + if (!$this->muser->valid_email($email)) { $error[]= "Invalid email."; } @@ -614,31 +614,6 @@ class User extends MY_Controller { } } - /* - * Check if a given username is valid. - * - * Valid usernames contain only lowercase characters and numbers. They are - * also <= 32 characters in length. - * - * @return boolean - */ - private function valid_username($username) - { - return 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() { $this->_require_cli_request(); @@ -647,7 +622,7 @@ class User extends MY_Controller { $error = array(); $username = $this->_get_line_cli("Username", function($username) { - if (!$this->valid_username($username)) { + if (!$this->muser->valid_username($username)) { echo "Invalid username (only up to 32 chars of a-z0-9 are allowed).\n"; return false; } else { @@ -660,7 +635,7 @@ class User extends MY_Controller { }); $email = $this->_get_line_cli("Email", function($email) { - if (!$this->valid_email($email)) { + if (!$this->muser->valid_email($email)) { echo "Invalid email.\n"; return false; } diff --git a/application/models/muser.php b/application/models/muser.php index f2b961d89..4ec821f4d 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -134,6 +134,31 @@ class Muser extends CI_Model { return $this->session->userdata('username'); } + /* + * Check if a given username is valid. + * + * Valid usernames contain only lowercase characters and numbers. They are + * also <= 32 characters in length. + * + * @return boolean + */ + public function valid_username($username) + { + return 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 + */ + public function valid_email($email) + { + $this->load->helper("email"); + return valid_email($email); + } + function get_userid() { if (!$this->logged_in()) { |