From 23e1d6ccbb0eabc48afcb26b3e60d7fb753eb4b6 Mon Sep 17 00:00:00 2001 From: Emad Elsaid Date: Sat, 16 Apr 2011 03:57:27 +0200 Subject: [PATCH] username is now the identity and sme bugfixes with activating the account and ion_aut model --- application/config/ion_auth.php | 12 ++--- application/controllers/auth.php | 30 +++++++----- application/controllers/users_editor.php | 62 ++---------------------- application/models/ion_auth_model.php | 2 +- application/views/auth/create_user.php | 4 ++ application/views/auth/login.php | 13 +++-- mysql.sql | 2 +- 7 files changed, 38 insertions(+), 87 deletions(-) diff --git a/application/config/ion_auth.php b/application/config/ion_auth.php index a29b570a..26facf34 100644 --- a/application/config/ion_auth.php +++ b/application/config/ion_auth.php @@ -54,13 +54,13 @@ * Columns in your meta table, * id not required. **/ - $config['columns'] = array('first_name', 'last_name', 'company', 'phone'); + $config['columns'] = array('first_name', 'last_name'); /** * A database column which is used to * login with. **/ - $config['identity'] = 'email'; + $config['identity'] = 'username'; /** * Minimum Required Length of Password @@ -138,22 +138,22 @@ /** * Message Start Delimiter **/ - $config['message_start_delimiter'] = '

'; + $config['message_start_delimiter'] = '

'; /** * Message End Delimiter **/ - $config['message_end_delimiter'] = '

'; + $config['message_end_delimiter'] = '
'; /** * Error Start Delimiter **/ - $config['error_start_delimiter'] = '

'; + $config['error_start_delimiter'] = '

'; /** * Error End Delimiter **/ - $config['error_end_delimiter'] = '

