@@ -302,10 +302,10 @@ discard block |
||
| 302 | 302 | $this->trigger_events('extra_where'); |
| 303 | 303 | |
| 304 | 304 | $query = $this->db->select('password, salt') |
| 305 | - ->where('id', $id) |
|
| 306 | - ->limit(1) |
|
| 307 | - ->order_by('id', 'desc') |
|
| 308 | - ->get($this->tables['users']); |
|
| 305 | + ->where('id', $id) |
|
| 306 | + ->limit(1) |
|
| 307 | + ->order_by('id', 'desc') |
|
| 308 | + ->get($this->tables['users']); |
|
| 309 | 309 | |
| 310 | 310 | $hash_password_db = $query->row(); |
| 311 | 311 | |
@@ -372,62 +372,62 @@ discard block |
||
| 372 | 372 | $raw_salt_len = 16; |
| 373 | 373 | |
| 374 | 374 | $buffer = ''; |
| 375 | - $buffer_valid = false; |
|
| 375 | + $buffer_valid = false; |
|
| 376 | 376 | |
| 377 | - if (function_exists('random_bytes')) { |
|
| 377 | + if (function_exists('random_bytes')) { |
|
| 378 | 378 | $buffer = random_bytes($raw_salt_len); |
| 379 | 379 | if ($buffer) { |
| 380 | - $buffer_valid = true; |
|
| 380 | + $buffer_valid = true; |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | if (!$buffer_valid && function_exists('mcrypt_create_iv') && !defined('PHALANGER')) { |
| 385 | - $buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM); |
|
| 386 | - if ($buffer) { |
|
| 387 | - $buffer_valid = true; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) { |
|
| 392 | - $buffer = openssl_random_pseudo_bytes($raw_salt_len); |
|
| 393 | - if ($buffer) { |
|
| 394 | - $buffer_valid = true; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if (!$buffer_valid && @is_readable('/dev/urandom')) { |
|
| 399 | - $f = fopen('/dev/urandom', 'r'); |
|
| 400 | - $read = strlen($buffer); |
|
| 401 | - while ($read < $raw_salt_len) { |
|
| 402 | - $buffer .= fread($f, $raw_salt_len - $read); |
|
| 403 | - $read = strlen($buffer); |
|
| 404 | - } |
|
| 405 | - fclose($f); |
|
| 406 | - if ($read >= $raw_salt_len) { |
|
| 407 | - $buffer_valid = true; |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if (!$buffer_valid || strlen($buffer) < $raw_salt_len) { |
|
| 412 | - $bl = strlen($buffer); |
|
| 413 | - for ($i = 0; $i < $raw_salt_len; $i++) { |
|
| 414 | - if ($i < $bl) { |
|
| 415 | - $buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255)); |
|
| 416 | - } else { |
|
| 417 | - $buffer .= chr(mt_rand(0, 255)); |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - $salt = $buffer; |
|
| 423 | - |
|
| 424 | - // encode string with the Base64 variant used by crypt |
|
| 425 | - $base64_digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
| 426 | - $bcrypt64_digits = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 427 | - $base64_string = base64_encode($salt); |
|
| 428 | - $salt = strtr(rtrim($base64_string, '='), $base64_digits, $bcrypt64_digits); |
|
| 429 | - |
|
| 430 | - $salt = substr($salt, 0, $this->salt_length); |
|
| 385 | + $buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM); |
|
| 386 | + if ($buffer) { |
|
| 387 | + $buffer_valid = true; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) { |
|
| 392 | + $buffer = openssl_random_pseudo_bytes($raw_salt_len); |
|
| 393 | + if ($buffer) { |
|
| 394 | + $buffer_valid = true; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if (!$buffer_valid && @is_readable('/dev/urandom')) { |
|
| 399 | + $f = fopen('/dev/urandom', 'r'); |
|
| 400 | + $read = strlen($buffer); |
|
| 401 | + while ($read < $raw_salt_len) { |
|
| 402 | + $buffer .= fread($f, $raw_salt_len - $read); |
|
| 403 | + $read = strlen($buffer); |
|
| 404 | + } |
|
| 405 | + fclose($f); |
|
| 406 | + if ($read >= $raw_salt_len) { |
|
| 407 | + $buffer_valid = true; |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if (!$buffer_valid || strlen($buffer) < $raw_salt_len) { |
|
| 412 | + $bl = strlen($buffer); |
|
| 413 | + for ($i = 0; $i < $raw_salt_len; $i++) { |
|
| 414 | + if ($i < $bl) { |
|
| 415 | + $buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255)); |
|
| 416 | + } else { |
|
| 417 | + $buffer .= chr(mt_rand(0, 255)); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + $salt = $buffer; |
|
| 423 | + |
|
| 424 | + // encode string with the Base64 variant used by crypt |
|
| 425 | + $base64_digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
| 426 | + $bcrypt64_digits = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 427 | + $base64_string = base64_encode($salt); |
|
| 428 | + $salt = strtr(rtrim($base64_string, '='), $base64_digits, $bcrypt64_digits); |
|
| 429 | + |
|
| 430 | + $salt = substr($salt, 0, $this->salt_length); |
|
| 431 | 431 | |
| 432 | 432 | |
| 433 | 433 | return $salt; |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | if ($code !== FALSE) |
| 457 | 457 | { |
| 458 | 458 | $query = $this->db->select($this->identity_column) |
| 459 | - ->where('activation_code', $code) |
|
| 460 | - ->where('id', $id) |
|
| 461 | - ->limit(1) |
|
| 462 | - ->order_by('id', 'desc') |
|
| 463 | - ->get($this->tables['users']); |
|
| 459 | + ->where('activation_code', $code) |
|
| 460 | + ->where('id', $id) |
|
| 461 | + ->limit(1) |
|
| 462 | + ->order_by('id', 'desc') |
|
| 463 | + ->get($this->tables['users']); |
|
| 464 | 464 | |
| 465 | 465 | $result = $query->row(); |
| 466 | 466 | |
@@ -472,8 +472,8 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $data = array( |
| 475 | - 'activation_code' => NULL, |
|
| 476 | - 'active' => 1 |
|
| 475 | + 'activation_code' => NULL, |
|
| 476 | + 'active' => 1 |
|
| 477 | 477 | ); |
| 478 | 478 | |
| 479 | 479 | $this->trigger_events('extra_where'); |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | else |
| 483 | 483 | { |
| 484 | 484 | $data = array( |
| 485 | - 'activation_code' => NULL, |
|
| 486 | - 'active' => 1 |
|
| 485 | + 'activation_code' => NULL, |
|
| 486 | + 'active' => 1 |
|
| 487 | 487 | ); |
| 488 | 488 | |
| 489 | 489 | |
@@ -524,18 +524,18 @@ discard block |
||
| 524 | 524 | $this->set_error('deactivate_unsuccessful'); |
| 525 | 525 | return FALSE; |
| 526 | 526 | } |
| 527 | - elseif($this->ion_auth->logged_in() && $this->user()->row()->id == $id) |
|
| 528 | - { |
|
| 529 | - $this->set_error('deactivate_current_user_unsuccessful'); |
|
| 530 | - return FALSE; |
|
| 531 | - } |
|
| 527 | + elseif($this->ion_auth->logged_in() && $this->user()->row()->id == $id) |
|
| 528 | + { |
|
| 529 | + $this->set_error('deactivate_current_user_unsuccessful'); |
|
| 530 | + return FALSE; |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | 533 | $activation_code = sha1(md5(microtime())); |
| 534 | 534 | $this->activation_code = $activation_code; |
| 535 | 535 | |
| 536 | 536 | $data = array( |
| 537 | - 'activation_code' => $activation_code, |
|
| 538 | - 'active' => 0 |
|
| 537 | + 'activation_code' => $activation_code, |
|
| 538 | + 'active' => 0 |
|
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | $this->trigger_events('extra_where'); |
@@ -562,8 +562,8 @@ discard block |
||
| 562 | 562 | if ($this->db->count_all_results($this->tables['users']) > 0) |
| 563 | 563 | { |
| 564 | 564 | $data = array( |
| 565 | - 'forgotten_password_code' => NULL, |
|
| 566 | - 'forgotten_password_time' => NULL |
|
| 565 | + 'forgotten_password_code' => NULL, |
|
| 566 | + 'forgotten_password_time' => NULL |
|
| 567 | 567 | ); |
| 568 | 568 | |
| 569 | 569 | $this->db->update($this->tables['users'], $data, array('forgotten_password_code' => $code)); |
@@ -591,10 +591,10 @@ discard block |
||
| 591 | 591 | $this->trigger_events('extra_where'); |
| 592 | 592 | |
| 593 | 593 | $query = $this->db->select('id, password, salt') |
| 594 | - ->where($this->identity_column, $identity) |
|
| 595 | - ->limit(1) |
|
| 596 | - ->order_by('id', 'desc') |
|
| 597 | - ->get($this->tables['users']); |
|
| 594 | + ->where($this->identity_column, $identity) |
|
| 595 | + ->limit(1) |
|
| 596 | + ->order_by('id', 'desc') |
|
| 597 | + ->get($this->tables['users']); |
|
| 598 | 598 | |
| 599 | 599 | if ($query->num_rows() !== 1) |
| 600 | 600 | { |
@@ -610,10 +610,10 @@ discard block |
||
| 610 | 610 | // store the new password and reset the remember code so all remembered instances have to re-login |
| 611 | 611 | // also clear the forgotten password code |
| 612 | 612 | $data = array( |
| 613 | - 'password' => $new, |
|
| 614 | - 'remember_code' => NULL, |
|
| 615 | - 'forgotten_password_code' => NULL, |
|
| 616 | - 'forgotten_password_time' => NULL, |
|
| 613 | + 'password' => $new, |
|
| 614 | + 'remember_code' => NULL, |
|
| 615 | + 'forgotten_password_code' => NULL, |
|
| 616 | + 'forgotten_password_time' => NULL, |
|
| 617 | 617 | ); |
| 618 | 618 | |
| 619 | 619 | $this->trigger_events('extra_where'); |
@@ -647,10 +647,10 @@ discard block |
||
| 647 | 647 | $this->trigger_events('extra_where'); |
| 648 | 648 | |
| 649 | 649 | $query = $this->db->select('id, password, salt') |
| 650 | - ->where($this->identity_column, $identity) |
|
| 651 | - ->limit(1) |
|
| 652 | - ->order_by('id', 'desc') |
|
| 653 | - ->get($this->tables['users']); |
|
| 650 | + ->where($this->identity_column, $identity) |
|
| 651 | + ->limit(1) |
|
| 652 | + ->order_by('id', 'desc') |
|
| 653 | + ->get($this->tables['users']); |
|
| 654 | 654 | |
| 655 | 655 | if ($query->num_rows() !== 1) |
| 656 | 656 | { |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | // store the new password and reset the remember code so all remembered instances have to re-login |
| 669 | 669 | $hashed_new_password = $this->hash_password($new, $user->salt); |
| 670 | 670 | $data = array( |
| 671 | - 'password' => $hashed_new_password, |
|
| 672 | - 'remember_code' => NULL, |
|
| 671 | + 'password' => $hashed_new_password, |
|
| 672 | + 'remember_code' => NULL, |
|
| 673 | 673 | ); |
| 674 | 674 | |
| 675 | 675 | $this->trigger_events('extra_where'); |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | ->group_by("id") |
| 715 | 715 | ->order_by("id", "ASC") |
| 716 | 716 | ->limit(1) |
| 717 | - ->count_all_results($this->tables['users']) > 0; |
|
| 717 | + ->count_all_results($this->tables['users']) > 0; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | ->group_by("id") |
| 739 | 739 | ->order_by("id", "ASC") |
| 740 | 740 | ->limit(1) |
| 741 | - ->count_all_results($this->tables['users']) > 0; |
|
| 741 | + ->count_all_results($this->tables['users']) > 0; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | return $this->db->where($this->identity_column, $identity) |
| 760 | - ->count_all_results($this->tables['users']) > 0; |
|
| 760 | + ->count_all_results($this->tables['users']) > 0; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -805,8 +805,8 @@ discard block |
||
| 805 | 805 | $this->trigger_events('extra_where'); |
| 806 | 806 | |
| 807 | 807 | $update = array( |
| 808 | - 'forgotten_password_code' => $key, |
|
| 809 | - 'forgotten_password_time' => time() |
|
| 808 | + 'forgotten_password_code' => $key, |
|
| 809 | + 'forgotten_password_time' => time() |
|
| 810 | 810 | ); |
| 811 | 811 | |
| 812 | 812 | $this->db->update($this->tables['users'], $update, array($this->identity_column => $identity)); |
@@ -855,9 +855,9 @@ discard block |
||
| 855 | 855 | $password = $this->salt(); |
| 856 | 856 | |
| 857 | 857 | $data = array( |
| 858 | - 'password' => $this->hash_password($password, $salt), |
|
| 859 | - 'forgotten_password_code' => NULL, |
|
| 860 | - 'active' => 1, |
|
| 858 | + 'password' => $this->hash_password($password, $salt), |
|
| 859 | + 'forgotten_password_code' => NULL, |
|
| 860 | + 'active' => 1, |
|
| 861 | 861 | ); |
| 862 | 862 | |
| 863 | 863 | $this->db->update($this->tables['users'], $data, array('forgotten_password_code' => $code)); |
@@ -911,13 +911,13 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | // Users table. |
| 913 | 913 | $data = array( |
| 914 | - $this->identity_column => $identity, |
|
| 915 | - 'username' => $identity, |
|
| 916 | - 'password' => $password, |
|
| 917 | - 'email' => $email, |
|
| 918 | - 'ip_address' => $ip_address, |
|
| 919 | - 'created_on' => time(), |
|
| 920 | - 'active' => ($manual_activation === false ? 1 : 0) |
|
| 914 | + $this->identity_column => $identity, |
|
| 915 | + 'username' => $identity, |
|
| 916 | + 'password' => $password, |
|
| 917 | + 'email' => $email, |
|
| 918 | + 'ip_address' => $ip_address, |
|
| 919 | + 'created_on' => time(), |
|
| 920 | + 'active' => ($manual_activation === false ? 1 : 0) |
|
| 921 | 921 | ); |
| 922 | 922 | |
| 923 | 923 | if ($this->store_salt) |
@@ -974,10 +974,10 @@ discard block |
||
| 974 | 974 | $this->trigger_events('extra_where'); |
| 975 | 975 | |
| 976 | 976 | $query = $this->db->select($this->identity_column . ', email, id, password, active, last_login') |
| 977 | - ->where($this->identity_column, $identity) |
|
| 978 | - ->limit(1) |
|
| 979 | - ->order_by('id', 'desc') |
|
| 980 | - ->get($this->tables['users']); |
|
| 977 | + ->where($this->identity_column, $identity) |
|
| 978 | + ->limit(1) |
|
| 979 | + ->order_by('id', 'desc') |
|
| 980 | + ->get($this->tables['users']); |
|
| 981 | 981 | |
| 982 | 982 | if($this->is_max_login_attempts_exceeded($identity)) |
| 983 | 983 | { |
@@ -1035,50 +1035,50 @@ discard block |
||
| 1035 | 1035 | return FALSE; |
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - /** |
|
| 1039 | - * recheck_session verifies if the session should be rechecked according to |
|
| 1040 | - * the configuration item recheck_timer. If it does, then it will check if the user is still active |
|
| 1041 | - * @return bool |
|
| 1042 | - */ |
|
| 1038 | + /** |
|
| 1039 | + * recheck_session verifies if the session should be rechecked according to |
|
| 1040 | + * the configuration item recheck_timer. If it does, then it will check if the user is still active |
|
| 1041 | + * @return bool |
|
| 1042 | + */ |
|
| 1043 | 1043 | public function recheck_session() |
| 1044 | - { |
|
| 1045 | - $recheck = (null !== $this->config->item('recheck_timer', 'ion_auth')) ? $this->config->item('recheck_timer', 'ion_auth') : 0; |
|
| 1046 | - |
|
| 1047 | - if($recheck!==0) |
|
| 1048 | - { |
|
| 1049 | - $last_login = $this->session->userdata('last_check'); |
|
| 1050 | - if($last_login+$recheck < time()) |
|
| 1051 | - { |
|
| 1052 | - $query = $this->db->select('id') |
|
| 1053 | - ->where(array($this->identity_column=>$this->session->userdata('identity'),'active'=>'1')) |
|
| 1054 | - ->limit(1) |
|
| 1055 | - ->order_by('id', 'desc') |
|
| 1056 | - ->get($this->tables['users']); |
|
| 1057 | - if ($query->num_rows() === 1) |
|
| 1058 | - { |
|
| 1059 | - $this->session->set_userdata('last_check',time()); |
|
| 1060 | - } |
|
| 1061 | - else |
|
| 1062 | - { |
|
| 1063 | - $this->trigger_events('logout'); |
|
| 1064 | - |
|
| 1065 | - $identity = $this->config->item('identity', 'ion_auth'); |
|
| 1066 | - |
|
| 1067 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 1068 | - { |
|
| 1069 | - $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
|
| 1070 | - } |
|
| 1071 | - else |
|
| 1072 | - { |
|
| 1073 | - $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 1074 | - } |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - return (bool) $this->session->userdata('identity'); |
|
| 1081 | - } |
|
| 1044 | + { |
|
| 1045 | + $recheck = (null !== $this->config->item('recheck_timer', 'ion_auth')) ? $this->config->item('recheck_timer', 'ion_auth') : 0; |
|
| 1046 | + |
|
| 1047 | + if($recheck!==0) |
|
| 1048 | + { |
|
| 1049 | + $last_login = $this->session->userdata('last_check'); |
|
| 1050 | + if($last_login+$recheck < time()) |
|
| 1051 | + { |
|
| 1052 | + $query = $this->db->select('id') |
|
| 1053 | + ->where(array($this->identity_column=>$this->session->userdata('identity'),'active'=>'1')) |
|
| 1054 | + ->limit(1) |
|
| 1055 | + ->order_by('id', 'desc') |
|
| 1056 | + ->get($this->tables['users']); |
|
| 1057 | + if ($query->num_rows() === 1) |
|
| 1058 | + { |
|
| 1059 | + $this->session->set_userdata('last_check',time()); |
|
| 1060 | + } |
|
| 1061 | + else |
|
| 1062 | + { |
|
| 1063 | + $this->trigger_events('logout'); |
|
| 1064 | + |
|
| 1065 | + $identity = $this->config->item('identity', 'ion_auth'); |
|
| 1066 | + |
|
| 1067 | + if (substr(CI_VERSION, 0, 1) == '2') |
|
| 1068 | + { |
|
| 1069 | + $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
|
| 1070 | + } |
|
| 1071 | + else |
|
| 1072 | + { |
|
| 1073 | + $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 1074 | + } |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + return (bool) $this->session->userdata('identity'); |
|
| 1081 | + } |
|
| 1082 | 1082 | |
| 1083 | 1083 | /** |
| 1084 | 1084 | * is_max_login_attempts_exceeded |
@@ -1115,20 +1115,20 @@ discard block |
||
| 1115 | 1115 | */ |
| 1116 | 1116 | public function get_attempts_num($identity, $ip_address = NULL) |
| 1117 | 1117 | { |
| 1118 | - if ($this->config->item('track_login_attempts', 'ion_auth')) { |
|
| 1119 | - $this->db->select('1', FALSE); |
|
| 1120 | - $this->db->where('login', $identity); |
|
| 1121 | - if ($this->config->item('track_login_ip_address', 'ion_auth')) { |
|
| 1122 | - if (!isset($ip_address)) { |
|
| 1123 | - $ip_address = $this->_prepare_ip($this->input->ip_address()); |
|
| 1124 | - } |
|
| 1125 | - $this->db->where('ip_address', $ip_address); |
|
| 1126 | - } |
|
| 1127 | - $this->db->where('time >', time() - $this->config->item('lockout_time', 'ion_auth'), FALSE); |
|
| 1128 | - $qres = $this->db->get($this->tables['login_attempts']); |
|
| 1129 | - return $qres->num_rows(); |
|
| 1130 | - } |
|
| 1131 | - return 0; |
|
| 1118 | + if ($this->config->item('track_login_attempts', 'ion_auth')) { |
|
| 1119 | + $this->db->select('1', FALSE); |
|
| 1120 | + $this->db->where('login', $identity); |
|
| 1121 | + if ($this->config->item('track_login_ip_address', 'ion_auth')) { |
|
| 1122 | + if (!isset($ip_address)) { |
|
| 1123 | + $ip_address = $this->_prepare_ip($this->input->ip_address()); |
|
| 1124 | + } |
|
| 1125 | + $this->db->where('ip_address', $ip_address); |
|
| 1126 | + } |
|
| 1127 | + $this->db->where('time >', time() - $this->config->item('lockout_time', 'ion_auth'), FALSE); |
|
| 1128 | + $qres = $this->db->get($this->tables['login_attempts']); |
|
| 1129 | + return $qres->num_rows(); |
|
| 1130 | + } |
|
| 1131 | + return 0; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | /** |
@@ -1185,11 +1185,11 @@ discard block |
||
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | /** |
| 1188 | - * Get the IP address of the last time a login attempt occured from given identity |
|
| 1189 | - * |
|
| 1188 | + * Get the IP address of the last time a login attempt occured from given identity |
|
| 1189 | + * |
|
| 1190 | 1190 | * @param string $identity: user's identity |
| 1191 | - * @return string |
|
| 1192 | - */ |
|
| 1191 | + * @return string |
|
| 1192 | + */ |
|
| 1193 | 1193 | public function get_last_attempt_ip($identity) { |
| 1194 | 1194 | if ($this->config->item('track_login_attempts', 'ion_auth') && $this->config->item('track_login_ip_address', 'ion_auth')) { |
| 1195 | 1195 | $this->db->select('ip_address'); |
@@ -1387,9 +1387,9 @@ discard block |
||
| 1387 | 1387 | { |
| 1388 | 1388 | //default selects |
| 1389 | 1389 | $this->db->select(array( |
| 1390 | - $this->tables['users'].'.*', |
|
| 1391 | - $this->tables['users'].'.id as id', |
|
| 1392 | - $this->tables['users'].'.id as user_id' |
|
| 1390 | + $this->tables['users'].'.*', |
|
| 1391 | + $this->tables['users'].'.id as id', |
|
| 1392 | + $this->tables['users'].'.id as user_id' |
|
| 1393 | 1393 | )); |
| 1394 | 1394 | } |
| 1395 | 1395 | |
@@ -1407,9 +1407,9 @@ discard block |
||
| 1407 | 1407 | { |
| 1408 | 1408 | $this->db->distinct(); |
| 1409 | 1409 | $this->db->join( |
| 1410 | - $this->tables['users_groups'], |
|
| 1411 | - $this->tables['users_groups'].'.'.$this->join['users'].'='.$this->tables['users'].'.id', |
|
| 1412 | - 'inner' |
|
| 1410 | + $this->tables['users_groups'], |
|
| 1411 | + $this->tables['users_groups'].'.'.$this->join['users'].'='.$this->tables['users'].'.id', |
|
| 1412 | + 'inner' |
|
| 1413 | 1413 | ); |
| 1414 | 1414 | } |
| 1415 | 1415 | |
@@ -1521,9 +1521,9 @@ discard block |
||
| 1521 | 1521 | $id || $id = $this->session->userdata('user_id'); |
| 1522 | 1522 | |
| 1523 | 1523 | return $this->db->select($this->tables['users_groups'].'.'.$this->join['groups'].' as id, '.$this->tables['groups'].'.name, '.$this->tables['groups'].'.description') |
| 1524 | - ->where($this->tables['users_groups'].'.'.$this->join['users'], $id) |
|
| 1525 | - ->join($this->tables['groups'], $this->tables['users_groups'].'.'.$this->join['groups'].'='.$this->tables['groups'].'.id') |
|
| 1526 | - ->get($this->tables['users_groups']); |
|
| 1524 | + ->where($this->tables['users_groups'].'.'.$this->join['users'], $id) |
|
| 1525 | + ->join($this->tables['groups'], $this->tables['users_groups'].'.'.$this->join['groups'].'='.$this->tables['groups'].'.id') |
|
| 1526 | + ->get($this->tables['users_groups']); |
|
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | 1529 | /** |
@@ -1744,11 +1744,11 @@ discard block |
||
| 1744 | 1744 | } |
| 1745 | 1745 | |
| 1746 | 1746 | /** |
| 1747 | - * delete_user |
|
| 1748 | - * |
|
| 1749 | - * @return bool |
|
| 1750 | - * @author Phil Sturgeon |
|
| 1751 | - **/ |
|
| 1747 | + * delete_user |
|
| 1748 | + * |
|
| 1749 | + * @return bool |
|
| 1750 | + * @author Phil Sturgeon |
|
| 1751 | + **/ |
|
| 1752 | 1752 | public function delete_user($id) |
| 1753 | 1753 | { |
| 1754 | 1754 | $this->trigger_events('pre_delete_user'); |
@@ -1838,12 +1838,12 @@ discard block |
||
| 1838 | 1838 | $this->trigger_events('pre_set_session'); |
| 1839 | 1839 | |
| 1840 | 1840 | $session_data = array( |
| 1841 | - 'identity' => $user->{$this->identity_column}, |
|
| 1842 | - $this->identity_column => $user->{$this->identity_column}, |
|
| 1843 | - 'email' => $user->email, |
|
| 1844 | - 'user_id' => $user->id, //everyone likes to overwrite id so we'll use user_id |
|
| 1845 | - 'old_last_login' => $user->last_login, |
|
| 1846 | - 'last_check' => time(), |
|
| 1841 | + 'identity' => $user->{$this->identity_column}, |
|
| 1842 | + $this->identity_column => $user->{$this->identity_column}, |
|
| 1843 | + 'email' => $user->email, |
|
| 1844 | + 'user_id' => $user->id, //everyone likes to overwrite id so we'll use user_id |
|
| 1845 | + 'old_last_login' => $user->last_login, |
|
| 1846 | + 'last_check' => time(), |
|
| 1847 | 1847 | ); |
| 1848 | 1848 | |
| 1849 | 1849 | $this->session->set_userdata($session_data); |
@@ -1888,15 +1888,15 @@ discard block |
||
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | set_cookie(array( |
| 1891 | - 'name' => $this->config->item('identity_cookie_name', 'ion_auth'), |
|
| 1892 | - 'value' => $user->{$this->identity_column}, |
|
| 1893 | - 'expire' => $expire |
|
| 1891 | + 'name' => $this->config->item('identity_cookie_name', 'ion_auth'), |
|
| 1892 | + 'value' => $user->{$this->identity_column}, |
|
| 1893 | + 'expire' => $expire |
|
| 1894 | 1894 | )); |
| 1895 | 1895 | |
| 1896 | 1896 | set_cookie(array( |
| 1897 | - 'name' => $this->config->item('remember_cookie_name', 'ion_auth'), |
|
| 1898 | - 'value' => $salt, |
|
| 1899 | - 'expire' => $expire |
|
| 1897 | + 'name' => $this->config->item('remember_cookie_name', 'ion_auth'), |
|
| 1898 | + 'value' => $salt, |
|
| 1899 | + 'expire' => $expire |
|
| 1900 | 1900 | )); |
| 1901 | 1901 | |
| 1902 | 1902 | $this->trigger_events(array('post_remember_user', 'remember_user_successful')); |
@@ -1929,12 +1929,12 @@ discard block |
||
| 1929 | 1929 | // get the user |
| 1930 | 1930 | $this->trigger_events('extra_where'); |
| 1931 | 1931 | $query = $this->db->select($this->identity_column.', id, email, last_login') |
| 1932 | - ->where($this->identity_column, urldecode(get_cookie($this->config->item('identity_cookie_name', 'ion_auth')))) |
|
| 1933 | - ->where('remember_code', get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 1932 | + ->where($this->identity_column, urldecode(get_cookie($this->config->item('identity_cookie_name', 'ion_auth')))) |
|
| 1933 | + ->where('remember_code', get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 1934 | 1934 | ->where('active',1) |
| 1935 | - ->limit(1) |
|
| 1936 | - ->order_by('id', 'desc') |
|
| 1937 | - ->get($this->tables['users']); |
|
| 1935 | + ->limit(1) |
|
| 1936 | + ->order_by('id', 'desc') |
|
| 1937 | + ->get($this->tables['users']); |
|
| 1938 | 1938 | |
| 1939 | 1939 | // if the user was found, sign them in |
| 1940 | 1940 | if ($query->num_rows() == 1) |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | * create_group |
| 1965 | 1965 | * |
| 1966 | 1966 | * @author aditya menon |
| 1967 | - */ |
|
| 1967 | + */ |
|
| 1968 | 1968 | public function create_group($group_name = FALSE, $group_description = '', $additional_data = array()) |
| 1969 | 1969 | { |
| 1970 | 1970 | // bail if the group name was not passed |
@@ -2028,12 +2028,12 @@ discard block |
||
| 2028 | 2028 | } |
| 2029 | 2029 | |
| 2030 | 2030 | // restrict change of name of the admin group |
| 2031 | - $group = $this->db->get_where($this->tables['groups'], array('id' => $group_id))->row(); |
|
| 2032 | - if($this->config->item('admin_group', 'ion_auth') === $group->name && $group_name !== $group->name) |
|
| 2033 | - { |
|
| 2034 | - $this->set_error('group_name_admin_not_alter'); |
|
| 2035 | - return FALSE; |
|
| 2036 | - } |
|
| 2031 | + $group = $this->db->get_where($this->tables['groups'], array('id' => $group_id))->row(); |
|
| 2032 | + if($this->config->item('admin_group', 'ion_auth') === $group->name && $group_name !== $group->name) |
|
| 2033 | + { |
|
| 2034 | + $this->set_error('group_name_admin_not_alter'); |
|
| 2035 | + return FALSE; |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | 2038 | |
| 2039 | 2039 | // IMPORTANT!! Third parameter was string type $description; this following code is to maintain backward compatibility |
@@ -2054,11 +2054,11 @@ discard block |
||
| 2054 | 2054 | } |
| 2055 | 2055 | |
| 2056 | 2056 | /** |
| 2057 | - * delete_group |
|
| 2058 | - * |
|
| 2059 | - * @return bool |
|
| 2060 | - * @author aditya menon |
|
| 2061 | - **/ |
|
| 2057 | + * delete_group |
|
| 2058 | + * |
|
| 2059 | + * @return bool |
|
| 2060 | + * @author aditya menon |
|
| 2061 | + **/ |
|
| 2062 | 2062 | public function delete_group($group_id = FALSE) |
| 2063 | 2063 | { |
| 2064 | 2064 | // bail if mandatory param not set |
@@ -13,84 +13,84 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function __construct($params=array('rounds'=>7, 'salt_prefix'=>'$2y$')) { |
| 15 | 15 | |
| 16 | - if(CRYPT_BLOWFISH != 1) { |
|
| 17 | - throw new Exception("bcrypt not supported in this installation. See http://php.net/crypt"); |
|
| 18 | - } |
|
| 16 | + if(CRYPT_BLOWFISH != 1) { |
|
| 17 | + throw new Exception("bcrypt not supported in this installation. See http://php.net/crypt"); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - $this->rounds = $params['rounds']; |
|
| 21 | - $this->salt_prefix = $params['salt_prefix']; |
|
| 20 | + $this->rounds = $params['rounds']; |
|
| 21 | + $this->salt_prefix = $params['salt_prefix']; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function hash($input) { |
| 25 | - $hash = crypt($input, $this->getSalt()); |
|
| 25 | + $hash = crypt($input, $this->getSalt()); |
|
| 26 | 26 | |
| 27 | - if(strlen($hash) > 13) { |
|
| 28 | - return $hash; |
|
| 29 | - } |
|
| 27 | + if(strlen($hash) > 13) { |
|
| 28 | + return $hash; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return false; |
|
| 31 | + return false; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @param $input |
| 36 | 36 | * @param $existingHash |
| 37 | 37 | * @return bool |
| 38 | - */ |
|
| 38 | + */ |
|
| 39 | 39 | public function verify($input, $existingHash) { |
| 40 | - $hash = crypt($input, $existingHash); |
|
| 41 | - return $this->hashEquals($existingHash, $hash); |
|
| 40 | + $hash = crypt($input, $existingHash); |
|
| 41 | + return $this->hashEquals($existingHash, $hash); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * Polyfill for hash_equals() |
|
| 46 | - * Code mainly taken from hash_equals() compat function of CodeIgniter 3 |
|
| 47 | - * |
|
| 48 | - * @param string $known_string |
|
| 49 | - * @param string $user_string |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 45 | + * Polyfill for hash_equals() |
|
| 46 | + * Code mainly taken from hash_equals() compat function of CodeIgniter 3 |
|
| 47 | + * |
|
| 48 | + * @param string $known_string |
|
| 49 | + * @param string $user_string |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | 52 | private function hashEquals($known_string, $user_string) |
| 53 | 53 | { |
| 54 | - // For CI3 or PHP >= 5.6 |
|
| 55 | - if (function_exists('hash_equals')) |
|
| 56 | - { |
|
| 57 | - return hash_equals($known_string, $user_string); |
|
| 58 | - } |
|
| 54 | + // For CI3 or PHP >= 5.6 |
|
| 55 | + if (function_exists('hash_equals')) |
|
| 56 | + { |
|
| 57 | + return hash_equals($known_string, $user_string); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - // For CI2 with PHP < 5.6 |
|
| 61 | - // Code from CI3 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/compat/hash.php |
|
| 62 | - if ( ! is_string($known_string)) |
|
| 63 | - { |
|
| 64 | - trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING); |
|
| 65 | - return FALSE; |
|
| 66 | - } |
|
| 67 | - elseif ( ! is_string($user_string)) |
|
| 68 | - { |
|
| 69 | - trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING); |
|
| 70 | - return FALSE; |
|
| 71 | - } |
|
| 72 | - elseif (($length = strlen($known_string)) !== strlen($user_string)) |
|
| 73 | - { |
|
| 74 | - return FALSE; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $diff = 0; |
|
| 78 | - for ($i = 0; $i < $length; $i++) |
|
| 79 | - { |
|
| 80 | - $diff |= ord($known_string[$i]) ^ ord($user_string[$i]); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return ($diff === 0); |
|
| 60 | + // For CI2 with PHP < 5.6 |
|
| 61 | + // Code from CI3 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/compat/hash.php |
|
| 62 | + if ( ! is_string($known_string)) |
|
| 63 | + { |
|
| 64 | + trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING); |
|
| 65 | + return FALSE; |
|
| 66 | + } |
|
| 67 | + elseif ( ! is_string($user_string)) |
|
| 68 | + { |
|
| 69 | + trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING); |
|
| 70 | + return FALSE; |
|
| 71 | + } |
|
| 72 | + elseif (($length = strlen($known_string)) !== strlen($user_string)) |
|
| 73 | + { |
|
| 74 | + return FALSE; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $diff = 0; |
|
| 78 | + for ($i = 0; $i < $length; $i++) |
|
| 79 | + { |
|
| 80 | + $diff |= ord($known_string[$i]) ^ ord($user_string[$i]); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return ($diff === 0); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | private function getSalt() { |
| 87 | - $salt = sprintf($this->salt_prefix.'%02d$', $this->rounds); |
|
| 87 | + $salt = sprintf($this->salt_prefix.'%02d$', $this->rounds); |
|
| 88 | 88 | |
| 89 | - $bytes = $this->getRandomBytes(16); |
|
| 89 | + $bytes = $this->getRandomBytes(16); |
|
| 90 | 90 | |
| 91 | - $salt .= $this->encodeBytes($bytes); |
|
| 91 | + $salt .= $this->encodeBytes($bytes); |
|
| 92 | 92 | |
| 93 | - return $salt; |
|
| 93 | + return $salt; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | private $randomState; |
@@ -99,78 +99,78 @@ discard block |
||
| 99 | 99 | /** |
| 100 | 100 | * @param $count |
| 101 | 101 | * @return string |
| 102 | - */ |
|
| 102 | + */ |
|
| 103 | 103 | private function getRandomBytes($count) { |
| 104 | - $bytes = ''; |
|
| 105 | - |
|
| 106 | - if(function_exists('openssl_random_pseudo_bytes') && |
|
| 107 | - (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win |
|
| 108 | - $bytes = openssl_random_pseudo_bytes($count); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if($bytes === '' && @is_readable('/dev/urandom') && |
|
| 112 | - ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) { |
|
| 113 | - $bytes = fread($hRand, $count); |
|
| 114 | - fclose($hRand); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if(strlen($bytes) < $count) { |
|
| 118 | - $bytes = ''; |
|
| 119 | - |
|
| 120 | - if($this->randomState === null) { |
|
| 121 | - $this->randomState = microtime(); |
|
| 122 | - if(function_exists('getmypid')) { |
|
| 123 | - $this->randomState .= getmypid(); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - for($i = 0; $i < $count; $i += 16) { |
|
| 128 | - $this->randomState = md5(microtime() . $this->randomState); |
|
| 129 | - |
|
| 130 | - if (PHP_VERSION >= '5') { |
|
| 131 | - $bytes .= md5($this->randomState, true); |
|
| 132 | - } else { |
|
| 133 | - $bytes .= pack('H*', md5($this->randomState)); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $bytes = substr($bytes, 0, $count); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $bytes; |
|
| 104 | + $bytes = ''; |
|
| 105 | + |
|
| 106 | + if(function_exists('openssl_random_pseudo_bytes') && |
|
| 107 | + (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win |
|
| 108 | + $bytes = openssl_random_pseudo_bytes($count); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if($bytes === '' && @is_readable('/dev/urandom') && |
|
| 112 | + ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) { |
|
| 113 | + $bytes = fread($hRand, $count); |
|
| 114 | + fclose($hRand); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if(strlen($bytes) < $count) { |
|
| 118 | + $bytes = ''; |
|
| 119 | + |
|
| 120 | + if($this->randomState === null) { |
|
| 121 | + $this->randomState = microtime(); |
|
| 122 | + if(function_exists('getmypid')) { |
|
| 123 | + $this->randomState .= getmypid(); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + for($i = 0; $i < $count; $i += 16) { |
|
| 128 | + $this->randomState = md5(microtime() . $this->randomState); |
|
| 129 | + |
|
| 130 | + if (PHP_VERSION >= '5') { |
|
| 131 | + $bytes .= md5($this->randomState, true); |
|
| 132 | + } else { |
|
| 133 | + $bytes .= pack('H*', md5($this->randomState)); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $bytes = substr($bytes, 0, $count); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $bytes; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * @param $input |
| 145 | 145 | * @return string |
| 146 | - */ |
|
| 146 | + */ |
|
| 147 | 147 | private function encodeBytes($input) { |
| 148 | - // The following is code from the PHP Password Hashing Framework |
|
| 149 | - $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 150 | - |
|
| 151 | - $output = ''; |
|
| 152 | - $i = 0; |
|
| 153 | - do { |
|
| 154 | - $c1 = ord($input[$i++]); |
|
| 155 | - $output .= $itoa64[$c1 >> 2]; |
|
| 156 | - $c1 = ($c1 & 0x03) << 4; |
|
| 157 | - if ($i >= 16) { |
|
| 158 | - $output .= $itoa64[$c1]; |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $c2 = ord($input[$i++]); |
|
| 163 | - $c1 |= $c2 >> 4; |
|
| 164 | - $output .= $itoa64[$c1]; |
|
| 165 | - $c1 = ($c2 & 0x0f) << 2; |
|
| 166 | - |
|
| 167 | - $c2 = ord($input[$i++]); |
|
| 168 | - $c1 |= $c2 >> 6; |
|
| 169 | - $output .= $itoa64[$c1]; |
|
| 170 | - $output .= $itoa64[$c2 & 0x3f]; |
|
| 171 | - } while (1); |
|
| 172 | - |
|
| 173 | - return $output; |
|
| 148 | + // The following is code from the PHP Password Hashing Framework |
|
| 149 | + $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 150 | + |
|
| 151 | + $output = ''; |
|
| 152 | + $i = 0; |
|
| 153 | + do { |
|
| 154 | + $c1 = ord($input[$i++]); |
|
| 155 | + $output .= $itoa64[$c1 >> 2]; |
|
| 156 | + $c1 = ($c1 & 0x03) << 4; |
|
| 157 | + if ($i >= 16) { |
|
| 158 | + $output .= $itoa64[$c1]; |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $c2 = ord($input[$i++]); |
|
| 163 | + $c1 |= $c2 >> 4; |
|
| 164 | + $output .= $itoa64[$c1]; |
|
| 165 | + $c1 = ($c2 & 0x0f) << 2; |
|
| 166 | + |
|
| 167 | + $c2 = ord($input[$i++]); |
|
| 168 | + $c1 |= $c2 >> 6; |
|
| 169 | + $output .= $itoa64[$c1]; |
|
| 170 | + $output .= $itoa64[$c2 & 0x3f]; |
|
| 171 | + } while (1); |
|
| 172 | + |
|
| 173 | + return $output; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | if ( $this->ion_auth_model->forgotten_password($identity) ) //changed |
| 134 | 134 | { |
| 135 | 135 | // Get user information |
| 136 | - $identifier = $this->ion_auth_model->identity_column; // use model identity column, so it can be overridden in a controller |
|
| 137 | - $user = $this->where($identifier, $identity)->where('active', 1)->users()->row(); // changed to get_user_by_identity from email |
|
| 136 | + $identifier = $this->ion_auth_model->identity_column; // use model identity column, so it can be overridden in a controller |
|
| 137 | + $user = $this->where($identifier, $identity)->where('active', 1)->users()->row(); // changed to get_user_by_identity from email |
|
| 138 | 138 | |
| 139 | 139 | if ($user) |
| 140 | 140 | { |
@@ -388,14 +388,14 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | $identity = $this->config->item('identity', 'ion_auth'); |
| 390 | 390 | |
| 391 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 391 | + if (substr(CI_VERSION, 0, 1) == '2') |
|
| 392 | 392 | { |
| 393 | 393 | $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
| 394 | - } |
|
| 395 | - else |
|
| 396 | - { |
|
| 397 | - $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 398 | - } |
|
| 394 | + } |
|
| 395 | + else |
|
| 396 | + { |
|
| 397 | + $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | 400 | // delete the remember me cookies if they exist |
| 401 | 401 | if (get_cookie($this->config->item('identity_cookie_name', 'ion_auth'))) |
@@ -437,15 +437,15 @@ discard block |
||
| 437 | 437 | { |
| 438 | 438 | $this->ion_auth_model->trigger_events('logged_in'); |
| 439 | 439 | |
| 440 | - $recheck= $this->ion_auth_model->recheck_session(); |
|
| 440 | + $recheck= $this->ion_auth_model->recheck_session(); |
|
| 441 | 441 | |
| 442 | - //auto-login the user if they are remembered |
|
| 443 | - if ( ! $recheck && get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) && get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 442 | + //auto-login the user if they are remembered |
|
| 443 | + if ( ! $recheck && get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) && get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 444 | 444 | { |
| 445 | 445 | $recheck = $this->ion_auth_model->login_remembered_user(); |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - return $recheck; |
|
| 448 | + return $recheck; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -23,487 +23,487 @@ |
||
| 23 | 23 | |
| 24 | 24 | class Gravatar { |
| 25 | 25 | |
| 26 | - protected $defaults; |
|
| 27 | - |
|
| 28 | - protected $gravatar_base_url; |
|
| 29 | - protected $gravatar_secure_base_url; |
|
| 30 | - protected $gravatar_image_extension; |
|
| 31 | - protected $gravatar_image_size; |
|
| 32 | - protected $gravatar_default_image; |
|
| 33 | - protected $gravatar_force_default_image; |
|
| 34 | - protected $gravatar_rating ; |
|
| 35 | - protected $gravatar_useragent; |
|
| 26 | + protected $defaults; |
|
| 27 | + |
|
| 28 | + protected $gravatar_base_url; |
|
| 29 | + protected $gravatar_secure_base_url; |
|
| 30 | + protected $gravatar_image_extension; |
|
| 31 | + protected $gravatar_image_size; |
|
| 32 | + protected $gravatar_default_image; |
|
| 33 | + protected $gravatar_force_default_image; |
|
| 34 | + protected $gravatar_rating ; |
|
| 35 | + protected $gravatar_useragent; |
|
| 36 | 36 | |
| 37 | - protected $last_error = GRAVATAR_NO_ERROR; |
|
| 38 | - |
|
| 39 | - protected $is_https; |
|
| 40 | - protected $curl_exists; |
|
| 41 | - protected $allow_url_fopen; |
|
| 42 | - |
|
| 43 | - public function __construct($config = array()) { |
|
| 44 | - |
|
| 45 | - $this->defaults = array( |
|
| 46 | - 'gravatar_base_url' => 'http://www.gravatar.com/', |
|
| 47 | - 'gravatar_secure_base_url' => 'https://secure.gravatar.com/', |
|
| 48 | - 'gravatar_image_extension' => '.png', |
|
| 49 | - 'gravatar_image_size' => 80, |
|
| 50 | - 'gravatar_default_image' => '', |
|
| 51 | - 'gravatar_force_default_image' => false, |
|
| 52 | - 'gravatar_rating' => '', |
|
| 53 | - 'gravatar_useragent' => 'PHP Gravatar Library', |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - $this->is_https = $this->is_https(); |
|
| 57 | - $this->curl_exists = function_exists('curl_init'); |
|
| 58 | - $allow_url_fopen = @ini_get('allow_url_fopen'); |
|
| 59 | - $allow_url_fopen = $allow_url_fopen === false || in_array(strtolower($allow_url_fopen), array('on', 'true', '1')); |
|
| 60 | - $this->allow_url_fopen = $allow_url_fopen; |
|
| 61 | - |
|
| 62 | - if (!is_array($config)) { |
|
| 63 | - $config = array(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $this->defaults = array_merge($this->defaults, $config); |
|
| 67 | - $this->initialize($this->defaults); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function initialize($config = array()) { |
|
| 71 | - |
|
| 72 | - if (!is_array($config)) { |
|
| 73 | - $config = array(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - foreach ($config as $key => $value) { |
|
| 77 | - $this->{$key} = $value; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $this->gravatar_base_url = (string) $this->gravatar_base_url; |
|
| 81 | - $this->gravatar_secure_base_url = (string) $this->gravatar_secure_base_url; |
|
| 82 | - $this->gravatar_image_extension = (string) $this->gravatar_image_extension; |
|
| 83 | - |
|
| 84 | - $this->gravatar_image_size = (int) $this->gravatar_image_size; |
|
| 85 | - |
|
| 86 | - if ($this->gravatar_image_size <= 0) { |
|
| 87 | - $this->gravatar_image_size = 80; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->gravatar_default_image = (string) $this->gravatar_default_image; |
|
| 91 | - $this->gravatar_force_default_image = !empty($this->gravatar_force_default_image); |
|
| 92 | - $this->gravatar_rating = (string) $this->gravatar_rating; |
|
| 93 | - $this->gravatar_useragent = (string) $this->gravatar_useragent; |
|
| 94 | - |
|
| 95 | - return $this; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function reset() { |
|
| 99 | - |
|
| 100 | - $this->initialize($this->defaults); |
|
| 101 | - |
|
| 102 | - return $this; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function get_defaults() { |
|
| 106 | - |
|
| 107 | - return $this->defaults; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Creates a URL for requesting a Gravatar image. |
|
| 112 | - * @link http://en.gravatar.com/site/implement/images/ |
|
| 113 | - * |
|
| 114 | - * @param string $email A registered email. |
|
| 115 | - * @param int $size The requested size of the avarar in pixels (a square image). |
|
| 116 | - * @param string $default_image The fallback image option: '', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'. |
|
| 117 | - * @param bool $force_default_image Enforces the fallback image to be shown. |
|
| 118 | - * @param string $rating The level of allowed self-rate of the avatar: '', 'g' (default), 'pg', 'r', 'x'. |
|
| 119 | - * @return string Returns the URL of the avatar to be requested. |
|
| 120 | - * |
|
| 121 | - * When optional parameters are not set, their default values are taken |
|
| 122 | - * from the configuration file application/config/gravatar.php |
|
| 123 | - */ |
|
| 124 | - public function get($email, $size = null, $default_image = null, $force_default_image = null, $rating = null) { |
|
| 125 | - |
|
| 126 | - $url = ($this->is_https ? $this->gravatar_secure_base_url : $this->gravatar_base_url).'avatar/'.$this->create_hash($email).$this->gravatar_image_extension; |
|
| 127 | - |
|
| 128 | - $query = array(); |
|
| 129 | - |
|
| 130 | - $size = (int) $size; |
|
| 37 | + protected $last_error = GRAVATAR_NO_ERROR; |
|
| 38 | + |
|
| 39 | + protected $is_https; |
|
| 40 | + protected $curl_exists; |
|
| 41 | + protected $allow_url_fopen; |
|
| 42 | + |
|
| 43 | + public function __construct($config = array()) { |
|
| 44 | + |
|
| 45 | + $this->defaults = array( |
|
| 46 | + 'gravatar_base_url' => 'http://www.gravatar.com/', |
|
| 47 | + 'gravatar_secure_base_url' => 'https://secure.gravatar.com/', |
|
| 48 | + 'gravatar_image_extension' => '.png', |
|
| 49 | + 'gravatar_image_size' => 80, |
|
| 50 | + 'gravatar_default_image' => '', |
|
| 51 | + 'gravatar_force_default_image' => false, |
|
| 52 | + 'gravatar_rating' => '', |
|
| 53 | + 'gravatar_useragent' => 'PHP Gravatar Library', |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + $this->is_https = $this->is_https(); |
|
| 57 | + $this->curl_exists = function_exists('curl_init'); |
|
| 58 | + $allow_url_fopen = @ini_get('allow_url_fopen'); |
|
| 59 | + $allow_url_fopen = $allow_url_fopen === false || in_array(strtolower($allow_url_fopen), array('on', 'true', '1')); |
|
| 60 | + $this->allow_url_fopen = $allow_url_fopen; |
|
| 61 | + |
|
| 62 | + if (!is_array($config)) { |
|
| 63 | + $config = array(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $this->defaults = array_merge($this->defaults, $config); |
|
| 67 | + $this->initialize($this->defaults); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function initialize($config = array()) { |
|
| 71 | + |
|
| 72 | + if (!is_array($config)) { |
|
| 73 | + $config = array(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + foreach ($config as $key => $value) { |
|
| 77 | + $this->{$key} = $value; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $this->gravatar_base_url = (string) $this->gravatar_base_url; |
|
| 81 | + $this->gravatar_secure_base_url = (string) $this->gravatar_secure_base_url; |
|
| 82 | + $this->gravatar_image_extension = (string) $this->gravatar_image_extension; |
|
| 83 | + |
|
| 84 | + $this->gravatar_image_size = (int) $this->gravatar_image_size; |
|
| 85 | + |
|
| 86 | + if ($this->gravatar_image_size <= 0) { |
|
| 87 | + $this->gravatar_image_size = 80; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->gravatar_default_image = (string) $this->gravatar_default_image; |
|
| 91 | + $this->gravatar_force_default_image = !empty($this->gravatar_force_default_image); |
|
| 92 | + $this->gravatar_rating = (string) $this->gravatar_rating; |
|
| 93 | + $this->gravatar_useragent = (string) $this->gravatar_useragent; |
|
| 94 | + |
|
| 95 | + return $this; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function reset() { |
|
| 99 | + |
|
| 100 | + $this->initialize($this->defaults); |
|
| 101 | + |
|
| 102 | + return $this; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function get_defaults() { |
|
| 106 | + |
|
| 107 | + return $this->defaults; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Creates a URL for requesting a Gravatar image. |
|
| 112 | + * @link http://en.gravatar.com/site/implement/images/ |
|
| 113 | + * |
|
| 114 | + * @param string $email A registered email. |
|
| 115 | + * @param int $size The requested size of the avarar in pixels (a square image). |
|
| 116 | + * @param string $default_image The fallback image option: '', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'. |
|
| 117 | + * @param bool $force_default_image Enforces the fallback image to be shown. |
|
| 118 | + * @param string $rating The level of allowed self-rate of the avatar: '', 'g' (default), 'pg', 'r', 'x'. |
|
| 119 | + * @return string Returns the URL of the avatar to be requested. |
|
| 120 | + * |
|
| 121 | + * When optional parameters are not set, their default values are taken |
|
| 122 | + * from the configuration file application/config/gravatar.php |
|
| 123 | + */ |
|
| 124 | + public function get($email, $size = null, $default_image = null, $force_default_image = null, $rating = null) { |
|
| 125 | + |
|
| 126 | + $url = ($this->is_https ? $this->gravatar_secure_base_url : $this->gravatar_base_url).'avatar/'.$this->create_hash($email).$this->gravatar_image_extension; |
|
| 127 | + |
|
| 128 | + $query = array(); |
|
| 129 | + |
|
| 130 | + $size = (int) $size; |
|
| 131 | 131 | |
| 132 | - if ($size <= 0) { |
|
| 133 | - $size = $this->gravatar_image_size; |
|
| 134 | - } |
|
| 132 | + if ($size <= 0) { |
|
| 133 | + $size = $this->gravatar_image_size; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if ($size > 0) { |
|
| 137 | - $query['s'] = $size; |
|
| 138 | - } |
|
| 136 | + if ($size > 0) { |
|
| 137 | + $query['s'] = $size; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if (isset($default_image)) { |
|
| 141 | - $default_image = (string) $default_image; |
|
| 142 | - } else { |
|
| 143 | - $default_image = $this->gravatar_default_image; |
|
| 144 | - } |
|
| 140 | + if (isset($default_image)) { |
|
| 141 | + $default_image = (string) $default_image; |
|
| 142 | + } else { |
|
| 143 | + $default_image = $this->gravatar_default_image; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - if ($default_image != '') { |
|
| 147 | - $query['d'] = $default_image; |
|
| 148 | - } |
|
| 146 | + if ($default_image != '') { |
|
| 147 | + $query['d'] = $default_image; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if (isset($force_default_image)) { |
|
| 151 | - $force_default_image = !empty($force_default_image); |
|
| 152 | - } else { |
|
| 153 | - $force_default_image = $this->gravatar_force_default_image; |
|
| 154 | - } |
|
| 150 | + if (isset($force_default_image)) { |
|
| 151 | + $force_default_image = !empty($force_default_image); |
|
| 152 | + } else { |
|
| 153 | + $force_default_image = $this->gravatar_force_default_image; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - if ($force_default_image) { |
|
| 157 | - $query['f'] = 'y'; |
|
| 158 | - } |
|
| 156 | + if ($force_default_image) { |
|
| 157 | + $query['f'] = 'y'; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - if (isset($rating)) { |
|
| 161 | - $rating = (string) $rating; |
|
| 162 | - } else { |
|
| 163 | - $rating = $this->gravatar_rating; |
|
| 164 | - } |
|
| 160 | + if (isset($rating)) { |
|
| 161 | + $rating = (string) $rating; |
|
| 162 | + } else { |
|
| 163 | + $rating = $this->gravatar_rating; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if ($rating != '') { |
|
| 167 | - $query['r'] = $rating; |
|
| 168 | - } |
|
| 166 | + if ($rating != '') { |
|
| 167 | + $query['r'] = $rating; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - if (!empty($query)) { |
|
| 171 | - $url = $url.'?'.http_build_query($query); |
|
| 172 | - } |
|
| 170 | + if (!empty($query)) { |
|
| 171 | + $url = $url.'?'.http_build_query($query); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - return $url; |
|
| 175 | - } |
|
| 174 | + return $url; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Executes a request for Gravatar profile data and returns it as a multidimensional array. |
|
| 179 | - * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 180 | - * |
|
| 181 | - * @param string $email A registered email. |
|
| 182 | - * @return array/null Received profile data. |
|
| 183 | - */ |
|
| 184 | - public function get_profile_data($email) { |
|
| 177 | + /** |
|
| 178 | + * Executes a request for Gravatar profile data and returns it as a multidimensional array. |
|
| 179 | + * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 180 | + * |
|
| 181 | + * @param string $email A registered email. |
|
| 182 | + * @return array/null Received profile data. |
|
| 183 | + */ |
|
| 184 | + public function get_profile_data($email) { |
|
| 185 | 185 | |
| 186 | - $result = $this->execute_profile_request($email, 'php'); |
|
| 186 | + $result = $this->execute_profile_request($email, 'php'); |
|
| 187 | 187 | |
| 188 | - if ($this->last_error != GRAVATAR_NO_ERROR) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 188 | + if ($this->last_error != GRAVATAR_NO_ERROR) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - $result = @ unserialize($result); |
|
| 192 | + $result = @ unserialize($result); |
|
| 193 | 193 | |
| 194 | - if ($result === false) { |
|
| 194 | + if ($result === false) { |
|
| 195 | 195 | |
| 196 | - $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 197 | - return null; |
|
| 198 | - } |
|
| 196 | + $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 197 | + return null; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - if (!is_array($result)) { |
|
| 200 | + if (!is_array($result)) { |
|
| 201 | 201 | |
| 202 | - $this->last_error = GRAVATAR_PROFILE_DOES_NOT_EXIST; |
|
| 203 | - return null; |
|
| 204 | - } |
|
| 202 | + $this->last_error = GRAVATAR_PROFILE_DOES_NOT_EXIST; |
|
| 203 | + return null; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - if (!isset($result['entry']) || !isset($result['entry'][0])) { |
|
| 206 | + if (!isset($result['entry']) || !isset($result['entry'][0])) { |
|
| 207 | 207 | |
| 208 | - $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 209 | - return null; |
|
| 210 | - } |
|
| 208 | + $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 209 | + return null; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - return $result['entry'][0]; |
|
| 213 | - } |
|
| 212 | + return $result['entry'][0]; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Executes a request for Gravatar profile data and returns raw received response. |
|
| 217 | - * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 218 | - * |
|
| 219 | - * @param string $email A registered email. |
|
| 220 | - * @param string $format '', 'json', 'xml', 'php', 'vcf', 'qr'. |
|
| 221 | - * @return string/null Received profile raw data. |
|
| 222 | - */ |
|
| 223 | - public function execute_profile_request($email, $format = null) { |
|
| 215 | + /** |
|
| 216 | + * Executes a request for Gravatar profile data and returns raw received response. |
|
| 217 | + * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 218 | + * |
|
| 219 | + * @param string $email A registered email. |
|
| 220 | + * @param string $format '', 'json', 'xml', 'php', 'vcf', 'qr'. |
|
| 221 | + * @return string/null Received profile raw data. |
|
| 222 | + */ |
|
| 223 | + public function execute_profile_request($email, $format = null) { |
|
| 224 | 224 | |
| 225 | - $this->last_error = GRAVATAR_NO_ERROR; |
|
| 225 | + $this->last_error = GRAVATAR_NO_ERROR; |
|
| 226 | 226 | |
| 227 | - if (function_exists('valid_email')) { |
|
| 227 | + if (function_exists('valid_email')) { |
|
| 228 | 228 | |
| 229 | - if (!valid_email($email)) { |
|
| 229 | + if (!valid_email($email)) { |
|
| 230 | 230 | |
| 231 | - $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 232 | - return null; |
|
| 233 | - } |
|
| 231 | + $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 232 | + return null; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - } else { |
|
| 235 | + } else { |
|
| 236 | 236 | |
| 237 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 237 | + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 238 | 238 | |
| 239 | - $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 240 | - return null; |
|
| 241 | - } |
|
| 242 | - } |
|
| 239 | + $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 240 | + return null; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - $format = trim($format); |
|
| 244 | + $format = trim($format); |
|
| 245 | 245 | |
| 246 | - if ($format != '') { |
|
| 247 | - $format = '.'.ltrim($format, '.'); |
|
| 248 | - } |
|
| 246 | + if ($format != '') { |
|
| 247 | + $format = '.'.ltrim($format, '.'); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - $result = null; |
|
| 250 | + $result = null; |
|
| 251 | 251 | |
| 252 | - if ($this->curl_exists) { |
|
| 252 | + if ($this->curl_exists) { |
|
| 253 | 253 | |
| 254 | - $url = $this->gravatar_secure_base_url.$this->create_hash($email).$format; |
|
| 254 | + $url = $this->gravatar_secure_base_url.$this->create_hash($email).$format; |
|
| 255 | 255 | |
| 256 | - $ch = curl_init(); |
|
| 256 | + $ch = curl_init(); |
|
| 257 | 257 | |
| 258 | - $options = array( |
|
| 259 | - CURLOPT_USERAGENT, $this->gravatar_useragent, |
|
| 260 | - CURLOPT_RETURNTRANSFER => true, |
|
| 261 | - CURLOPT_POST => true, |
|
| 262 | - CURLOPT_POSTFIELDS => array(), |
|
| 263 | - CURLOPT_URL => $url, |
|
| 264 | - CURLOPT_TIMEOUT => 3, |
|
| 265 | - ); |
|
| 258 | + $options = array( |
|
| 259 | + CURLOPT_USERAGENT, $this->gravatar_useragent, |
|
| 260 | + CURLOPT_RETURNTRANSFER => true, |
|
| 261 | + CURLOPT_POST => true, |
|
| 262 | + CURLOPT_POSTFIELDS => array(), |
|
| 263 | + CURLOPT_URL => $url, |
|
| 264 | + CURLOPT_TIMEOUT => 3, |
|
| 265 | + ); |
|
| 266 | 266 | |
| 267 | - if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
| 268 | - $options[CURLOPT_FOLLOWLOCATION] = true; |
|
| 269 | - } |
|
| 267 | + if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
| 268 | + $options[CURLOPT_FOLLOWLOCATION] = true; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - curl_setopt_array($ch, $options); |
|
| 271 | + curl_setopt_array($ch, $options); |
|
| 272 | 272 | |
| 273 | - $result = curl_exec($ch); |
|
| 273 | + $result = curl_exec($ch); |
|
| 274 | 274 | |
| 275 | - $code = @ curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 275 | + $code = @ curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 276 | 276 | |
| 277 | - @ curl_close($ch); |
|
| 277 | + @ curl_close($ch); |
|
| 278 | 278 | |
| 279 | - if ($code != 200) { |
|
| 279 | + if ($code != 200) { |
|
| 280 | 280 | |
| 281 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 282 | - return null; |
|
| 283 | - } |
|
| 281 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 282 | + return null; |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - } elseif ($this->allow_url_fopen) { |
|
| 285 | + } elseif ($this->allow_url_fopen) { |
|
| 286 | 286 | |
| 287 | - $url = $this->gravatar_base_url.$this->create_hash($email).$format; |
|
| 287 | + $url = $this->gravatar_base_url.$this->create_hash($email).$format; |
|
| 288 | 288 | |
| 289 | - $options = array( |
|
| 290 | - 'http' => array( |
|
| 291 | - 'method' => 'GET', |
|
| 292 | - 'useragent' => $this->gravatar_useragent, |
|
| 293 | - ), |
|
| 294 | - ); |
|
| 289 | + $options = array( |
|
| 290 | + 'http' => array( |
|
| 291 | + 'method' => 'GET', |
|
| 292 | + 'useragent' => $this->gravatar_useragent, |
|
| 293 | + ), |
|
| 294 | + ); |
|
| 295 | 295 | |
| 296 | - $context = stream_context_create($options); |
|
| 296 | + $context = stream_context_create($options); |
|
| 297 | 297 | |
| 298 | - $result = @ file_get_contents($url, false, $context); |
|
| 298 | + $result = @ file_get_contents($url, false, $context); |
|
| 299 | 299 | |
| 300 | - } else { |
|
| 300 | + } else { |
|
| 301 | 301 | |
| 302 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 303 | - return null; |
|
| 304 | - } |
|
| 302 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 303 | + return null; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - if ($result === false) { |
|
| 306 | + if ($result === false) { |
|
| 307 | 307 | |
| 308 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 309 | - return null; |
|
| 310 | - } |
|
| 308 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 309 | + return null; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - return $result; |
|
| 313 | - } |
|
| 312 | + return $result; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Returns the error code as a result of the last profile request operation. |
|
| 317 | - * |
|
| 318 | - * @return int GRAVATAR_NO_ERROR - the last operation was successfull, |
|
| 319 | - * other returned value indicates failure. |
|
| 320 | - */ |
|
| 321 | - public function last_error() { |
|
| 315 | + /** |
|
| 316 | + * Returns the error code as a result of the last profile request operation. |
|
| 317 | + * |
|
| 318 | + * @return int GRAVATAR_NO_ERROR - the last operation was successfull, |
|
| 319 | + * other returned value indicates failure. |
|
| 320 | + */ |
|
| 321 | + public function last_error() { |
|
| 322 | 322 | |
| 323 | - return $this->last_error; |
|
| 324 | - } |
|
| 323 | + return $this->last_error; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Creates a hash value from a provided e-mail address. |
|
| 328 | - * @link https://en.gravatar.com/site/implement/hash/ |
|
| 329 | - * |
|
| 330 | - * @param string $email A registered email. |
|
| 331 | - * @return string/null The hash for accessing the avatar or profile data. |
|
| 332 | - */ |
|
| 333 | - public function create_hash($email) { |
|
| 334 | - |
|
| 335 | - return md5(strtolower(trim($email))); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - protected function is_https() { |
|
| 339 | - |
|
| 340 | - if (function_exists('is_https')) { |
|
| 341 | - return is_https(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 345 | - return true; |
|
| 346 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 347 | - return true; |
|
| 348 | - } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 349 | - return true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - //-------------------------------------------------------------------------- |
|
| 356 | - // The following original methods are kept here for backward compatibility. |
|
| 357 | - // Consider them as deprecated. |
|
| 358 | - //-------------------------------------------------------------------------- |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Set the email to be used, converting it into an md5 hash as required by gravatar.com |
|
| 363 | - * |
|
| 364 | - * @param string $email |
|
| 365 | - * |
|
| 366 | - * @return string|null Email hash or if email didn't validate then return NULL |
|
| 367 | - * |
|
| 368 | - * @deprecated |
|
| 369 | - */ |
|
| 370 | - public function set_email($email) |
|
| 371 | - { |
|
| 372 | - $email = trim(strtolower($email)); |
|
| 373 | - |
|
| 374 | - if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 375 | - { |
|
| 376 | - return md5($email); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return NULL; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * get_gravatar_url |
|
| 384 | - * |
|
| 385 | - * @see http://en.gravatar.com/site/implement/images/ for available options |
|
| 386 | - * |
|
| 387 | - * @param string $rating defaults to g |
|
| 388 | - * @param string $size defaults to 80 |
|
| 389 | - * @param string $default_image default sets can be found on the above link |
|
| 390 | - * @param boolean $secure set to TRUE if a secure url is required |
|
| 391 | - * |
|
| 392 | - * @return string gratavar url |
|
| 393 | - * |
|
| 394 | - * @deprecated |
|
| 395 | - */ |
|
| 396 | - public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) |
|
| 397 | - { |
|
| 398 | - $hash = $this->set_email($email); |
|
| 399 | - |
|
| 400 | - if ($hash === NULL) |
|
| 401 | - { |
|
| 402 | - // $hash has to be set to a value so the gravatar site can return a default image |
|
| 403 | - $hash = 'invalid_email'; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - $query_string = NULL; |
|
| 407 | - $options = array(); |
|
| 408 | - |
|
| 409 | - if ($rating !== NULL) |
|
| 410 | - { |
|
| 411 | - $options['r'] = $rating; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - if ($size !== NULL) |
|
| 415 | - { |
|
| 416 | - $options['s'] = $size; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if ($default_image !== NULL) |
|
| 420 | - { |
|
| 421 | - $options['d'] = urlencode($default_image); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - if (count($options) > 0) |
|
| 425 | - { |
|
| 426 | - $query_string = '?'. http_build_query($options); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - if ($secure !== NULL) |
|
| 430 | - { |
|
| 431 | - $base = $this->gravatar_secure_base_url; |
|
| 432 | - } |
|
| 433 | - else |
|
| 434 | - { |
|
| 435 | - $base = $this->gravatar_base_url; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $base .'avatar/'. $hash . $query_string; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Grab the full profile data for a given email from gravatar.com in xml format |
|
| 443 | - * |
|
| 444 | - * @param string $email |
|
| 445 | - * @param string fetch_method defaults to file, 'curl' is the other option |
|
| 446 | - * |
|
| 447 | - * @return object|null $xml->entry on success, NULL on an error |
|
| 448 | - * |
|
| 449 | - * @deprecated |
|
| 450 | - */ |
|
| 451 | - public function get_profile($email, $fetch_method = 'file') |
|
| 452 | - { |
|
| 453 | - $hash = $this->set_email($email); |
|
| 454 | - |
|
| 455 | - if ($hash === NULL) |
|
| 456 | - { |
|
| 457 | - // A hash value of NULL will return no xml so the method returns NULL |
|
| 458 | - return NULL; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - libxml_use_internal_errors(TRUE); |
|
| 462 | - |
|
| 463 | - if ($fetch_method === 'file') |
|
| 464 | - { |
|
| 465 | - if (ini_get('allow_url_fopen') == FALSE) |
|
| 466 | - { |
|
| 467 | - return NULL; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $str = file_get_contents($this->gravatar_base_url . $hash .'.xml'); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - if ($fetch_method === 'curl') |
|
| 474 | - { |
|
| 475 | - if ( ! function_exists('curl_init')) |
|
| 476 | - { |
|
| 477 | - return NULL; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $ch = curl_init(); |
|
| 481 | - $options = array( |
|
| 482 | - CURLOPT_RETURNTRANSFER => TRUE, |
|
| 483 | - CURLOPT_POST => TRUE, |
|
| 484 | - CURLOPT_URL => $this->gravatar_secure_base_url . $hash .'.xml', |
|
| 485 | - CURLOPT_TIMEOUT => 3 |
|
| 486 | - ); |
|
| 487 | - curl_setopt_array($ch, $options); |
|
| 488 | - $str = curl_exec($ch); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $xml = simplexml_load_string($str); |
|
| 492 | - |
|
| 493 | - if ($xml === FALSE) |
|
| 494 | - { |
|
| 495 | - $errors = array(); |
|
| 496 | - foreach(libxml_get_errors() as $error) |
|
| 497 | - { |
|
| 498 | - $errors[] = $error->message.'\n'; |
|
| 499 | - } |
|
| 500 | - $error_string = implode('\n', $errors); |
|
| 501 | - throw new Exception('Failed loading XML\n'. $error_string); |
|
| 502 | - } |
|
| 503 | - else |
|
| 504 | - { |
|
| 505 | - return $xml->entry; |
|
| 506 | - } |
|
| 507 | - } |
|
| 326 | + /** |
|
| 327 | + * Creates a hash value from a provided e-mail address. |
|
| 328 | + * @link https://en.gravatar.com/site/implement/hash/ |
|
| 329 | + * |
|
| 330 | + * @param string $email A registered email. |
|
| 331 | + * @return string/null The hash for accessing the avatar or profile data. |
|
| 332 | + */ |
|
| 333 | + public function create_hash($email) { |
|
| 334 | + |
|
| 335 | + return md5(strtolower(trim($email))); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + protected function is_https() { |
|
| 339 | + |
|
| 340 | + if (function_exists('is_https')) { |
|
| 341 | + return is_https(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 345 | + return true; |
|
| 346 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 347 | + return true; |
|
| 348 | + } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 349 | + return true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + //-------------------------------------------------------------------------- |
|
| 356 | + // The following original methods are kept here for backward compatibility. |
|
| 357 | + // Consider them as deprecated. |
|
| 358 | + //-------------------------------------------------------------------------- |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Set the email to be used, converting it into an md5 hash as required by gravatar.com |
|
| 363 | + * |
|
| 364 | + * @param string $email |
|
| 365 | + * |
|
| 366 | + * @return string|null Email hash or if email didn't validate then return NULL |
|
| 367 | + * |
|
| 368 | + * @deprecated |
|
| 369 | + */ |
|
| 370 | + public function set_email($email) |
|
| 371 | + { |
|
| 372 | + $email = trim(strtolower($email)); |
|
| 373 | + |
|
| 374 | + if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 375 | + { |
|
| 376 | + return md5($email); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return NULL; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * get_gravatar_url |
|
| 384 | + * |
|
| 385 | + * @see http://en.gravatar.com/site/implement/images/ for available options |
|
| 386 | + * |
|
| 387 | + * @param string $rating defaults to g |
|
| 388 | + * @param string $size defaults to 80 |
|
| 389 | + * @param string $default_image default sets can be found on the above link |
|
| 390 | + * @param boolean $secure set to TRUE if a secure url is required |
|
| 391 | + * |
|
| 392 | + * @return string gratavar url |
|
| 393 | + * |
|
| 394 | + * @deprecated |
|
| 395 | + */ |
|
| 396 | + public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) |
|
| 397 | + { |
|
| 398 | + $hash = $this->set_email($email); |
|
| 399 | + |
|
| 400 | + if ($hash === NULL) |
|
| 401 | + { |
|
| 402 | + // $hash has to be set to a value so the gravatar site can return a default image |
|
| 403 | + $hash = 'invalid_email'; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + $query_string = NULL; |
|
| 407 | + $options = array(); |
|
| 408 | + |
|
| 409 | + if ($rating !== NULL) |
|
| 410 | + { |
|
| 411 | + $options['r'] = $rating; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + if ($size !== NULL) |
|
| 415 | + { |
|
| 416 | + $options['s'] = $size; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if ($default_image !== NULL) |
|
| 420 | + { |
|
| 421 | + $options['d'] = urlencode($default_image); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + if (count($options) > 0) |
|
| 425 | + { |
|
| 426 | + $query_string = '?'. http_build_query($options); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + if ($secure !== NULL) |
|
| 430 | + { |
|
| 431 | + $base = $this->gravatar_secure_base_url; |
|
| 432 | + } |
|
| 433 | + else |
|
| 434 | + { |
|
| 435 | + $base = $this->gravatar_base_url; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $base .'avatar/'. $hash . $query_string; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Grab the full profile data for a given email from gravatar.com in xml format |
|
| 443 | + * |
|
| 444 | + * @param string $email |
|
| 445 | + * @param string fetch_method defaults to file, 'curl' is the other option |
|
| 446 | + * |
|
| 447 | + * @return object|null $xml->entry on success, NULL on an error |
|
| 448 | + * |
|
| 449 | + * @deprecated |
|
| 450 | + */ |
|
| 451 | + public function get_profile($email, $fetch_method = 'file') |
|
| 452 | + { |
|
| 453 | + $hash = $this->set_email($email); |
|
| 454 | + |
|
| 455 | + if ($hash === NULL) |
|
| 456 | + { |
|
| 457 | + // A hash value of NULL will return no xml so the method returns NULL |
|
| 458 | + return NULL; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + libxml_use_internal_errors(TRUE); |
|
| 462 | + |
|
| 463 | + if ($fetch_method === 'file') |
|
| 464 | + { |
|
| 465 | + if (ini_get('allow_url_fopen') == FALSE) |
|
| 466 | + { |
|
| 467 | + return NULL; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $str = file_get_contents($this->gravatar_base_url . $hash .'.xml'); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + if ($fetch_method === 'curl') |
|
| 474 | + { |
|
| 475 | + if ( ! function_exists('curl_init')) |
|
| 476 | + { |
|
| 477 | + return NULL; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $ch = curl_init(); |
|
| 481 | + $options = array( |
|
| 482 | + CURLOPT_RETURNTRANSFER => TRUE, |
|
| 483 | + CURLOPT_POST => TRUE, |
|
| 484 | + CURLOPT_URL => $this->gravatar_secure_base_url . $hash .'.xml', |
|
| 485 | + CURLOPT_TIMEOUT => 3 |
|
| 486 | + ); |
|
| 487 | + curl_setopt_array($ch, $options); |
|
| 488 | + $str = curl_exec($ch); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $xml = simplexml_load_string($str); |
|
| 492 | + |
|
| 493 | + if ($xml === FALSE) |
|
| 494 | + { |
|
| 495 | + $errors = array(); |
|
| 496 | + foreach(libxml_get_errors() as $error) |
|
| 497 | + { |
|
| 498 | + $errors[] = $error->message.'\n'; |
|
| 499 | + } |
|
| 500 | + $error_string = implode('\n', $errors); |
|
| 501 | + throw new Exception('Failed loading XML\n'. $error_string); |
|
| 502 | + } |
|
| 503 | + else |
|
| 504 | + { |
|
| 505 | + return $xml->entry; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | 508 | |
| 509 | 509 | } |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | if (!function_exists('gravatar')) { |
| 9 | 9 | |
| 10 | - // This helper function has been added here for compatibility with PyroCMS. |
|
| 11 | - function gravatar($email = '', $size = 50, $rating = 'g', $url_only = false, $default = false) { |
|
| 10 | + // This helper function has been added here for compatibility with PyroCMS. |
|
| 11 | + function gravatar($email = '', $size = 50, $rating = 'g', $url_only = false, $default = false) { |
|
| 12 | 12 | |
| 13 | - $ci = & get_instance(); |
|
| 14 | - $ci->load->library('gravatar'); |
|
| 13 | + $ci = & get_instance(); |
|
| 14 | + $ci->load->library('gravatar'); |
|
| 15 | 15 | |
| 16 | - if (@ (string) $default == '') { |
|
| 17 | - $default = null; |
|
| 18 | - } |
|
| 16 | + if (@ (string) $default == '') { |
|
| 17 | + $default = null; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - $gravatar_url = $ci->gravatar->get($email, $size, $default, null, $rating); |
|
| 20 | + $gravatar_url = $ci->gravatar->get($email, $size, $default, null, $rating); |
|
| 21 | 21 | |
| 22 | - if ($url_only) { |
|
| 23 | - return $gravatar_url; |
|
| 24 | - } |
|
| 22 | + if ($url_only) { |
|
| 23 | + return $gravatar_url; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - return '<img src="'.$gravatar_url.'" alt="Gravatar" class="gravatar" />'; |
|
| 27 | - } |
|
| 26 | + return '<img src="'.$gravatar_url.'" alt="Gravatar" class="gravatar" />'; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! defined('BASEPATH')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |