From 480a21049384e47afe920e73972ca336ec8e6a54 Mon Sep 17 00:00:00 2001 From: Calin-Andrei Burloiu Date: Mon, 24 Oct 2011 16:25:02 +0300 Subject: [PATCH] autogenerated usernames registered with OpenID can be changed; Google, Yahoo and myOpenID buttons added to log in directly with OpenID --- application/config/form_validation.php | 2 +- application/controllers/user.php | 16 ++++++- .../language/english/form_validation_lang.php | 1 + application/models/users_model.php | 3 +- application/views/user/login_view.php | 43 ++++++++++++++++++- application/views/user/register_view.php | 8 +++- 6 files changed, 67 insertions(+), 6 deletions(-) diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 02cb29c..b11b331 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -27,7 +27,7 @@ $config = array( 'field'=>'username', 'label'=>'lang:user_username', 'rules'=>'trim|callback__required_by_register|min_length[5]|max_length[32]' - . '|strtolower|xss_clean|callback__valid_username' + . '|strtolower|xss_clean|callback__is_username_unique|callback__valid_username' ), array( 'field'=>'password', diff --git a/application/controllers/user.php b/application/controllers/user.php index 397699b..5820379 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -196,9 +196,13 @@ class User extends CI_Controller { if (! $b_validation) { // Edit account data if logged in, otherwise register. - if ($user_id = $this->session->userdata('user_id')) + $user_id = $this->session->userdata('user_id'); + if ($user_id) { $userdata = $this->users_model->get_userdata(intval($user_id)); + if (substr($userdata['username'], 0, 8) == 'autogen_') + $userdata['autogen_username'] = //'xxx'; + substr($userdata['username'], 8); $selected_menu = 'account'; } else @@ -235,6 +239,8 @@ class User extends CI_Controller { else { $user_id = $this->input->post('user-id'); + if ($this->input->post('username')) + $data['username'] = $this->input->post('username'); $data['email'] = $this->input->post('email'); $data['first_name'] = $this->input->post('first-name'); $data['last_name'] = $this->input->post('last-name'); @@ -540,6 +546,14 @@ class User extends CI_Controller { $this->session->set_userdata($key, $val); } + public function _is_username_unique($username) + { + if ($this->users_model->get_userdata($username)) + return FALSE; + + return TRUE; + } + public function _valid_username($username) { return (preg_match('/^[a-z0-9\._]+$/', $username) === 1); diff --git a/application/language/english/form_validation_lang.php b/application/language/english/form_validation_lang.php index e86f027..59d8352 100644 --- a/application/language/english/form_validation_lang.php +++ b/application/language/english/form_validation_lang.php @@ -4,6 +4,7 @@ include('system/language/english/form_validation_lang.php'); // Login / Register/ Account / Profile +$lang['_is_username_unique'] = 'Username already exists. Please choose another one.'; $lang['_valid_username'] = 'You must enter a valid username with letters, numbers, . (dots) or _ (underscores).'; $lang['_valid_username_or_email'] = "You must enter an e-mail address or a valid username."; $lang['_do_login'] = 'Wrong %s, or wrong %s.'; diff --git a/application/models/users_model.php b/application/models/users_model.php index 427b07e..8046ed3 100644 --- a/application/models/users_model.php +++ b/application/models/users_model.php @@ -243,11 +243,11 @@ class Users_model extends CI_Model { { $data['username'] = $data['first_name'] . '_' . $data['last_name']; - $data['username'] = substr($data['username'], 0, 32); } else $data['username'] = $this->gen_username(); } + $data['username'] = substr($data['username'], 0, 24); if ($this->get_userdata($data['username'])) { $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; @@ -258,6 +258,7 @@ class Users_model extends CI_Model { $data['username'] .= $chars[ mt_rand(0, $len_chars - 1) ]; } while($this->get_userdata($data['username'])); } + $data['username'] = 'autogen_' . $data['username']; // Country $country = $ax_resp->get('http://axschema.org/contact/country'); diff --git a/application/views/user/login_view.php b/application/views/user/login_view.php index 265672b..3d3aaa0 100644 --- a/application/views/user/login_view.php +++ b/application/views/user/login_view.php @@ -43,6 +43,13 @@
lang->line('user_legend_login_openid') ?> + +

+ + + +

+ @@ -63,4 +70,38 @@
lang->line('user_openid'). ': ' ?>
- \ No newline at end of file + + + \ No newline at end of file diff --git a/application/views/user/register_view.php b/application/views/user/register_view.php index 59fee7e..dd97e2e 100644 --- a/application/views/user/register_view.php +++ b/application/views/user/register_view.php @@ -31,16 +31,20 @@ else   - + lang->line('user_username'). ' * : ' ?> + + + + lang->line('user_username'). ' : ' ?>   - ` + -- 2.20.1