From ada355332b092d2bd0ec7845f62c307587c9aab0 Mon Sep 17 00:00:00 2001 From: Calin Burloiu Date: Thu, 13 Oct 2011 17:09:36 +0300 Subject: [PATCH] integration of simple OpenID logging in facility almost ready --- application/config/config.php | 2 +- application/config/form_validation.php | 7 + application/config/openid.php | 7 +- application/controllers/catalog.php | 210 +++++---- application/controllers/message.php | 2 +- application/controllers/test.php | 287 ++++++------ application/controllers/user.php | 131 +++++- application/helpers/message_helper.php | 60 +++ application/language/english/openid_lang.php | 1 + application/language/english/user_lang.php | 3 + application/libraries/Auth/OpenID.php | 4 +- application/libraries/Openid.php | 439 +++++++++--------- ...view_policy.php => openid_policy_view.php} | 0 .../views/user/activated_account_view.php | 2 - application/views/user/login_view.php | 98 ++-- application/views/view_openid.php | 3 +- nbproject/netbeans_ci_code_completion.php | 103 ++++ nbproject/private/private.properties | 5 + nbproject/private/private.xml | 4 + nbproject/project.properties | 7 + nbproject/project.xml | 9 + 21 files changed, 873 insertions(+), 511 deletions(-) create mode 100644 application/helpers/message_helper.php rename application/views/{view_policy.php => openid_policy_view.php} (100%) delete mode 100644 application/views/user/activated_account_view.php create mode 100644 nbproject/netbeans_ci_code_completion.php create mode 100644 nbproject/private/private.properties create mode 100644 nbproject/private/private.xml create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/application/config/config.php b/application/config/config.php index f5a488d..a96f37b 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -126,7 +126,7 @@ $config['subclass_prefix'] = 'MY_'; | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | */ -$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-+'; +$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-+&'; /* diff --git a/application/config/form_validation.php b/application/config/form_validation.php index a52115c..02cb29c 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -15,6 +15,13 @@ $config = array( 'rules'=>'required|min_length[5]|max_length[32]' ) ), + 'login_openid'=> array( + array( + 'field'=>'openid', + 'label'=>'lang:user_openid', + 'rules'=>'trim|required' + ) + ), 'register'=> array( array( 'field'=>'username', diff --git a/application/config/openid.php b/application/config/openid.php index 37a9667..2dc2630 100644 --- a/application/config/openid.php +++ b/application/config/openid.php @@ -1,9 +1,12 @@ diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 8e69a64..28063ee 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -7,14 +7,14 @@ * @author Călin-Andrei Burloiu */ class Catalog extends CI_Controller { - + public function __construct() { parent::__construct(); - + //$this->lang->load('catalog'); - } - + } + public function index() { // ** @@ -26,54 +26,60 @@ class Catalog extends CI_Controller { { // Videos $vs_data['videos'] = $this->videos_model->get_videos_summary( - $id, NULL, 0, $this->config->item('videos_per_row')); - + $id, NULL, 0, $this->config->item('videos_per_row')); + // Category $vs_data['category_name'] = $name; $vs_data['category_id'] = $id; $videos_summary['category_name'] = $name; $videos_summary['category_title'] = $name ? - $this->lang->line("ui_categ_$name") : $name; - + $this->lang->line("ui_categ_$name") : $name; + // Pagination (not required) $vs_data['pagination'] = ''; - + $videos_summary['content'] = $this->load->view( - 'catalog/videos_summary_view', $vs_data, TRUE); + 'catalog/videos_summary_view', $vs_data, TRUE); $data['videos_summaries'][] = $videos_summary; } - - $params = array( 'title' => $this->config->item('site_name'), - 'css' => array( - 'catalog.css' - ), - //'js' => array(), - //'metas' => array('description'=>'','keywords'=>'') - ); + + $params = array('title' => $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + //'js' => array(), + //'metas' => array('description'=>'','keywords'=>'') + ); $this->load->library('html_head_params', $params); - + // ** // ** LOADING VIEWS // ** $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', array( - 'selected_menu'=> 'home' + 'selected_menu' => 'home' )); - - $main_params['content'] = $this->load->view('catalog/index_view', $data, TRUE); + + $main_params['content'] = $this->load->view('catalog/index_view', $data, + TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); - + $this->load->view('footer'); $this->load->view('html_end'); } - - public function test($page = 0) + + public function test() { - $this->load->model('users_model'); - echo Users_model::gen_activation_code('calin.burloiu'); + $q = $this->input->get('q'); + $q = ($q ? $q : 'nimic'); + + $w = $this->input->get('w'); + $w = ($w ? $w : 'nimic'); + + echo "$q / $w"; } - + public function category($category_name, $ordering = 'hottest', $offset = 0) { // ** @@ -81,69 +87,70 @@ class Catalog extends CI_Controller { // ** // Video Category $category_data = Catalog::_get_category_data($category_name); - + // Retrieve videos summary. $this->load->model('videos_model'); $vs_data['videos'] = $this->videos_model->get_videos_summary( - $category_data['category_id'], NULL, intval($offset), - $this->config->item('videos_per_page'), $ordering); - + $category_data['category_id'], NULL, intval($offset), + $this->config->item('videos_per_page'), $ordering); + $vs_data['ordering'] = $ordering; - + // Pagination $this->load->library('pagination'); - $pg_config['base_url'] = site_url("catalog/category/$category_name/$ordering/"); + $pg_config['base_url'] = site_url( + "catalog/category/$category_name/$ordering/"); $pg_config['uri_segment'] = 5; $pg_config['total_rows'] = $this->videos_model->get_videos_count( - $category_data['category_id']); + $category_data['category_id']); $pg_config['per_page'] = $this->config->item('videos_per_page'); $this->pagination->initialize($pg_config); $vs_data['pagination'] = $this->pagination->create_links(); $vs_data['category_name'] = $category_data['category_name']; $vs_data['title'] = $category_data['category_title']; - - $params = array( 'title' => - $category_data['category_title'].' – ' - . $this->config->item('site_name'), - 'css' => array( - 'catalog.css' - ) - //'metas' => array('description'=>'','keywords'=>'') - ); + + $params = array('title' => + $category_data['category_title'] . ' – ' + . $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ) + //'metas' => array('description'=>'','keywords'=>'') + ); $this->load->library('html_head_params', $params); - + // ** // ** LOADING VIEWS // ** $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', array( - 'search_category_name'=> $vs_data['category_name'] + 'search_category_name' => $vs_data['category_name'] )); - - $main_params['content'] = - $this->load->view('catalog/videos_summary_view', $vs_data, TRUE); + + $main_params['content'] = + $this->load->view('catalog/videos_summary_view', $vs_data, TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); - + $this->load->view('footer'); $this->load->view('html_end'); } - + public function search($search_query = "", $offset = 0, $category_name = NULL) { $this->load->model('videos_model'); $this->load->library('security'); - + // Redirect to an URL which contains search string if data was passed // via POST method and not via URL segments. $str_post_search = $this->input->post('search'); $str_post_category = $this->input->post('search-category'); - if ($search_query === "" && $str_post_search !== FALSE) + if ($search_query === "" && $str_post_search !== FALSE) { redirect('catalog/search/' - . $this->videos_model->encode_search_query($str_post_search) - . '/0' - . ($str_post_category === FALSE ? '' : "/$str_post_category")); + . $this->videos_model->encode_search_query($str_post_search) + . '/0' + . ($str_post_category === FALSE ? '' : "/$str_post_category")); return; } @@ -153,7 +160,7 @@ class Catalog extends CI_Controller { // Search query is encoded for URL and must be decoded. $enc_search_query = $search_query; $search_query = $this->videos_model->decode_search_query($search_query); - + // Security filtering $search_query = $this->security->xss_clean($search_query); $results_data['search_query'] = $search_query; @@ -161,115 +168,116 @@ class Catalog extends CI_Controller { // Category $results_data = Catalog::_get_category_data($category_name); if ($results_data === NULL) - $results_data = array('category_id'=>NULL); - + $results_data = array('category_id' => NULL); + // Page header data $header_data['search_query'] = $search_query; if ($category_name !== NULL) { $header_data['search_category_name'] = $results_data['category_name']; } - + // Check if search string is valid. if (strlen($search_query) === 0) { //$results_data['videos'] = NULL; - $this->error($this->lang->line('error_search_query_empty'), - $header_data); + $this->error($this->lang->line('error_search_query_empty'), $header_data); return; } else { // Retrieve search results. $results_data['count'] = $this->videos_model->search_videos( - $search_query, 0, 0, $results_data['category_id']); + $search_query, 0, 0, $results_data['category_id']); $results_data['videos'] = $this->videos_model->search_videos( - $search_query, intval($offset), - $this->config->item('search_results_per_page'), - $results_data['category_id']); + $search_query, intval($offset), $this->config->item( + 'search_results_per_page'), + $results_data['category_id']); if ($results_data['videos'] === NULL) $results_data['videos'] = array(); - + // Pagination $this->load->library('pagination'); $pg_config['base_url'] = site_url("catalog/search/$enc_search_query/"); $pg_config['uri_segment'] = 4; $pg_config['total_rows'] = $results_data['count']; $pg_config['per_page'] = - $this->config->item('search_results_per_page'); + $this->config->item('search_results_per_page'); $this->pagination->initialize($pg_config); $results_data['pagination'] = $this->pagination->create_links(); } - + // HTML head parameters - $params = array( 'title' => 'Search Results – ' - . $this->config->item('site_name'), - 'css' => array( - 'catalog.css' - ), - //'js' => array(), - //'metas' => array('description'=>'','keywords'=>'') - ); + $params = array('title' => 'Search Results – ' + . $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + //'js' => array(), + //'metas' => array('description'=>'','keywords'=>'') + ); $this->load->library('html_head_params', $params); - + // ** // ** LOADING VIEWS // ** $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', $header_data); - + // Search Results - $main_params['content'] = - $this->load->view('catalog/search_results_view', - $results_data, TRUE); + $main_params['content'] = + $this->load->view('catalog/search_results_view', $results_data, + TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); - + $this->load->view('footer'); $this->load->view('html_end'); } - + public function error($msg, $header_data) { - $params = array( 'title' => 'Error – ' - . $this->config->item('site_name'), - //'css' => array(), - //'js' => array(), - //'metas' => array('description'=>'','keywords'=>'') + $params = array('title' => 'Error – ' + . $this->config->item('site_name'), + //'css' => array(), + //'js' => array(), + //'metas' => array('description'=>'','keywords'=>'') ); $this->load->library('html_head_params', $params); - + // ** // ** LOADING VIEWS // ** $this->load->view('html_begin', $this->html_head_params); $this->load->view('header', $header_data); - - $main_params['content'] = $this->load->view('error_view', array('msg'=>$msg), TRUE); + + $main_params['content'] = $this->load->view('error_view', array( + 'msg' => $msg), TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); - + $this->load->view('footer'); $this->load->view('html_end'); } - + public static function _get_category_data($category_name) { - $ci =& get_instance(); - + $ci = & get_instance(); + if ($category_name === NULL) return NULL; - + $categories = $ci->config->item('categories'); $category_id = array_search($category_name, $categories); $results_data['category_name'] = $category_name; $results_data['category_id'] = $category_id; $results_data['category_title'] = $category_name ? - $ci->lang->line("ui_categ_$category_name") : $category_name; - + $ci->lang->line("ui_categ_$category_name") : $category_name; + return $results_data; - } + } + } /* End of file catalog.php */ -/* Location: ./application/controllers/catalog.php */ +/* Location: ./application/controllers/catalog.php */ \ No newline at end of file diff --git a/application/controllers/message.php b/application/controllers/message.php index 5d8b9dc..4f65ad4 100644 --- a/application/controllers/message.php +++ b/application/controllers/message.php @@ -19,7 +19,7 @@ class Message extends CI_Controller { $this->msg = $this->session->flashdata('msg'); } - public function _remap($method, $params = array()) + public function _remap($method, $par = array()) { if (! $this->msg) header('Location: '. site_url()); diff --git a/application/controllers/test.php b/application/controllers/test.php index c1cc29c..3daefde 100644 --- a/application/controllers/test.php +++ b/application/controllers/test.php @@ -1,146 +1,155 @@ lang->load('openid', 'english'); - $this->load->library('openid'); - $this->load->helper('url'); - //$this->output->enable_profiler(TRUE); - } - - // Index - function index() - { - if ($this->input->post('action') == 'verify') - { - $user_id = $this->input->post('openid_identifier'); - $pape_policy_uris = $this->input->post('policies'); - - if (!$pape_policy_uris) - { - $pape_policy_uris = array(); - } - - $this->config->load('openid'); - $req = $this->config->item('openid_required'); - $opt = $this->config->item('openid_optional'); - $policy = site_url($this->config->item('openid_policy')); - $request_to = site_url($this->config->item('openid_request_to')); - - $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); - $this->openid->set_pape(true, $pape_policy_uris); - $this->openid->authenticate($user_id); - } - - $data['pape_policy_uris'] = array( - PAPE_AUTH_MULTI_FACTOR_PHYSICAL, - PAPE_AUTH_MULTI_FACTOR, - PAPE_AUTH_PHISHING_RESISTANT - ); - - $this->load->view('view_openid', $data); - - } - - // Policy - function policy() - { - $this->load->view('view_policy'); - } - - // set message - function _set_message($msg, $val = '', $sub = '%s') - { - return str_replace($sub, $val, $this->lang->line($msg)); - } - - // Check - function check() - { - $this->config->load('openid'); - $request_to = site_url($this->config->item('openid_request_to')); - - $this->openid->set_request_to($request_to); - $response = $this->openid->getResponse(); - - switch ($response->status) - { - case Auth_OpenID_CANCEL: - $data['msg'] = $this->lang->line('openid_cancel'); - break; - case Auth_OpenID_FAILURE: - $data['error'] = $this->_set_message('openid_failure', $response->message); - break; - case Auth_OpenID_SUCCESS: - $openid = $response->getDisplayIdentifier(); - $esc_identity = htmlspecialchars($openid, ENT_QUOTES); - - $data['success'] = $this->_set_message('openid_success', array($esc_identity, $esc_identity), array('%s','%t')); - - if ($response->endpoint->canonicalID) { - $data['success'] .= $this->_set_message('openid_canonical', $response->endpoint->canonicalID); - } - - $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); - $sreg = $sreg_resp->contents(); - - foreach ($sreg as $key => $value) - { - $data['success'] .= $this->_set_message('openid_content', array($key, $value), array('%s','%t')); - } - - $pape_resp = Auth_OpenID_PAPE_Response::fromSuccessResponse($response); - - if ($pape_resp) - { - if ($pape_resp->auth_policies) - { - $data['success'] .= $this->lang->line('openid_pape_policies_affected'); - - foreach ($pape_resp->auth_policies as $uri) - { - $data['success'] .= "
  • $uri
  • "; - } - - $data['success'] .= ""; - } - else - { - $data['success'] .= $this->lang->line('openid_pape_not_affected'); - } - - if ($pape_resp->auth_age) - { - $data['success'] .= $this->_set_message('openid_auth_age', $pape_resp->auth_age); - } - - if ($pape_resp->nist_auth_level) - { - $data['success'] .= $this->_set_message('openid_nist_level', $pape_resp->nist_auth_level); - } - } - else - { - $data['success'] .= $this->lang->line('openid_pape_noresponse'); - } - break; - } - - $data['pape_policy_uris'] = array( - PAPE_AUTH_MULTI_FACTOR_PHYSICAL, - PAPE_AUTH_MULTI_FACTOR, - PAPE_AUTH_PHISHING_RESISTANT - ); - - $this->load->view('view_openid', $data); - } + function Test() + { + parent::__construct(); + + $this->lang->load('openid', 'english'); + $this->load->library('openid'); + $this->load->helper('url'); + //$this->output->enable_profiler(TRUE); + } + + // Index + function index() + { + if ($this->input->post('action') == 'verify') + { + $user_id = $this->input->post('openid_identifier'); + $pape_policy_uris = $this->input->post('policies'); + + if (!$pape_policy_uris) + { + $pape_policy_uris = array(); + } + + $this->config->load('openid'); + $req = $this->config->item('openid_required'); + $opt = $this->config->item('openid_optional'); + $policy = site_url($this->config->item('openid_policy')); + $request_to = site_url($this->config->item('openid_request_to')); + + $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); + $this->openid->set_pape(true, $pape_policy_uris); + $this->openid->authenticate($user_id); + } + else + { + $data['pape_policy_uris'] = array( + PAPE_AUTH_MULTI_FACTOR_PHYSICAL, + PAPE_AUTH_MULTI_FACTOR, + PAPE_AUTH_PHISHING_RESISTANT + ); + + $this->load->view('view_openid', $data); + } + } + + // Policy + function policy() + { + $this->load->view('openid_policy_view'); + } + + // set message + function _set_message($msg, $val = '', $sub = '%s') + { + return str_replace($sub, $val, $this->lang->line($msg)); + } + + // Check + function check() + { + $this->config->load('openid'); + $request_to = site_url($this->config->item('openid_request_to')); + + $this->openid->set_request_to($request_to); + $response = $this->openid->getResponse(); + + switch ($response->status) + { + case Auth_OpenID_CANCEL: + $data['msg'] = $this->lang->line('openid_cancel'); + break; + case Auth_OpenID_FAILURE: + $data['error'] = $this->_set_message('openid_failure', $response->message); + break; + case Auth_OpenID_SUCCESS: + $openid = $response->getDisplayIdentifier(); + $esc_identity = htmlspecialchars($openid, ENT_QUOTES); + + $data['success'] = $this->_set_message('openid_success', array($esc_identity, $esc_identity), array('%s', '%t')); + + if ($response->endpoint->canonicalID) + { + $data['success'] .= $this->_set_message('openid_canonical', $response->endpoint->canonicalID); + } + + $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); + $sreg = $sreg_resp->contents(); + + foreach ($sreg as $key => $value) + { + $data['success'] .= $this->_set_message('openid_content', array($key, $value), array('%s', '%t')); + } + + $pape_resp = Auth_OpenID_PAPE_Response::fromSuccessResponse($response); + + if ($pape_resp) + { + if ($pape_resp->auth_policies) + { + $data['success'] .= $this->lang->line('openid_pape_policies_affected'); + + foreach ($pape_resp->auth_policies as $uri) + { + $data['success'] .= "
  • $uri
  • "; + } + + $data['success'] .= ""; + } + else + { + $data['success'] .= $this->lang->line('openid_pape_not_affected'); + } + + if (isset($pape_resp->auth_age) && $pape_resp->auth_age) + { + $data['success'] .= $this->_set_message('openid_auth_age', $pape_resp->auth_age); + } + + if ($pape_resp->nist_auth_level) + { + $data['success'] .= $this->_set_message('openid_nist_level', $pape_resp->nist_auth_level); + } + } + else + { + $data['success'] .= $this->lang->line('openid_pape_noresponse'); + } + break; + } + + $data['pape_policy_uris'] = array( + PAPE_AUTH_MULTI_FACTOR_PHYSICAL, + PAPE_AUTH_MULTI_FACTOR, + PAPE_AUTH_PHISHING_RESISTANT + ); + +// echo "nickname: $nickname"; +// echo "esc_identity: $esc_identity"; + + $this->load->view('view_openid', $data); + } } + ?> diff --git a/application/controllers/user.php b/application/controllers/user.php index 8ebfdb3..5a9b779 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -41,8 +41,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 +80,30 @@ class User extends CI_Controller { } else { + 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')); + return; + } + + // Without OpenID if (! $this->activated_account) header('Location: ' . site_url("user/activate/{$this->user_id}")); @@ -86,6 +122,55 @@ 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) + { + case Auth_OpenID_CANCEL: + $this->load->helper('message'); + show_info_msg_page($this, $this->lang->line('openid_cancel')); + break; + case 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; + } + } + + 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. @@ -331,17 +416,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 +445,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 +490,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,16 +547,21 @@ 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) diff --git a/application/helpers/message_helper.php b/application/helpers/message_helper.php new file mode 100644 index 0000000..801a23e --- /dev/null +++ b/application/helpers/message_helper.php @@ -0,0 +1,60 @@ + $controller->lang->line("message_title_{$type}") + .' – ' + . $controller->config->item('site_name'), + //'metas' => array('description'=>'') + ); + $controller->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** + $controller->load->view('html_begin', $controller->html_head_params); + $controller->load->view('header', array()); + + $main_params['content'] = + $controller->load->view("message/{$type}_view", + array('msg'=> $msg), TRUE); + + $main_params['side'] = $controller->load->view('side_default', NULL, TRUE); + $controller->load->view('main', $main_params); + + $controller->load->view('footer'); + $controller->load->view('html_end'); +} + +/** + * Called from a controller to show an error message page. + * + * @param type $controller controller's object; pass $this from controller + * @param type $msg message text + */ +function show_error_msg_page($controller, $msg) +{ + show_msg_page($controller, 'error', $msg); +} + +/** + * Called from a controller to show an info message page. + * + * @param type $controller controller's object; pass $this from controller + * @param type $msg message text + */ +function show_info_msg_page($controller, $msg) +{ + show_msg_page($controller, 'info', $msg); +} + +/* End of file message_helper.php */ +/* Location: ./application/helpers/message_helper.php */ \ No newline at end of file diff --git a/application/language/english/openid_lang.php b/application/language/english/openid_lang.php index a21328f..ac2658e 100644 --- a/application/language/english/openid_lang.php +++ b/application/language/english/openid_lang.php @@ -1,5 +1,6 @@ %t as your identity.'; diff --git a/application/language/english/user_lang.php b/application/language/english/user_lang.php index 31285a6..a5ba105 100644 --- a/application/language/english/user_lang.php +++ b/application/language/english/user_lang.php @@ -3,8 +3,11 @@ $lang['user_appelation'] = 'User'; // Login / Register/ Account / Profile +$lang['user_legend_login_normal'] = 'Log in with a %s Account'; +$lang['user_legend_login_openid'] = 'Log in with a Third-party Account'; $lang['user_username'] = 'User Name'; $lang['user_username_or_email'] = 'User Name or E-mail'; +$lang['user_openid'] = 'OpenID'; $lang['user_password'] = 'Password'; $lang['user_password_confirmation'] = 'Password Confirmation'; $lang['user_old_password'] = 'Old Password'; diff --git a/application/libraries/Auth/OpenID.php b/application/libraries/Auth/OpenID.php index c9d9779..4576849 100644 --- a/application/libraries/Auth/OpenID.php +++ b/application/libraries/Auth/OpenID.php @@ -120,7 +120,7 @@ class Auth_OpenID { */ static function isFailure($thing) { - return is_a($thing, 'Auth_OpenID_FailureResponse'); + return is_a($thing, 'Auth_OpenID_FailureResponse'); } /** @@ -351,6 +351,8 @@ class Auth_OpenID { } return $url . $sep . Auth_OpenID::httpBuildQuery($args); + // Added by Calin-Andrei Burloiu. +// return $url .'/'. $sep . Auth_OpenID::httpBuildQuery($args); } /** diff --git a/application/libraries/Openid.php b/application/libraries/Openid.php index 6fa043d..0ac29e4 100644 --- a/application/libraries/Openid.php +++ b/application/libraries/Openid.php @@ -1,211 +1,232 @@ -config->load('openid'); - $this->storePath = $CI->config->item('openid_storepath'); - - session_start(); - $this->_doIncludes(); - - log_message('debug', "OpenID Class Initialized"); - } - - function _doIncludes() - { - set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); - - require_once "Auth/OpenID/Consumer.php"; - require_once "Auth/OpenID/FileStore.php"; - require_once "Auth/OpenID/SReg.php"; - require_once "Auth/OpenID/PAPE.php"; - } - - function set_sreg($enable, $required = null, $optional = null, $policy = null) - { - $this->sreg_enable = $enable; - $this->sreg_required = $required; - $this->sreg_optional = $optional; - $this->sreg_policy = $policy; - } - - function set_pape($enable, $policy_uris = null) - { - $this->pape_enable = $enable; - $this->pape_policy_uris = $policy_uris; - } - - function set_request_to($uri) - { - $this->request_to = $uri; - } - - function set_trust_root($trust_root) - { - $this->trust_root = $trust_root; - } - - function set_args($args) - { - $this->ext_args = $args; - } - - function _set_message($error, $msg, $val = '', $sub = '%s') - { - $CI =& get_instance(); - $CI->lang->load('openid', 'english'); - echo str_replace($sub, $val, $CI->lang->line($msg)); - - if ($error) - { - exit; - } - } - - function authenticate($openId) - { - $consumer = $this->_getConsumer(); - $authRequest = $consumer->begin($openId); - - // No auth request means we can't begin OpenID. - if (!$authRequest) - { - $this->_set_message(true,'openid_auth_error'); - } - - if ($this->sreg_enable) - { - $sreg_request = Auth_OpenID_SRegRequest::build($this->sreg_required, $this->sreg_optional, $this->sreg_policy); - - if ($sreg_request) - { - $authRequest->addExtension($sreg_request); - } - else - { - $this->_set_message(true,'openid_sreg_failed'); - } - } - - if ($this->pape_enable) - { - $pape_request = new Auth_OpenID_PAPE_Request($this->pape_policy_uris); - - if ($pape_request) - { - $authRequest->addExtension($pape_request); - } - else - { - $this->_set_message(true,'openid_pape_failed'); - } - } - - if ($this->ext_args != null) - { - foreach ($this->ext_args as $extensionArgument) - { - if (count($extensionArgument) == 3) - { - $authRequest->addExtensionArg($extensionArgument[0], $extensionArgument[1], $extensionArgument[2]); - } - } - } - - // Redirect the user to the OpenID server for authentication. - // Store the token for this authentication so we can verify the - // response. - - // For OpenID 1, send a redirect. For OpenID 2, use a Javascript - // form to send a POST request to the server. - if ($authRequest->shouldSendRedirect()) - { - $redirect_url = $authRequest->redirectURL($this->trust_root, $this->request_to); - - // If the redirect URL can't be built, display an error - // message. - if (Auth_OpenID::isFailure($redirect_url)) - { - $this->_set_message(true,'openid_redirect_failed', $redirect_url->message); - } - else - { - // Send redirect. - header("Location: ".$redirect_url); - } - } - else - { - // Generate form markup and render it. - $form_id = 'openid_message'; - $form_html = $authRequest->formMarkup($this->trust_root, $this->request_to, false, array('id' => $form_id)); - - // Display an error if the form markup couldn't be generated; - // otherwise, render the HTML. - if (Auth_OpenID::isFailure($form_html)) - { - $this->_set_message(true,'openid_redirect_failed', $form_html->message); - } - else - { - $page_contents = array( - "", - "OpenID transaction in progress", - "", - "", - $form_html, - ""); - - print implode("\n", $page_contents); - } - } - - } - - function getResponse() - { - $consumer = $this->_getConsumer(); - $response = $consumer->complete($this->request_to); - - return $response; - } - - function _getConsumer() - { - if (!file_exists($this->storePath) && !mkdir($this->storePath)) - { - $this->_set_message(true,'openid_storepath_failed', $this->storePath); - } - - $store = new Auth_OpenID_FileStore($this->storePath); - $consumer = new Auth_OpenID_Consumer($store); - - return $consumer; - } + * OpenID Library + * + * @package CodeIgniter + * @author bardelot, Călin-Andrei Burloiu + * @see http://cakebaker.42dh.com/2007/01/11/cakephp-and-openid/ + * & http://openidenabled.com/php-openid/ + */ +class Openid { + + var $storePath = 'tmp'; + var $sreg_enable = FALSE; + var $sreg_required = NULL; + var $sreg_optional = NULL; + var $sreg_policy = NULL; + var $pape_enable = FALSE; + var $pape_policy_uris = NULL; + var $ext_args = NULL; + var $request_to; + var $trust_root; + + function __construct() + { + $CI = & get_instance(); + $CI->config->load('openid'); + $this->storePath = $CI->config->item('openid_storepath'); + + session_start(); + $this->_do_includes(); + + log_message('debug', "OpenID Class Initialized"); + } + + function _do_includes() + { + set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); + + require_once "Auth/OpenID/Consumer.php"; + require_once "Auth/OpenID/FileStore.php"; + require_once "Auth/OpenID/SReg.php"; + require_once "Auth/OpenID/AX.php"; + require_once "Auth/OpenID/PAPE.php"; + } + + function set_sreg($enable, $required = NULL, $optional = NULL, $policy = NULL) + { + $this->sreg_enable = $enable; + $this->sreg_required = $required; + $this->sreg_optional = $optional; + $this->sreg_policy = $policy; + } + + function set_pape($enable, $policy_uris = NULL) + { + $this->pape_enable = $enable; + $this->pape_policy_uris = $policy_uris; + } + + function set_request_to($uri) + { + $this->request_to = $uri; + } + + function set_trust_root($trust_root) + { + $this->trust_root = $trust_root; + } + + function set_args($args) + { + $this->ext_args = $args; + } + + function _set_message($error, $msg, $val = '', $sub = '%s') + { + $CI = & get_instance(); + $CI->lang->load('openid', 'english'); + echo str_replace($sub, $val, $CI->lang->line($msg)); + + if ($error) + { + exit; + } + } + + function authenticate($openId) + { + $consumer = $this->_get_consumer(); + $authRequest = $consumer->begin($openId); + + // No auth request means we can't begin OpenID. + if (!$authRequest) + { + $this->_set_message(TRUE, 'openid_auth_error'); + } + + if ($this->sreg_enable) + { + $sreg_request = Auth_OpenID_SRegRequest::build( + $this->sreg_required, $this->sreg_optional, + $this->sreg_policy); + + if ($sreg_request) + { + $authRequest->addExtension($sreg_request); + } + else + { + $this->_set_message(TRUE, 'openid_sreg_failed'); + } + } + + + + // *** TODO *** + + // Create attribute request object + // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters + // Usage: make($type_uri, $count=1, $required=false, $alias=null) + $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/contact/email',2,1, 'email'); + $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/first',1,1, 'firstname'); + $attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/last',1,1, 'lastname'); + + // Create AX fetch request + $ax = new Auth_OpenID_AX_FetchRequest; + + // Add attributes to AX fetch request + foreach($attribute as $attr){ + $ax->add($attr); + } + + // Add AX fetch request to authentication request + $authRequest->addExtension($ax); + + + + if ($this->pape_enable) + { + $pape_request = new Auth_OpenID_PAPE_Request($this->pape_policy_uris); + + if ($pape_request) + { + $authRequest->addExtension($pape_request); + } + else + { + $this->_set_message(TRUE, 'openid_pape_failed'); + } + } + + if ($this->ext_args != NULL) + { + foreach ($this->ext_args as $extensionArgument) + { + if (count($extensionArgument) == 3) + { + $authRequest->addExtensionArg($extensionArgument[0], + $extensionArgument[1], + $extensionArgument[2]); + } + } + } + + // Redirect the user to the OpenID server for authentication. + // Store the token for this authentication so we can verify the + // response. + // For OpenID 1, send a redirect. For OpenID 2, use a Javascript + // form to send a POST request to the server. + if ($authRequest->shouldSendRedirect()) + { + $redirect_url = $authRequest->redirectURL($this->trust_root, + $this->request_to); + + // If the redirect URL can't be built, display an error + // message. + if (Auth_OpenID::isFailure($redirect_url)) + { + $this->_set_message(TRUE, 'openid_redirect_failed', $redirect_url->message); + } + else + { + // Send redirect. + header("Location: " . $redirect_url); + } + } + else + { + // Generate form markup and render it. + $form_id = 'openid_message'; + $form_html = $authRequest->htmlMarkup($this->trust_root, + $this->request_to, FALSE, array('id' => $form_id)); + + // Display an error if the form markup couldn't be generated; + // otherwise, render the HTML. + if (Auth_OpenID::isFailure($form_html)) + { + $this->_set_message(TRUE, 'openid_redirect_failed', $form_html->message); + } + else + { + print $form_html; + } + } + } + + function get_response() + { + $consumer = $this->_get_consumer(); + $response = $consumer->complete($this->request_to); + + return $response; + } + + function _get_consumer() + { + if (!file_exists($this->storePath) && !mkdir($this->storePath)) + { + $this->_set_message(TRUE, 'openid_storepath_failed', $this->storePath); + } + + $store = new Auth_OpenID_FileStore($this->storePath); + $consumer = new Auth_OpenID_Consumer($store); + + return $consumer; + } + } -?> diff --git a/application/views/view_policy.php b/application/views/openid_policy_view.php similarity index 100% rename from application/views/view_policy.php rename to application/views/openid_policy_view.php diff --git a/application/views/user/activated_account_view.php b/application/views/user/activated_account_view.php deleted file mode 100644 index 9049a54..0000000 --- a/application/views/user/activated_account_view.php +++ /dev/null @@ -1,2 +0,0 @@ -

    lang->line('user_msg_activated_account'), - site_url('user/login')) ?>

    \ No newline at end of file diff --git a/application/views/user/login_view.php b/application/views/user/login_view.php index b066866..265672b 100644 --- a/application/views/user/login_view.php +++ b/application/views/user/login_view.php @@ -1,36 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
    lang->line('user_username_or_email'). ': ' ?> - -
    lang->line('user_password'). ': ' ?> - -
    - -
    -

    lang->line('user_link_password_recovery') ?>

    -
    +
    + lang->line('user_legend_login_normal'), $this->config->item('site_name')) ?> + + + + + + + + + + + + + + + + + + + + + + + + + + +
    lang->line('user_username_or_email'). ': ' ?> + +
    lang->line('user_password'). ': ' ?> + +
    + +
    +

    lang->line('user_link_password_recovery') ?>

    +
    +
    + + + +
    + lang->line('user_legend_login_openid') ?> + + + + + + + + + + + + + + + +
    lang->line('user_openid'). ': ' ?> + +
    + +
    +
    \ No newline at end of file diff --git a/application/views/view_openid.php b/application/views/view_openid.php index d4c65e0..d079584 100644 --- a/application/views/view_openid.php +++ b/application/views/view_openid.php @@ -1,5 +1,5 @@ - PHP OpenID Authentication Example + PHP OpenID Authentication Example +

    PHP OpenID Authentication Example

    diff --git a/nbproject/netbeans_ci_code_completion.php b/nbproject/netbeans_ci_code_completion.php new file mode 100644 index 0000000..fbdf075 --- /dev/null +++ b/nbproject/netbeans_ci_code_completion.php @@ -0,0 +1,103 @@ + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..6ffde2f --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_5 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=true +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..c1fc066 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + P2P-Tube + + + -- 2.20.1