X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fcontrollers%2Fuser.php;h=5820379117738b795d91fd26e3bbbcd4fa83bc5d;hb=2881d1393f363efd3c5f0e9b58706e6e35e85717;hp=96454bedb07672716840fbbd27664ddb387b755b;hpb=9cc2a6602b47ac97d72efa51ec654418b252b4e4;p=living-lab-site.git diff --git a/application/controllers/user.php b/application/controllers/user.php index 96454be..5820379 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -26,7 +26,7 @@ class User extends CI_Controller { public function test($user_id = 1) { - echo sha1('hQwCUEPQZcN8c4Es'); + echo ($this->users_model->get_userdata('calin.burloiu') ? 'd' : 'n'); } /** @@ -39,11 +39,22 @@ class User extends CI_Controller { public function login($redirect = '') { $this->load->library('form_validation'); - $this->form_validation->set_error_delimiters('', ''); + + // Normal or OpenID login? + if ($this->input->post('openid') !== FALSE) + $b_openid = TRUE; + else + $b_openid = FALSE; + // Validate the correct form. + $res_form_validation = FALSE; + if (!$b_openid) + $res_form_validation = $this->form_validation->run('login'); + else + $res_form_validation = $this->form_validation->run('login_openid'); - if ($this->form_validation->run('login') === FALSE) + if ($res_form_validation === FALSE) { $params = array( 'title' => $this->lang->line('ui_nav_menu_login') @@ -69,6 +80,14 @@ class User extends CI_Controller { } else { + if ($b_openid) + { + $this->users_model->openid_begin_login( + $this->input->post('openid')); + return; + } + + // Without OpenID if (! $this->activated_account) header('Location: ' . site_url("user/activate/{$this->user_id}")); @@ -87,6 +106,43 @@ class User extends CI_Controller { } } + public function check_openid_login() + { + $user = $this->users_model->openid_complete_login(); + + // Authentication failed. + if ($user == Auth_OpenID_CANCEL) + { + $this->load->helper('message'); + show_error_msg_page($this, $this->lang->line('openid_cancel')); + return; + } + else if ($user == Auth_OpenID_FAILURE) + { + $this->load->helper('message'); + show_error_msg_page($this, $this->lang->line('openid_failure')); + return; + } + + // Authentication successful: set session with user data. + $this->session->set_userdata(array( + 'user_id'=> $user['id'], + 'username'=> $user['username'], + 'auth_src'=> $user['auth_src'], + 'time_zone'=> $user['time_zone'] + )); + + if ($user['import']) + header('Location: '. site_url('user/account')); + else + header('Location: '. site_url()); + } + + public function openid_policy() + { + $this->load->view('openid_policy_view'); + } + /** * Logout user and then redirect it to the last page which must be encoded * in $redirect. @@ -112,13 +168,41 @@ class User extends CI_Controller { $this->form_validation->set_error_delimiters('', ''); + $error_upload = ''; + + if ($this->form_validation->run('register')) + { + $b_validation = TRUE; + + if ($_FILES['picture']['tmp_name']) + { + // Upload library + $config_upload['upload_path'] = './data/user_pictures'; + $config_upload['file_name'] = + str_replace('.', '-', $this->input->post('username')) .'-'; + $config_upload['allowed_types'] = 'gif|jpg|png'; + $config_upload['max_size'] = '10240'; + $this->load->library('upload', $config_upload); + + $b_validation = $this->upload->do_upload('picture'); + $error_upload = + $this->upload->display_errors('', + ''); + } + } + else + $b_validation = FALSE; - if ($this->form_validation->run('register') === FALSE) + 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 @@ -143,7 +227,8 @@ class User extends CI_Controller { array('selected_menu' => $selected_menu)); $main_params['content'] = $this->load->view('user/register_view', - array('userdata'=> $userdata, 'redirect'=> $redirect), + array('userdata'=> $userdata, 'redirect'=> $redirect, + 'error_upload'=> $error_upload), TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); @@ -154,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'); @@ -163,6 +250,26 @@ class User extends CI_Controller { $data['ui_lang'] = $this->input->post('ui-lang'); $data['time_zone'] = $this->input->post('time-zone'); + // Handle picture if one was uploaded. + if ($_FILES['picture']['tmp_name']) + { + $upload_data = $this->upload->data(); + $this->load->library('image'); + $this->image->load($upload_data['full_path']); + // Resize original to a maximum size. + if ($this->image->get_width() * $this->image->get_height() + > 640*480) + { + $this->image->save_thumbnail( + $upload_data['full_path'], + 640, 480, IMAGETYPE_AUTO); + } + // Create thumbnail. + $data['picture'] = $upload_data['file_name']; + $this->image->save_thumbnail($upload_data['file_path'] + . $upload_data['file_name']. '-thumb.jpg', 120, 90); + } + // Update session user data. $this->_update_session_userdata($data); @@ -213,19 +320,14 @@ class User extends CI_Controller { // ** // Logged in user time zone $time_zone = $this->session->userdata('time_zone'); - if (! $time_zone) - $time_zone = 'UTC'; // User data $userdata = $this->users_model->get_userdata($username); $userdata['roles'] = Users_model::roles_to_string($userdata['roles']); $country_list = $this->config->item('country_list'); $userdata['country_name'] = $country_list[ $userdata['country'] ]; - $userdata['last_login'] = date('Y-m-d H:i:s', - gmt_to_local( - strtotime($userdata['last_login']), - $time_zone, - TRUE)) . ($time_zone == 'UTC' ? ' (UTC)' : ''); + $userdata['last_login'] = human_gmt_to_human_local( + $userdata['last_login'], $time_zone); $userdata['time_zone'] = $this->lang->line($userdata['time_zone']); // User's videos @@ -292,17 +394,18 @@ class User extends CI_Controller { && $this->users_model->activate_account($user_id, $activation_code)) { - $this->session->set_flashdata('msg', sprintf( + $this->load->helper('message'); + show_info_msg_page($this, sprintf( $this->lang->line('user_msg_activated_account'), site_url('user/login'))); - header('Location: '. site_url('message/info')); return; } else { - $this->session->set_flashdata('msg', - $this->lang->line('user_msg_wrong_activation_code')); - header('Location: '. site_url('message/error')); + $this->load->helper('message'); + show_error_msg_page($this, + $this->lang->line( + 'user_msg_wrong_activation_code')); return; } } @@ -320,10 +423,10 @@ class User extends CI_Controller { if ($activated_account) { - $this->session->set_flashdata('msg', sprintf( - $this->lang->line('user_msg_activated_account'), - site_url('user/login'))); - header('Location: '. site_url('message/info')); + $this->load->helper('message'); + show_info_msg_page($this, sprintf( + $this->lang->line('user_msg_activated_account'), + site_url('user/login'))); return; } @@ -365,21 +468,21 @@ class User extends CI_Controller { { if ($method == 'code') { - // Redirect to a message which tells the user that the + // A message which tells the user that the // activation was successful. - $this->session->set_flashdata('msg', sprintf( - $this->lang->line('user_msg_activated_account'), - site_url('user/login'))); - header('Location: '. site_url('message/info')); + $this->load->helper('message'); + show_info_msg_page($this, sprintf( + $this->lang->line('user_msg_activated_account'), + site_url('user/login'))); return; } else if ($method == 'resend') { // Redirect to resent message - $this->session->set_flashdata('msg', sprintf( + $this->load->helper('message'); + show_info_msg_page($this, sprintf( $this->lang->line('user_msg_activation_resent'), $this->input->post('email'))); - header('Location: '. site_url('message/info')); return; } } @@ -422,22 +525,35 @@ class User extends CI_Controller { } else { - // Redirect to resent message - $this->session->set_flashdata('msg', sprintf( + // Resent message + $this->load->helper('message'); + show_info_msg_page($this, sprintf( $this->lang->line('user_msg_password_recovery_email_sent'), $this->input->post('username'), $this->input->post('email'))); - header('Location: '. site_url('message/info')); return; } } + public function _format_message($msg, $val = '', $sub = '%s') + { + return str_replace($sub, $val, $this->lang->line($msg)); + } + public function _update_session_userdata($data) { foreach ($data as $key=> $val) $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); @@ -461,6 +577,15 @@ class User extends CI_Controller { return (preg_match('/[\d]{4}-[\d]{2}-[\d]{2}/', $date) === 1); } + public function _postprocess_birth_date($date) + { + // If the user entered no birth date NULL needs to be inserted into DB. + if (! $date) + return NULL; + + return $date; + } + public function _valid_old_password($old_password, $field_username) { if (! $old_password)