{"action":"created","comment":{"url":"https://api.github.com/repos/anph/test_sideci/pulls/comments/92137539","pull_request_review_id":12645674,"id":92137539,"diff_hunk":"@@ -0,0 +1,1561 @@\n+<?php\n+\n+if (!defined('BASEPATH'))\n+\texit('No direct script access allowed');\n+\n+/**\n+ * DX Auth Class\n+ *\n+ * Authentication library for Code Igniter.\n+ *\n+ * @author\t\tDexcell\n+ * @version\t\t1.0.6\n+ * @based on\tCL Auth by Jason Ashdown (http://http://www.jasonashdown.co.uk/)\n+ * @link\t\t\thttp://dexcell.shinsengumiteam.com/dx_auth\n+ * @license\t\tMIT License Copyright (c) 2008 Erick Hartanto\n+ * @credits\t\thttp://dexcell.shinsengumiteam.com/dx_auth/general/credits.html\n+ */\n+class DX_Auth_User\n+{\n+\n+\t// Private\n+\tvar $_banned;\n+\tvar $_ban_reason;\n+\tvar $_auth_error; // Contain user error when login\n+\tvar $_captcha_image;\n+\n+\n+\tfunction DX_Auth_User()\n+\t{\n+\n+\t\t$this->ci = & get_instance();\n+\n+\t\tlog_message('debug', 'DX Auth Initialized');\n+\n+\t\t// Load required library\n+\t\t$this->ci->load->library('Session');\n+\t\t$this->ci->load->database();\n+\n+\t\t// Load DX Auth config\n+\t\t$this->ci->load->config('dx_auth_user');\n+\n+\t\t// Load DX Auth language\n+\t\t$this->ci->lang->load('dx_auth_user');\n+\n+\t\t// Load DX Auth event\n+\t\t$this->ci->load->library('DX_Auth_Event');\n+\n+\t\t// Initialize\n+\t\t$this->_init();\n+\t}\n+\n+\t/* Private function */\n+\n+\tfunction _init()\n+\t{\n+\t\t// When we load this library, auto Login any returning users\n+\t\t$this->autologin();\n+\n+\t\t// Init helper config variable\n+\t\t$this->email_activation = $this->ci->config->item('DX_email_activation');\n+\n+\t\t$this->allow_registration = $this->ci->config->item('DX_allow_registration');\n+\t\t$this->captcha_registration = $this->ci->config->item('DX_captcha_registration');\n+\n+\t\t$this->captcha_login = $this->ci->config->item('DX_captcha_login');\n+\n+\t\t// URIs\n+\t\t$this->banned_uri = $this->ci->config->item('DX_banned_uri');\n+\t\t$this->deny_uri = $this->ci->config->item('DX_deny_uri');\n+\t\t$this->login_uri = $this->ci->config->item('DX_login_uri');\n+\t\t$this->logout_uri = $this->ci->config->item('DX_logout_uri');\n+\t\t$this->register_uri = $this->ci->config->item('DX_register_uri');\n+\t\t$this->activate_uri = $this->ci->config->item('DX_activate_uri');\n+\t\t$this->forgot_password_uri = $this->ci->config->item('DX_forgot_password_uri');\n+\t\t$this->reset_password_uri = $this->ci->config->item('DX_reset_password_uri');\n+\t\t$this->change_password_uri = $this->ci->config->item('DX_change_password_uri');\n+\t\t$this->cancel_account_uri = $this->ci->config->item('DX_cancel_account_uri');\n+\n+\t\t// Forms view\n+\t\t$this->login_view = $this->ci->config->item('DX_login_view');\n+\t\t$this->register_view = $this->ci->config->item('DX_register_view');\n+\t\t$this->forgot_password_view = $this->ci->config->item('DX_forgot_password_view');\n+\t\t$this->change_password_view = $this->ci->config->item('DX_change_password_view');\n+\t\t$this->cancel_account_view = $this->ci->config->item('DX_cancel_account_view');\n+\n+\t\t// Pages view\n+\t\t$this->deny_view = $this->ci->config->item('DX_deny_view');\n+\t\t$this->banned_view = $this->ci->config->item('DX_banned_view');\n+\t\t$this->logged_in_view = $this->ci->config->item('DX_logged_in_view');\n+\t\t$this->logout_view = $this->ci->config->item('DX_logout_view');\n+\n+\t\t$this->register_success_view = $this->ci->config->item('DX_register_success_view');\n+\t\t$this->activate_success_view = $this->ci->config->item('DX_activate_success_view');\n+\t\t$this->forgot_password_success_view = $this->ci->config->item('DX_forgot_password_success_view');\n+\t\t$this->reset_password_success_view = $this->ci->config->item('DX_reset_password_success_view');\n+\t\t$this->change_password_success_view = $this->ci->config->item('DX_change_password_success_view');\n+\n+\t\t$this->register_disabled_view = $this->ci->config->item('DX_register_disabled_view');\n+\t\t$this->activate_failed_view = $this->ci->config->item('DX_activate_failed_view');\n+\t\t$this->reset_password_failed_view = $this->ci->config->item('DX_reset_password_failed_view');\n+\t}\n+\n+\tfunction _gen_pass($len = 8)\n+\t{\n+\t\t// No Zero (for user clarity);\n+\t\t$pool = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n+\n+\t\t$str = '';\n+\t\tfor ($i = 0; $i < $len; $i++)\n+\t\t{\n+\t\t\t$str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);\n+\t\t}\n+\n+\t\treturn $str;\n+\t}\n+\n+\t/*\n+\t * Function: _encode\n+\t * Modified for DX_Auth\n+\t * Original Author: FreakAuth_light 1.1\n+\t */\n+\n+\tfunction _encode($password)\n+\t{\n+\t\t$majorsalt = $this->ci->config->item('DX_salt');\n+\n+\t\t// if PHP5\n+\t\tif (function_exists('str_split'))\n+\t\t{\n+\t\t\t$_pass = str_split($password);\n+\t\t}\n+\t\t// if PHP4\n+\t\telse\n+\t\t{\n+\t\t\t$_pass = array();\n+\t\t\tif (is_string($password))\n+\t\t\t{\n+\t\t\t\tfor ($i = 0; $i < strlen($password); $i++)\n+\t\t\t\t{\n+\t\t\t\t\tarray_push($_pass, $password[$i]);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\t// encrypts every single letter of the password\n+\t\tforeach ($_pass as $_hashpass)\n+\t\t{\n+\t\t\t$majorsalt .= md5($_hashpass);\n+\t\t}\n+\n+\t\t// encrypts the string combinations of every single encrypted letter\n+\t\t// and finally returns the encrypted password\n+\t\treturn md5($majorsalt);\n+\t}\n+\n+\tfunction _array_in_array($needle, $haystack)\n+\t{\n+\t\t// Make sure $needle is an array for foreach\n+\t\tif (!is_array($needle))\n+\t\t{\n+\t\t\t$needle = array($needle);\n+\t\t}\n+\n+\t\t// For each value in $needle, return TRUE if in $haystack\n+\t\tforeach ($needle as $pin)\n+\t\t{\n+\t\t\tif (in_array($pin, $haystack))\n+\t\t\t\treturn TRUE;\n+\t\t}\n+\t\t// Return FALSE if none of the values from $needle are found in $haystack\n+\t\treturn FALSE;\n+\t}\n+\n+\t/*\n+\t  function _email($to, $from, $subject, $message)\n+\t  {\n+\t  $this->ci->load->library('qdmail');\n+\n+\t  $subject  = $subject;\n+\t  $body     = $message;\n+\t  $fromname = $from;\n+\t  $reply_to = $from;\n+\t  $from     = $from;\n+\t  $to       = $to;\n+\n+\t  //半角カナを変換\n+\t  $body = mb_convert_kana($body , \"KV\" , 'UTF8');\n+\t  $subject = mb_convert_kana($subject , \"KV\" , 'UTF8');\n+\n+\t  mb_language(\"Ja\");\n+\t  mb_internal_encoding(\"UTF8\");\n+\n+\t  $parameter ='-f '.$reply_to;\n+\t  $option = array(\n+\t  'type'=>'text',\n+\t  'option'=>array(\n+\t  'mtaOption'=>$parameter\n+\t  )\n+\t  );\n+\n+\t  $var['from'] = array(\"$from\",\"$fromname\");\n+\t  $var['reply-to'] = array(\"$reply_to\",\"$fromname\");\n+\n+\t  //送信\n+\t  if(qd_send_mail($option,$to,\"$subject\",\"$body\",$var))\n+\t  {\n+\t  return true;\n+\t  }\n+\t  else\n+\t  {\n+\t  return false;\n+\t  }\n+\t  }\n+\t *\n+\t */\n+\n+\tfunction _email($to, $from, $subject, $message)\n+\t{\n+\n+\t\t$this->ci->load->library('qdmail');\n+\n+        $subject  = $subject;\n+        $body     = $message;\n+        $fromname = $from;\n+        $reply_to = $from;\n+        $from     = $from;\n+        $to       = $to;\n+\n+        //半角カナを変換\n+        $body = mb_convert_kana($body , \"KV\" , 'UTF8');\n+        $subject = mb_convert_kana($subject , \"KV\" , 'UTF8');\n+\n+        mb_language(\"Ja\");\n+        mb_internal_encoding(\"UTF8\");\n+\n+        $parameter ='-f '.$reply_to;\n+        $option = array(\n+            'type'=>'text',\n+            'option'=>array(\n+                'mtaOption'=>$parameter\n+            )\n+        );\n+\n+        $var['from'] = array(\"$from\",\"$fromname\");\n+        $var['reply-to'] = array(\"$reply_to\",\"$fromname\");\n+\n+        //送信\n+        if(qd_send_mail($option,$to,\"$subject\",\"$body\",$var))\n+        {\n+            return true;\n+        }\n+        else\n+        {\n+            return false;\n+        }\n+\n+\n+\n+\n+\t\t/*\n+\t\t// $this->ci->load->library('qdmail');\n+\t\t$subject = $subject;\n+\t\t$body = $message;\n+\t\t$fromname = SITE_NAME;\n+\t\t$from = $from;\n+\t\t$to = $to;\n+\n+\t\t//半角カナを変換\n+\t\t$body = mb_convert_kana($body, \"KV\", 'UTF8');\n+\t\t$subject = mb_convert_kana($subject, \"KV\", 'UTF8');\n+\n+\t\tmb_language(\"Ja\");\n+\t\tmb_internal_encoding(\"UTF8\");\n+\n+\t\t$this->ci->mail_send_smtp($to, $subject, $body, $fromname, $from);\n+\n+\t\t*/\n+\t}\n+\n+\t// Set last ip and last login function when user login\n+\tfunction _set_last_ip_and_last_login($user_id)\n+\t{\n+\t\t$data = array();\n+\n+\t\tif ($this->ci->config->item('DX_login_record_ip'))\n+\t\t{\n+\t\t\t$data['last_ip'] = $this->ci->input->ip_address();\n+\t\t}\n+\n+\t\tif ($this->ci->config->item('DX_login_record_time'))\n+\t\t{\n+\t\t\t$data['last_login'] = date('Y-m-d H:i:s', time());\n+\t\t}\n+\n+\t\tif (!empty($data))\n+\t\t{\n+\t\t\t// Load model\n+\t\t\t$this->ci->load->model('dx_auth/users', 'users');\n+\t\t\t// Update record\n+\t\t\t$this->ci->users->set_user($user_id, $data);\n+\t\t}\n+\t}\n+\n+\t// Increase login attempt\n+\tfunction _increase_login_attempt()\n+\t{\n+\t\tif ($this->ci->config->item('DX_count_login_attempts') AND ! $this->is_max_login_attempts_exceeded())\n+\t\t{\n+\t\t\t// Load model\n+\t\t\t$this->ci->load->model('dx_auth/login_attempts', 'login_attempts');\n+\t\t\t// Increase login attempts for current IP\n+\t\t\t$this->ci->login_attempts->increase_attempt($this->ci->input->ip_address());\n+\t\t}\n+\t}\n+\n+\t// Clear login attempts\n+\tfunction _clear_login_attempts()\n+\t{\n+\t\tif ($this->ci->config->item('DX_count_login_attempts'))\n+\t\t{\n+\t\t\t// Load model\n+\t\t\t$this->ci->load->model('dx_auth/login_attempts', 'login_attempts');\n+\t\t\t// Clear login attempts for current IP\n+\t\t\t$this->ci->login_attempts->clear_attempts($this->ci->input->ip_address());\n+\t\t}\n+\t}\n+\n+\t// Get role data from database by id, used in _set_session() function\n+\t// $parent_roles_id, $parent_roles_name is an array.\n+\tfunction _get_role_data($role_id)\n+\t{\n+\t\t// Load models\n+\t\t$this->ci->load->model('dx_auth/roles', 'roles');\n+\t\t$this->ci->load->model('dx_auth/permissions', 'permissions');\n+\n+\t\t// Clear return value\n+\t\t$role_name = '';\n+\t\t$parent_roles_id = array();\n+\t\t$parent_roles_name = array();\n+\t\t$permission = array();\n+\t\t$parent_permissions = array();\n+\n+\t\t/* Get role_name, parent_roles_id and parent_roles_name */\n+\n+\t\t// Get role query from role id\n+\t\t$query = $this->ci->roles->get_role_by_id($role_id);\n+\n+\t\t// Check if role exist\n+\t\tif ($query->num_rows() > 0)\n+\t\t{\n+\t\t\t// Get row\n+\t\t\t$role = $query->row();\n+\n+\t\t\t// Get role name\n+\t\t\t$role_name = $role->name;\n+\n+\t\t\t/*\n+\t\t\t  Code below will search if user role_id have parent_id > 0 (which mean role_id have parent role_id)\n+\t\t\t  and do it recursively until parent_id reach 0 (no parent) or parent_id not found.\n+\n+\t\t\t  If anyone have better approach than this code, please let me know.\n+\t\t\t */\n+\n+\t\t\t// Check if role has parent id\n+\t\t\tif ($role->parent_id > 0)\n+\t\t\t{\n+\t\t\t\t// Add to result array\n+\t\t\t\t$parent_roles_id[] = $role->parent_id;\n+\n+\t\t\t\t// Set variable used in looping\n+\t\t\t\t$finished = FALSE;\n+\t\t\t\t$parent_id = $role->parent_id;\n+\n+\t\t\t\t// Get all parent id\n+\t\t\t\twhile ($finished == FALSE)\n+\t\t\t\t{\n+\t\t\t\t\t$i_query = $this->ci->roles->get_role_by_id($parent_id);\n+\n+\t\t\t\t\t// If role exist\n+\t\t\t\t\tif ($i_query->num_rows() > 0)\n+\t\t\t\t\t{\n+\t\t\t\t\t\t// Get row\n+\t\t\t\t\t\t$i_role = $i_query->row();\n+\n+\t\t\t\t\t\t// Check if role doesn't have parent\n+\t\t\t\t\t\tif ($i_role->parent_id == 0)\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\t// Get latest parent name\n+\t\t\t\t\t\t\t$parent_roles_name[] = $i_role->name;\n+\t\t\t\t\t\t\t// Stop looping\n+\t\t\t\t\t\t\t$finished = TRUE;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\telse\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\t// Change parent id for next looping\n+\t\t\t\t\t\t\t$parent_id = $i_role->parent_id;\n+\n+\t\t\t\t\t\t\t// Add to result array\n+\t\t\t\t\t\t\t$parent_roles_id[] = $parent_id;\n+\t\t\t\t\t\t\t$parent_roles_name[] = $i_role->name;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t\telse\n+\t\t\t\t\t{\n+\t\t\t\t\t\t// Remove latest parent_roles_id since parent_id not found\n+\t\t\t\t\t\tarray_pop($parent_roles_id);\n+\t\t\t\t\t\t// Stop looping\n+\t\t\t\t\t\t$finished = TRUE;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* End of Get role_name, parent_roles_id and parent_roles_name */\n+\n+\t\t/* Get user and parents permission */\n+\n+\t\t// Get user role permission\n+\t\t$permission = $this->ci->permissions->get_permission_data($role_id);\n+\n+\t\t// Get user role parent permissions\n+\t\tif (!empty($parent_roles_id))\n+\t\t{\n+\t\t\t$parent_permissions = $this->ci->permissions->get_permissions_data($parent_roles_id);\n+\t\t}\n+\n+\t\t/* End of Get user and parents permission */\n+\n+\t\t// Set return value\n+\t\t$data['role_name'] = $role_name;\n+\t\t$data['parent_roles_id'] = $parent_roles_id;\n+\t\t$data['parent_roles_name'] = $parent_roles_name;\n+\t\t$data['permission'] = $permission;\n+\t\t$data['parent_permissions'] = $parent_permissions;\n+\n+\t\treturn $data;\n+\t}\n+\n+\t/* Autologin related function */\n+\n+\tfunction _create_autologin($user_id)\n+\t{\n+\t\t$result = FALSE;\n+\n+\t\t// User wants to be remembered\n+\t\t$user = array(\n+\t\t\t'key_id' => substr(md5(uniqid(rand() . $this->ci->input->cookie($this->ci->config->item('sess_cookie_name')))), 0, 16),\n+\t\t\t'user_id' => $user_id\n+\t\t);\n+\n+\t\t// Load Models\n+\t\t$this->ci->load->model('dx_auth/user_autologin', 'user_autologin');\n+\n+\t\t// Prune keys\n+\t\t$this->ci->user_autologin->prune_keys($user['user_id']);\n+\n+\t\tif ($this->ci->user_autologin->store_key($user['key_id'], $user['user_id']))\n+\t\t{\n+\t\t\t// Set Users AutoLogin cookie\n+\t\t\t$this->_auto_cookie($user);\n+\n+\t\t\t$result = TRUE;\n+\t\t}\n+\n+\t\treturn $result;\n+\t}\n+\n+\tfunction autologin()\n+\t{\n+\t\t$result = FALSE;\n+\n+\t\tif ($auto = $this->ci->input->cookie($this->ci->config->item('DX_autologin_cookie_name')) AND ! $this->ci->session->userdata('DX_logged_in_user'))\n+\t\t{\n+\t\t\t// Extract data\n+\t\t\t$auto = unserialize($auto);\n+\n+\t\t\tif (isset($auto['key_id']) AND $auto['key_id'] AND $auto['user_id'])\n+\t\t\t{\n+\t\t\t\t// Load Models\n+\t\t\t\t$this->ci->load->model('dx_auth/user_autologin', 'user_autologin');\n+\n+\t\t\t\t// Get key\n+\t\t\t\t$query = $this->ci->user_autologin->get_key($auto['key_id'], $auto['user_id']);\n+\n+\t\t\t\tif ($result = $query->row())\n+\t\t\t\t{\n+\t\t\t\t\t// User verified, log them in\n+\t\t\t\t\t$this->_set_session($result);\n+\t\t\t\t\t// Renew users cookie to prevent it from expiring\n+\t\t\t\t\t$this->_auto_cookie($auto);\n+\n+\t\t\t\t\t// Set last ip and last login\n+\t\t\t\t\t$this->_set_last_ip_and_last_login($auto['user_id']);\n+\n+\t\t\t\t\t$result = TRUE;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn $result;\n+\t}\n+\n+\tfunction _delete_autologin()\n+\t{\n+\t\tif ($auto = $this->ci->input->cookie($this->ci->config->item('DX_autologin_cookie_name')))\n+\t\t{\n+\t\t\t// Load Cookie Helper\n+\t\t\t$this->ci->load->helper('cookie');\n+\n+\t\t\t// Load Models\n+\t\t\t$this->ci->load->model('dx_auth/user_autologin', 'user_autologin');\n+\n+\t\t\t// Extract data\n+\t\t\t$auto = unserialize($auto);\n+\n+\t\t\t// Delete db entry\n+\t\t\t$this->ci->user_autologin->delete_key($auto['key_id'], $auto['user_id']);\n+\n+\t\t\t// Make cookie expired\n+\t\t\tset_cookie($this->ci->config->item('DX_autologin_cookie_name'), '', -1);\n+\t\t}\n+\t}\n+\n+\tfunction _set_session($data)\n+\t{\n+\t\t// Get role data\n+\t\t$role_data = $this->_get_role_data($data->role_id);\n+\n+\t\t// Set session data array\n+\t\t$user = array(\n+\t\t\t'DX_user_id_user' => $data->id,\n+\t\t\t'DX_username_user' => $data->username,\n+\t\t\t'DX_role_id_user' => $data->role_id,\n+\t\t\t'DX_role_name_user' => $role_data['role_name'],\n+\t\t\t'DX_parent_roles_id_user' => $role_data['parent_roles_id'], // Array of parent role_id\n+\t\t\t'DX_parent_roles_name_user' => $role_data['parent_roles_name'], // Array of parent role_name\n+\t\t\t'DX_permission_user' => $role_data['permission'],\n+\t\t\t'DX_parent_permissions_user' => $role_data['parent_permissions'],\n+\t\t\t'DX_logged_in_user' => TRUE\n+\t\t);\n+\n+\t\t$this->ci->session->set_userdata($user);\n+\t}\n+\n+\tfunction _auto_cookie($data)\n+\t{\n+\t\t// Load Cookie Helper\n+\t\t$this->ci->load->helper('cookie');\n+\n+\t\t$cookie = array(\n+\t\t\t'name' => $this->ci->config->item('DX_autologin_cookie_name'),\n+\t\t\t'value' => serialize($data),\n+\t\t\t'expire' => $this->ci->config->item('DX_autologin_cookie_life')\n+\t\t);\n+\n+\t\tset_cookie($cookie);\n+\t}\n+\n+\t/* End of Auto login related function */\n+\n+\t/* Helper function */\n+\n+\tfunction check_uri_permissions($allow = TRUE)\n+\t{\n+\t\t// First check if user already logged in or not\n+\t\tif ($this->is_logged_in())\n+\t\t{\n+\t\t\t// If user is not admin\n+\t\t\tif (!$this->is_admin())\n+\t\t\t{\n+\t\t\t\t// Get variable from current URI\n+\t\t\t\t$controller = '/' . $this->ci->uri->rsegment(1) . '/';\n+\t\t\t\tif ($this->ci->uri->rsegment(2) != '')\n+\t\t\t\t{\n+\t\t\t\t\t$action = $controller . $this->ci->uri->rsegment(2) . '/';\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t{\n+\t\t\t\t\t$action = $controller . 'index/';\n+\t\t\t\t}\n+\n+\t\t\t\t// Get URI permissions from role and all parents\n+\t\t\t\t// Note: URI permissions is saved in 'uri' key\n+\t\t\t\t$roles_allowed_uris = $this->get_permissions_value('uri');\n+\n+\t\t\t\t// Variable to determine if URI found\n+\t\t\t\t$have_access = !$allow;\n+\t\t\t\t// Loop each roles URI permissions\n+\t\t\t\tforeach ($roles_allowed_uris as $allowed_uris)\n+\t\t\t\t{\n+\t\t\t\t\tif ($allowed_uris != NULL)\n+\t\t\t\t\t{\n+\t\t\t\t\t\t// Check if user allowed to access URI\n+\t\t\t\t\t\tif ($this->_array_in_array(array('/', $controller, $action), $allowed_uris))\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\t$have_access = $allow;\n+\t\t\t\t\t\t\t// Stop loop\n+\t\t\t\t\t\t\tbreak;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\t\t\t\t// Trigger event\n+\t\t\t\t$this->ci->dx_auth_event->checked_uri_permissions($this->get_user_id(), $have_access);\n+\n+\t\t\t\tif (!$have_access)\n+\t\t\t\t{\n+\t\t\t\t\t// User didn't have previlege to access current URI, so we show user 403 forbidden access\n+\t\t\t\t\t$this->deny_access();\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\t// User haven't logged in, so just redirect user to login page\n+\t\t\t$this->deny_access('login');\n+\t\t}\n+\t}\n+\n+\t/*\n+\t  Get permission value from specified key.\n+\t  Call this function only when user is logged in already.\n+\t  $key is permission array key (Note: permissions is saved as array in table).\n+\t  If $check_parent is TRUE means if permission value not found in user role, it will try to get permission value from parent role.\n+\t  Returning value if permission found, otherwise returning NULL\n+\t */\n+\n+\tfunction get_permission_value($key, $check_parent = TRUE)\n+\t{\n+\t\t// Default return value\n+\t\t$result = NULL;\n+\n+\t\t// Get current user permission\n+\t\t$permission = $this->ci->session->userdata('DX_permission_user');\n+\n+\t\t// Check if key is in user permission array\n+\t\tif (array_key_exists($key, $permission))\n+\t\t{\n+\t\t\t$result = $permission[$key];\n+\t\t}\n+\t\t// Key not found\n+\t\telse\n+\t\t{\n+\t\t\tif ($check_parent)\n+\t\t\t{\n+\t\t\t\t// Get current user parent permissions\n+\t\t\t\t$parent_permissions = $this->ci->session->userdata('DX_parent_permissions_user');\n+\n+\t\t\t\t// Check parent permissions array\n+\t\t\t\tforeach ($parent_permissions as $permission)\n+\t\t\t\t{\n+\t\t\t\t\tif (array_key_exists($key, $permission))\n+\t\t\t\t\t{\n+\t\t\t\t\t\t$result = $permission[$key];\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\t// Trigger event\n+\t\t$this->ci->dx_auth_event->got_permission_value($this->get_user_id(), $key);\n+\n+\t\treturn $result;\n+\t}\n+\n+\t/*\n+\t  Get permissions value from specified key.\n+\t  Call this function only when user is logged in already.\n+\t  This will get user permission, and it's parents permissions.\n+\n+\t  $array_key = 'default'. Array ordered using 0, 1, 2 as array key.\n+\t  $array_key = 'role_id'. Array ordered using role_id as array key.\n+\t  $array_key = 'role_name'. Array ordered using role_name as array key.\n+\n+\t  Returning array of value if permission found, otherwise returning NULL.\n+\t */\n+\n+\tfunction get_permissions_value($key, $array_key = 'default')\n+\t{\n+\t\t$result = array();\n+\n+\t\t$role_id = $this->ci->session->userdata('DX_role_id_user');\n+\t\t$role_name = $this->ci->session->userdata('DX_role_name_user');\n+\n+\t\t$parent_roles_id = $this->ci->session->userdata('DX_parent_roles_id_user');\n+\t\t$parent_roles_name = $this->ci->session->userdata('DX_parent_roles_name_user');\n+\n+\t\t// Get current user permission\n+\t\t$value = $this->get_permission_value($key, FALSE);\n+\n+\t\tif ($array_key == 'role_id')\n+\t\t{\n+\t\t\t$result[$role_id] = $value;\n+\t\t}\n+\t\telseif ($array_key == 'role_name')\n+\t\t{\n+\t\t\t$result[$role_name] = $value;\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\tarray_push($result, $value);\n+\t\t}\n+\n+\t\t// Get current user parent permissions\n+\t\t$parent_permissions = $this->ci->session->userdata('DX_parent_permissions_user');\n+\n+\t\t$i = 0;\n+\t\tforeach ($parent_permissions as $permission)\n+\t\t{\n+\t\t\tif (array_key_exists($key, $permission))\n+\t\t\t{\n+\t\t\t\t$value = $permission[$key];\n+\t\t\t}\n+\n+\t\t\tif ($array_key == 'role_id')\n+\t\t\t{\n+\t\t\t\t// It's safe to use $parents_roles_id[$i] because array order is same with permission array\n+\t\t\t\t$result[$parent_roles_id[$i]] = $value;\n+\t\t\t}\n+\t\t\telseif ($array_key == 'role_name')\n+\t\t\t{\n+\t\t\t\t// It's safe to use $parents_roles_name[$i] because array order is same with permission array\n+\t\t\t\t$result[$parent_roles_name[$i]] = $value;\n+\t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\tarray_push($result, $value);\n+\t\t\t}\n+\n+\t\t\t$i++;\n+\t\t}\n+\n+\t\t// Trigger event\n+\t\t$this->ci->dx_auth_event->got_permissions_value($this->get_user_id(), $key);\n+\n+\t\treturn $result;\n+\t}\n+\n+\tfunction deny_access($uri = 'deny')\n+\t{\n+\t\t$this->ci->load->helper('url');\n+\n+\t\tif ($uri == 'login')\n+\t\t{\n+\t\t\tredirect($this->ci->config->item('DX_login_uri'), 'location');\n+\t\t}\n+\t\telse if ($uri == 'banned')\n+\t\t{\n+\t\t\tredirect($this->ci->config->item('DX_banned_uri'), 'location');\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\tredirect($this->ci->config->item('DX_deny_uri'), 'location');\n+\t\t}\n+\t\texit;","path":"application/libraries/DX_Auth_User.php","position":756,"original_position":756,"commit_id":"5bc17496e6899f6a25d79b583d2df9ee38830c65","original_commit_id":"5bc17496e6899f6a25d79b583d2df9ee38830c65","user":{"login":"anph","id":8475601,"avatar_url":"https://avatars.githubusercontent.com/u/8475601?v=3","gravatar_id":"","url":"https://api.github.com/users/anph","html_url":"https://github.com/anph","followers_url":"https://api.github.com/users/anph/followers","following_url":"https://api.github.com/users/anph/following{/other_user}","gists_url":"https://api.github.com/users/anph/gists{/gist_id}","starred_url":"https://api.github.com/users/anph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anph/subscriptions","organizations_url":"https://api.github.com/users/anph/orgs","repos_url":"https://api.github.com/users/anph/repos","events_url":"https://api.github.com/users/anph/events{/privacy}","received_events_url":"https://api.github.com/users/anph/received_events","type":"User","site_admin":false},"body":"__[phpmd]__\n* The method deny_access() contains an exit expression.\n\n<!-- Comment by [SideCI](https://sideci.com) -->","created_at":"2016-12-13T10:22:31Z","updated_at":"2016-12-13T10:22:31Z","html_url":"https://github.com/anph/test_sideci/pull/1#discussion_r92137539","pull_request_url":"https://api.github.com/repos/anph/test_sideci/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/comments/92137539"},"html":{"href":"https://github.com/anph/test_sideci/pull/1#discussion_r92137539"},"pull_request":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/anph/test_sideci/pulls/1","id":97720621,"html_url":"https://github.com/anph/test_sideci/pull/1","diff_url":"https://github.com/anph/test_sideci/pull/1.diff","patch_url":"https://github.com/anph/test_sideci/pull/1.patch","issue_url":"https://api.github.com/repos/anph/test_sideci/issues/1","number":1,"state":"open","locked":false,"title":"commit code","user":{"login":"duoctvd","id":16394386,"avatar_url":"https://avatars.githubusercontent.com/u/16394386?v=3","gravatar_id":"","url":"https://api.github.com/users/duoctvd","html_url":"https://github.com/duoctvd","followers_url":"https://api.github.com/users/duoctvd/followers","following_url":"https://api.github.com/users/duoctvd/following{/other_user}","gists_url":"https://api.github.com/users/duoctvd/gists{/gist_id}","starred_url":"https://api.github.com/users/duoctvd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duoctvd/subscriptions","organizations_url":"https://api.github.com/users/duoctvd/orgs","repos_url":"https://api.github.com/users/duoctvd/repos","events_url":"https://api.github.com/users/duoctvd/events{/privacy}","received_events_url":"https://api.github.com/users/duoctvd/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-13T10:13:09Z","updated_at":"2016-12-13T10:22:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24bd7a1cddcab084adcf7bc9bc58517d21ba3d6a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/anph/test_sideci/pulls/1/commits","review_comments_url":"https://api.github.com/repos/anph/test_sideci/pulls/1/comments","review_comment_url":"https://api.github.com/repos/anph/test_sideci/pulls/comments{/number}","comments_url":"https://api.github.com/repos/anph/test_sideci/issues/1/comments","statuses_url":"https://api.github.com/repos/anph/test_sideci/statuses/5bc17496e6899f6a25d79b583d2df9ee38830c65","head":{"label":"anph:test_sideci_myhome","ref":"test_sideci_myhome","sha":"5bc17496e6899f6a25d79b583d2df9ee38830c65","user":{"login":"anph","id":8475601,"avatar_url":"https://avatars.githubusercontent.com/u/8475601?v=3","gravatar_id":"","url":"https://api.github.com/users/anph","html_url":"https://github.com/anph","followers_url":"https://api.github.com/users/anph/followers","following_url":"https://api.github.com/users/anph/following{/other_user}","gists_url":"https://api.github.com/users/anph/gists{/gist_id}","starred_url":"https://api.github.com/users/anph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anph/subscriptions","organizations_url":"https://api.github.com/users/anph/orgs","repos_url":"https://api.github.com/users/anph/repos","events_url":"https://api.github.com/users/anph/events{/privacy}","received_events_url":"https://api.github.com/users/anph/received_events","type":"User","site_admin":false},"repo":{"id":76346631,"name":"test_sideci","full_name":"anph/test_sideci","owner":{"login":"anph","id":8475601,"avatar_url":"https://avatars.githubusercontent.com/u/8475601?v=3","gravatar_id":"","url":"https://api.github.com/users/anph","html_url":"https://github.com/anph","followers_url":"https://api.github.com/users/anph/followers","following_url":"https://api.github.com/users/anph/following{/other_user}","gists_url":"https://api.github.com/users/anph/gists{/gist_id}","starred_url":"https://api.github.com/users/anph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anph/subscriptions","organizations_url":"https://api.github.com/users/anph/orgs","repos_url":"https://api.github.com/users/anph/repos","events_url":"https://api.github.com/users/anph/events{/privacy}","received_events_url":"https://api.github.com/users/anph/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anph/test_sideci","description":null,"fork":false,"url":"https://api.github.com/repos/anph/test_sideci","forks_url":"https://api.github.com/repos/anph/test_sideci/forks","keys_url":"https://api.github.com/repos/anph/test_sideci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anph/test_sideci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anph/test_sideci/teams","hooks_url":"https://api.github.com/repos/anph/test_sideci/hooks","issue_events_url":"https://api.github.com/repos/anph/test_sideci/issues/events{/number}","events_url":"https://api.github.com/repos/anph/test_sideci/events","assignees_url":"https://api.github.com/repos/anph/test_sideci/assignees{/user}","branches_url":"https://api.github.com/repos/anph/test_sideci/branches{/branch}","tags_url":"https://api.github.com/repos/anph/test_sideci/tags","blobs_url":"https://api.github.com/repos/anph/test_sideci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anph/test_sideci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anph/test_sideci/git/refs{/sha}","trees_url":"https://api.github.com/repos/anph/test_sideci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anph/test_sideci/statuses/{sha}","languages_url":"https://api.github.com/repos/anph/test_sideci/languages","stargazers_url":"https://api.github.com/repos/anph/test_sideci/stargazers","contributors_url":"https://api.github.com/repos/anph/test_sideci/contributors","subscribers_url":"https://api.github.com/repos/anph/test_sideci/subscribers","subscription_url":"https://api.github.com/repos/anph/test_sideci/subscription","commits_url":"https://api.github.com/repos/anph/test_sideci/commits{/sha}","git_commits_url":"https://api.github.com/repos/anph/test_sideci/git/commits{/sha}","comments_url":"https://api.github.com/repos/anph/test_sideci/comments{/number}","issue_comment_url":"https://api.github.com/repos/anph/test_sideci/issues/comments{/number}","contents_url":"https://api.github.com/repos/anph/test_sideci/contents/{+path}","compare_url":"https://api.github.com/repos/anph/test_sideci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anph/test_sideci/merges","archive_url":"https://api.github.com/repos/anph/test_sideci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anph/test_sideci/downloads","issues_url":"https://api.github.com/repos/anph/test_sideci/issues{/number}","pulls_url":"https://api.github.com/repos/anph/test_sideci/pulls{/number}","milestones_url":"https://api.github.com/repos/anph/test_sideci/milestones{/number}","notifications_url":"https://api.github.com/repos/anph/test_sideci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anph/test_sideci/labels{/name}","releases_url":"https://api.github.com/repos/anph/test_sideci/releases{/id}","deployments_url":"https://api.github.com/repos/anph/test_sideci/deployments","created_at":"2016-12-13T10:03:38Z","updated_at":"2016-12-13T10:03:38Z","pushed_at":"2016-12-13T10:22:22Z","git_url":"git://github.com/anph/test_sideci.git","ssh_url":"git@github.com:anph/test_sideci.git","clone_url":"https://github.com/anph/test_sideci.git","svn_url":"https://github.com/anph/test_sideci","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"anph:develop","ref":"develop","sha":"ff2cb8737815fd3367ac536a6bdc826e6b49d694","user":{"login":"anph","id":8475601,"avatar_url":"https://avatars.githubusercontent.com/u/8475601?v=3","gravatar_id":"","url":"https://api.github.com/users/anph","html_url":"https://github.com/anph","followers_url":"https://api.github.com/users/anph/followers","following_url":"https://api.github.com/users/anph/following{/other_user}","gists_url":"https://api.github.com/users/anph/gists{/gist_id}","starred_url":"https://api.github.com/users/anph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anph/subscriptions","organizations_url":"https://api.github.com/users/anph/orgs","repos_url":"https://api.github.com/users/anph/repos","events_url":"https://api.github.com/users/anph/events{/privacy}","received_events_url":"https://api.github.com/users/anph/received_events","type":"User","site_admin":false},"repo":{"id":76346631,"name":"test_sideci","full_name":"anph/test_sideci","owner":{"login":"anph","id":8475601,"avatar_url":"https://avatars.githubusercontent.com/u/8475601?v=3","gravatar_id":"","url":"https://api.github.com/users/anph","html_url":"https://github.com/anph","followers_url":"https://api.github.com/users/anph/followers","following_url":"https://api.github.com/users/anph/following{/other_user}","gists_url":"https://api.github.com/users/anph/gists{/gist_id}","starred_url":"https://api.github.com/users/anph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anph/subscriptions","organizations_url":"https://api.github.com/users/anph/orgs","repos_url":"https://api.github.com/users/anph/repos","events_url":"https://api.github.com/users/anph/events{/privacy}","received_events_url":"https://api.github.com/users/anph/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anph/test_sideci","description":null,"fork":false,"url":"https://api.github.com/repos/anph/test_sideci","forks_url":"https://api.github.com/repos/anph/test_sideci/forks","keys_url":"https://api.github.com/repos/anph/test_sideci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anph/test_sideci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anph/test_sideci/teams","hooks_url":"https://api.github.com/repos/anph/test_sideci/hooks","issue_events_url":"https://api.github.com/repos/anph/test_sideci/issues/events{/number}","events_url":"https://api.github.com/repos/anph/test_sideci/events","assignees_url":"https://api.github.com/repos/anph/test_sideci/assignees{/user}","branches_url":"https://api.github.com/repos/anph/test_sideci/branches{/branch}","tags_url":"https://api.github.com/repos/anph/test_sideci/tags","blobs_url":"https://api.github.com/repos/anph/test_sideci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anph/test_sideci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anph/test_sideci/git/refs{/sha}","trees_url":"https://api.github.com/repos/anph/test_sideci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anph/test_sideci/statuses/{sha}","languages_url":"https://api.github.com/repos/anph/test_sideci/languages","stargazers_url":"https://api.github.com/repos/anph/test_sideci/stargazers","contributors_url":"https://api.github.com/repos/anph/test_sideci/contributors","subscribers_url":"https://api.github.com/repos/anph/test_sideci/subscribers","subscription_url":"https://api.github.com/repos/anph/test_sideci/subscription","commits_url":"https://api.github.com/repos/anph/test_sideci/commits{/sha}","git_commits_url":"https://api.github.com/repos/anph/test_sideci/git/commits{/sha}","comments_url":"https://api.github.com/repos/anph/test_sideci/comments{/number}","issue_comment_url":"https://api.github.com/repos/anph/test_sideci/issues/comments{/number}","contents_url":"https://api.github.com/repos/anph/test_sideci/contents/{+path}","compare_url":"https://api.github.com/repos/anph/test_sideci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anph/test_sideci/merges","archive_url":"https://api.github.com/repos/anph/test_sideci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anph/test_sideci/downloads","issues_url":"https://api.github.com/repos/anph/test_sideci/issues{/number}","pulls_url":"https://api.github.com/repos/anph/test_sideci/pulls{/number}","milestones_url":"https://api.github.com/repos/anph/test_sideci/milestones{/number}","notifications_url":"https://api.github.com/repos/anph/test_sideci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anph/test_sideci/labels{/name}","releases_url":"https://api.github.com/repos/anph/test_sideci/releases{/id}","deployments_url":"https://api.github.com/repos/anph/test_sideci/deployments","created_at":"2016-12-13T10:03:38Z","updated_at":"2016-12-13T10:03:38Z","pushed_at":"2016-12-13T10:22:22Z","git_url":"git://github.com/anph/test_sideci.git","ssh_url":"git@github.com:anph/test_sideci.git","clone_url":"https://github.com/anph/test_sideci.git","svn_url":"https://github.com/anph/test_sideci","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/1"},"html":{"href":"https://github.com/anph/test_sideci/pull/1"},"issue":{"href":"https://api.github.com/repos/anph/test_sideci/issues/1"},"comments":{"href":"https://api.github.com/repos/anph/test_sideci/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/anph/test_sideci/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/anph/test_sideci/statuses/5bc17496e6899f6a25d79b583d2df9ee38830c65"}}}}
{"actor":{"display_login":"anph"}}