X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fcontrollers%2Fuser.php;h=fad3ddf9ef8e5837a97eb3b29126272982de7e30;hb=42b8f76ab32990f2668a4e3346374de7bad91be2;hp=8ebfdb3888791f2e6f5451049fec349e95775c03;hpb=a69349a99360f6cb64ae3d87f6572f1d8a98400f;p=living-lab-site.git diff --git a/application/controllers/user.php b/application/controllers/user.php index 8ebfdb3..fad3ddf 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -26,7 +26,31 @@ class User extends CI_Controller { public function test($user_id = 1) { - + echo extension_loaded('gd') ? 'gd' : 'nu'; + } + + // DEBUG + public function show_session() + { + if (ENVIRONMENT == 'production') + die(); + + var_dump($this->session->all_userdata()); + } + // DEBUG + public function destroy_session() + { + if (ENVIRONMENT == 'production') + die(); + + $this->session->sess_destroy(); + } + + public function ajax_get_captcha() + { + $this->load->library('captcha'); + $captcha = $this->captcha->get_captcha(); + echo $captcha['image']; } /** @@ -41,8 +65,20 @@ class User extends CI_Controller { $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') @@ -68,6 +104,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}")); @@ -86,6 +130,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. @@ -108,6 +189,8 @@ class User extends CI_Controller { $this->load->library('form_validation'); $this->load->helper('localization'); $this->load->helper('date'); + + $user_id = $this->session->userdata('user_id'); $this->form_validation->set_error_delimiters('', ''); @@ -135,19 +218,30 @@ class User extends CI_Controller { } else $b_validation = FALSE; - + if (! $b_validation) { // Edit account data if logged in, otherwise register. - if ($user_id = $this->session->userdata('user_id')) + // ** ACCOUNT + if ($user_id) { $userdata = $this->users_model->get_userdata(intval($user_id)); + if (substr($userdata['username'], 0, 8) == 'autogen_') + $userdata['autogen_username'] = + substr($userdata['username'], 8); $selected_menu = 'account'; + $captcha = FALSE; } + // ** REGISTER else { $userdata = FALSE; $selected_menu = 'register'; + + // CAPTCHA + $this->load->library('captcha'); + $captcha = $this->captcha->get_captcha(); + $captcha = $captcha['image']; } $params = array('title' => @@ -167,7 +261,7 @@ class User extends CI_Controller { $main_params['content'] = $this->load->view('user/register_view', array('userdata'=> $userdata, 'redirect'=> $redirect, - 'error_upload'=> $error_upload), + 'error_upload'=> $error_upload, 'captcha'=> $captcha), TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); @@ -177,10 +271,14 @@ class User extends CI_Controller { } else { - $user_id = $this->input->post('user-id'); + // TODO: Security problem! + //$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'); + $data['sex'] = intval($this->input->post('sex')); $data['birth_date'] = $this->input->post('birth-date'); $data['country'] = $this->input->post('country'); $data['locality'] = $this->input->post('locality'); @@ -207,6 +305,7 @@ class User extends CI_Controller { . $upload_data['file_name']. '-thumb.jpg', 120, 90); } + // TODO: To much info as session data? // Update session user data. $this->_update_session_userdata($data); @@ -215,7 +314,7 @@ class User extends CI_Controller { { $password = $this->input->post('new-password'); if ($password) - $data['password'] = $this->input->post('new-password'); + $data['password'] = $password; $this->users_model->set_userdata($user_id, $data); @@ -227,6 +326,7 @@ class User extends CI_Controller { { $data['username'] = $this->input->post('username'); $data['password'] = $this->input->post('password'); + $data['auth_src'] = 'internal'; $this->users_model->register($data); $user_id = $this->users_model->get_userdata($data['username'], @@ -331,17 +431,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; } } @@ -359,10 +460,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; } @@ -404,21 +505,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; } } @@ -461,20 +562,36 @@ 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); + { + if ($this->session->userdata($key)) + $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) @@ -509,12 +626,12 @@ class User extends CI_Controller { return $date; } - public function _valid_old_password($old_password, $field_username) + public function _valid_old_password($old_password) { if (! $old_password) return TRUE; - $username= $this->input->post($field_username); + $username= $this->session->userdata('username'); if ($this->users_model->login($username, $old_password)) return TRUE; @@ -534,7 +651,7 @@ class User extends CI_Controller { public function _required_by_register($param) { - $user_id = $this->input->post('user-id'); + $user_id = $this->session->userdata('user_id'); if (! $user_id && ! $param) return FALSE; @@ -610,6 +727,13 @@ class User extends CI_Controller { return TRUE; } + public function _check_captcha($word) + { + $this->load->library('captcha'); + + return $this->captcha->check_captcha($word); + } + public function _internal_account($username) { $userdata = $this->users_model->get_userdata($username, 'auth_src');