X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fcontrollers%2Fuser.php;h=5820379117738b795d91fd26e3bbbcd4fa83bc5d;hb=2881d1393f363efd3c5f0e9b58706e6e35e85717;hp=5a9b779024bf21b15484688db3aa6103c5b792f8;hpb=ada355332b092d2bd0ec7845f62c307587c9aab0;p=living-lab-site.git diff --git a/application/controllers/user.php b/application/controllers/user.php index 5a9b779..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 ($this->users_model->get_userdata('calin.burloiu') ? 'd' : 'n'); } /** @@ -82,24 +82,8 @@ class User extends CI_Controller { { if ($b_openid) { - $this->lang->load('openid'); - $this->load->library('openid'); - $this->config->load('openid'); - $request_to = site_url('user/check_openid_login'); - $req = $this->config->item('openid_required'); - $opt = $this->config->item('openid_optional'); - $policy = site_url('user/openid_policy'); - $pape_policy_uris = $this->config->item('openid_papa_policies'); - - $this->openid->set_request_to($request_to); - $this->openid->set_trust_root(base_url()); - $this->openid->set_args(null); - $this->openid->set_sreg(true, $req, $opt, $policy); - if (!empty($pape_policy_uris)) - $this->openid->set_pape(true, $pape_policy_uris); - - // Redirection to OP site will follow. - $this->openid->authenticate($this->input->post('openid')); + $this->users_model->openid_begin_login( + $this->input->post('openid')); return; } @@ -124,46 +108,34 @@ class User extends CI_Controller { public function check_openid_login() { - $this->lang->load('openid'); - $this->load->library('openid'); - $this->config->load('openid'); - $request_to = site_url('user/check_openid_login'); - - $this->openid->set_request_to($request_to); - $response = $this->openid->get_response(); - - switch ($response->status) + $user = $this->users_model->openid_complete_login(); + + // Authentication failed. + if ($user == Auth_OpenID_CANCEL) { - case Auth_OpenID_CANCEL: $this->load->helper('message'); - show_info_msg_page($this, $this->lang->line('openid_cancel')); - break; - case Auth_OpenID_FAILURE: + 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->_format_message('openid_failure', - $response->message)); - break; - case Auth_OpenID_SUCCESS: - $openid = $response->getDisplayIdentifier(); - $esc_identity = htmlspecialchars($openid, ENT_QUOTES); - - $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); - $sreg = $sreg_resp->contents(); - - // Get registration informations - $ax = new Auth_OpenID_AX_FetchResponse(); - $obj = $ax->fromSuccessResponse($response); - - //echo 'nickname('. $sreg_resp->get('nickname'). ')'; - echo var_dump($obj->data); -// foreach ($sreg as $key => $value) -// { -// $data['success'] .= $this->_set_message('openid_content', array($key, $value), array('%s', '%t')); -// } - - break; + 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() @@ -224,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 @@ -263,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'); @@ -568,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);