'; + $config['error_end_delimiter'] = '
'; /* End of file ion_auth.php */ /* Location: ./system/application/config/ion_auth.php */ \ No newline at end of file diff --git a/application/controllers/auth.php b/application/controllers/auth.php index a9e27163..f02a2dd0 100644 --- a/application/controllers/auth.php +++ b/application/controllers/auth.php @@ -24,17 +24,15 @@ public function index(){ //log the user in public function login(){ - $this->data['title'] = lang('system_login'); - //validate form input - $this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email'); + $this->form_validation->set_rules('username', lang('system_email'), 'required'); $this->form_validation->set_rules('password', lang('system_password'), 'required'); if ($this->form_validation->run() == true){ //check to see if the user is logging in //check for "remember me" $remember = (bool) $this->input->post('remember'); - if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember)){ //if the login is successful + if ($this->ion_auth->login($this->input->post('username'), $this->input->post('password'), $remember)){ //if the login is successful //redirect them back to the home page $this->session->set_flashdata('message', $this->ion_auth->messages()); redirect($this->config->item('base_url'), 'refresh'); @@ -47,10 +45,10 @@ public function login(){ //set the flash data error message if there is one $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); - $this->data['email'] = array('name' => 'email', - 'id' => 'email', + $this->data['username'] = array('name' => 'username', + 'id' => 'username', 'type' => 'text', - 'value' => $this->form_validation->set_value('email'), + 'value' => $this->form_validation->set_value('username'), ); $this->data['password'] = array('name' => 'password', 'id' => 'password', @@ -64,11 +62,10 @@ public function login(){ //log the user out public function logout(){ - $this->data['title'] = lang('system_logout'); //log the user out $logout = $this->ion_auth->logout(); //redirect them back to the page they came from - redirect('auth', 'refresh'); + redirect('auth/login', 'refresh'); } @@ -172,7 +169,7 @@ public function activate($id, $code=false){ if ($activation){ //redirect them to the auth page $this->session->set_flashdata('message', $this->ion_auth->messages()); - redirect("auth", 'refresh'); + redirect("auth/login", 'refresh'); }else{ //redirect them to the forgot password page $this->session->set_flashdata('message', $this->ion_auth->errors()); @@ -188,12 +185,13 @@ public function create_user(){ //validate form input $this->form_validation->set_rules('first_name', lang('system_first_name'), 'required|xss_clean'); $this->form_validation->set_rules('last_name', lang('system_last_name'), 'required|xss_clean'); + $this->form_validation->set_rules('username', lang('system_username'), 'trim|required|min_length[5]|max_length[15]|xss_clean'); $this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email'); $this->form_validation->set_rules('password', lang('system_password'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]'); $this->form_validation->set_rules('password_confirm', lang('system_password_conf'), 'required'); if ($this->form_validation->run() == true){ - $username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name')); + $username = $this->input->post('username'); $email = $this->input->post('email'); $password = $this->input->post('password'); @@ -203,10 +201,11 @@ public function create_user(){ ); } - if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)){ //check to see if we are creating the user + if ($this->form_validation->run() == true + && $this->ion_auth->register($username, $password, $email, $additional_data)){ //redirect them back to the admin page $this->session->set_flashdata('message', "User Created"); - redirect("auth", 'refresh'); + redirect("auth/login", 'refresh'); }else{ //display the create user form //set the flash data error message if there is one $this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message'))); @@ -226,6 +225,11 @@ public function create_user(){ 'type' => 'text', 'value' => $this->form_validation->set_value('email'), ); + $this->data['username'] = array('name' => 'username', + 'id' => 'username', + 'type' => 'text', + 'value' => $this->form_validation->set_value('username'), + ); $this->data['password'] = array('name' => 'password', 'id' => 'password', 'type' => 'password', diff --git a/application/controllers/users_editor.php b/application/controllers/users_editor.php index c3e9365d..ac4ff8bf 100644 --- a/application/controllers/users_editor.php +++ b/application/controllers/users_editor.php @@ -24,8 +24,7 @@ public function __construct(){ $this->pages = array( 'index'=>lang('system_active_users'), 'inactive'=>lang('system_inactive_users'), - 'newGroup'=>lang('system_new_group'), - 'newUser'=>lang('system_new_user') + 'newGroup'=>lang('system_new_group') ); $this->load->library('gui'); @@ -220,61 +219,6 @@ public function deleteGroup($id){ } - /** - * create new user page, and it has one form - * with needed data - * and it has already the action itself, - * that is copied from ion-auth Auth controller - */ - public function newUser(){ - - $this->load->library('form_validation'); - //validate form input - $this->form_validation->set_rules('first_name', lang('system_first_name'), 'required|xss_clean'); - $this->form_validation->set_rules('last_name', lang('system_last_name'), 'required|xss_clean'); - $this->form_validation->set_rules('email', lang('system_email'), 'required|valid_email'); - $this->form_validation->set_rules('password', lang('system_password'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]'); - $this->form_validation->set_rules('password_confirm', lang('system_password_conf'), 'required'); - - if ($this->form_validation->run() == true) - { - $username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name')); - $email = $this->input->post('email'); - $password = $this->input->post('password'); - - $additional_data = array('first_name' => $this->input->post('first_name'), - 'last_name' => $this->input->post('last_name') - ); - } - if ($this->form_validation->run() == true - && $this->ion_auth->register($username, $password, $email, $additional_data,$this->input->post('group'))) - { //check to see if we are creating the user - //redirect them back to the admin page - $this->session->set_flashdata('message', lang('system_user_created')); - redirect("users_editor"); - }else{ //display the create user form - //set the flash data error message if there is one - $groups = new Group(); - $groups->get(); - $groups_array = array(); - foreach( $groups as $group ) - $groups_array[$group->name] = $group->name; - - $this->print_text( - $this->gui->form('users_editor/newUser', - array( - ' ' => (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message'))), - lang('system_group_label') => $this->gui->dropdown('group','',$groups_array), - lang('system_first_name').'*' => $this->gui->textbox('first_name',$this->form_validation->set_value('first_name')), - lang('system_last_name').'*' => $this->gui->textbox('last_name',$this->form_validation->set_value('last_name')), - lang('system_email').'*' => $this->gui->textbox( 'email', $this->form_validation->set_value('email')), - lang('system_password').'*' => $this->gui->password( 'password', $this->form_validation->set_value('password')), - lang('system_password_conf').'*' => $this->gui->password( 'password_confirm', $this->form_validation->set_value('password_confirm')), - '' => $this->gui->button('submit',lang('system_create_user'), array('type'=>'submit')) - ))); - } - } - /** * edit user information * @@ -289,7 +233,7 @@ public function editUser($id){ $groups_array[$group->id] = $group->name; $user = $this->ion_auth->get_user($id); - $this->print_text( + $this->print_text( '

'. $this->gui->form('users_editor/editUserAction', array( lang('system_group_label') => $this->gui->dropdown('group',$user->group_id,$groups_array), @@ -311,7 +255,7 @@ public function editUser($id){ anchor('users_editor/deleteUser/'.$id,lang('system_delete_user')) ),'', array('id'=>$user->id) - ) + ) .'

' ); } diff --git a/application/models/ion_auth_model.php b/application/models/ion_auth_model.php index 4bb31ab9..01ee042b 100644 --- a/application/models/ion_auth_model.php +++ b/application/models/ion_auth_model.php @@ -458,7 +458,7 @@ public function profile($identity = '', $is_code = false) **/ public function register($username, $password, $email, $additional_data = false, $group_name = false) { - if ($this->identity_column == 'email' && $this->email_check($email)) + if ( $this->email_check($email) ) { $this->ion_auth->set_error('account_creation_duplicate_email'); return FALSE; diff --git a/application/views/auth/create_user.php b/application/views/auth/create_user.php index d4475630..5d39aa5f 100644 --- a/application/views/auth/create_user.php +++ b/application/views/auth/create_user.php @@ -68,6 +68,10 @@


+ +


+ +


diff --git a/application/views/auth/login.php b/application/views/auth/login.php index 7adc316b..d6d16153 100644 --- a/application/views/auth/login.php +++ b/application/views/auth/login.php @@ -9,7 +9,7 @@ - -