@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Ion Auth Model |
| 4 | 6 | * |
@@ -19,8 +21,7 @@ discard block |
||
| 19 | 21 | * |
| 20 | 22 | */ |
| 21 | 23 | |
| 22 | -class Ion_auth_model extends CI_Model |
|
| 23 | -{ |
|
| 24 | +class Ion_auth_model extends CI_Model { |
|
| 24 | 25 | /** |
| 25 | 26 | * Holds an array of tables used |
| 26 | 27 | * |
@@ -161,8 +162,7 @@ discard block |
||
| 161 | 162 | **/ |
| 162 | 163 | protected $_cache_groups = array(); |
| 163 | 164 | |
| 164 | - public function __construct() |
|
| 165 | - { |
|
| 165 | + public function __construct() { |
|
| 166 | 166 | parent::__construct(); |
| 167 | 167 | $this->load->database(); |
| 168 | 168 | $this->config->load('ion_auth', TRUE); |
@@ -194,8 +194,7 @@ discard block |
||
| 194 | 194 | $delimiters_source = $this->config->item('delimiters_source', 'ion_auth'); |
| 195 | 195 | |
| 196 | 196 | // load the error delimeters either from the config file or use what's been supplied to form validation |
| 197 | - if ($delimiters_source === 'form_validation') |
|
| 198 | - { |
|
| 197 | + if ($delimiters_source === 'form_validation') { |
|
| 199 | 198 | // load in delimiters from form_validation |
| 200 | 199 | // to keep this simple we'll load the value using reflection since these properties are protected |
| 201 | 200 | $this->load->library('form_validation'); |
@@ -210,9 +209,7 @@ discard block |
||
| 210 | 209 | $error_suffix->setAccessible(TRUE); |
| 211 | 210 | $this->error_end_delimiter = $error_suffix->getValue($this->form_validation); |
| 212 | 211 | $this->message_end_delimiter = $this->error_end_delimiter; |
| 213 | - } |
|
| 214 | - else |
|
| 215 | - { |
|
| 212 | + } else { |
|
| 216 | 213 | // use delimiters from config |
| 217 | 214 | $this->message_start_delimiter = $this->config->item('message_start_delimiter', 'ion_auth'); |
| 218 | 215 | $this->message_end_delimiter = $this->config->item('message_end_delimiter', 'ion_auth'); |
@@ -226,13 +223,10 @@ discard block |
||
| 226 | 223 | |
| 227 | 224 | // load the bcrypt class if needed |
| 228 | 225 | if ($this->hash_method == 'bcrypt') { |
| 229 | - if ($this->random_rounds) |
|
| 230 | - { |
|
| 226 | + if ($this->random_rounds) { |
|
| 231 | 227 | $rand = rand($this->min_rounds,$this->max_rounds); |
| 232 | 228 | $params = array('rounds' => $rand); |
| 233 | - } |
|
| 234 | - else |
|
| 235 | - { |
|
| 229 | + } else { |
|
| 236 | 230 | $params = array('rounds' => $this->default_rounds); |
| 237 | 231 | } |
| 238 | 232 | |
@@ -260,26 +254,20 @@ discard block |
||
| 260 | 254 | * @return void |
| 261 | 255 | * @author Mathew |
| 262 | 256 | **/ |
| 263 | - public function hash_password($password, $salt=false, $use_sha1_override=FALSE) |
|
| 264 | - { |
|
| 265 | - if (empty($password)) |
|
| 266 | - { |
|
| 257 | + public function hash_password($password, $salt=false, $use_sha1_override=FALSE) { |
|
| 258 | + if (empty($password)) { |
|
| 267 | 259 | return FALSE; |
| 268 | 260 | } |
| 269 | 261 | |
| 270 | 262 | // bcrypt |
| 271 | - if ($use_sha1_override === FALSE && $this->hash_method == 'bcrypt') |
|
| 272 | - { |
|
| 263 | + if ($use_sha1_override === FALSE && $this->hash_method == 'bcrypt') { |
|
| 273 | 264 | return $this->bcrypt->hash($password); |
| 274 | 265 | } |
| 275 | 266 | |
| 276 | 267 | |
| 277 | - if ($this->store_salt && $salt) |
|
| 278 | - { |
|
| 268 | + if ($this->store_salt && $salt) { |
|
| 279 | 269 | return sha1($password . $salt); |
| 280 | - } |
|
| 281 | - else |
|
| 282 | - { |
|
| 270 | + } else { |
|
| 283 | 271 | $salt = $this->salt(); |
| 284 | 272 | return $salt . substr(sha1($salt . $password), 0, -$this->salt_length); |
| 285 | 273 | } |
@@ -292,10 +280,8 @@ discard block |
||
| 292 | 280 | * @return void |
| 293 | 281 | * @author Mathew |
| 294 | 282 | **/ |
| 295 | - public function hash_password_db($id, $password, $use_sha1_override=FALSE) |
|
| 296 | - { |
|
| 297 | - if (empty($id) || empty($password)) |
|
| 298 | - { |
|
| 283 | + public function hash_password_db($id, $password, $use_sha1_override=FALSE) { |
|
| 284 | + if (empty($id) || empty($password)) { |
|
| 299 | 285 | return FALSE; |
| 300 | 286 | } |
| 301 | 287 | |
@@ -309,16 +295,13 @@ discard block |
||
| 309 | 295 | |
| 310 | 296 | $hash_password_db = $query->row(); |
| 311 | 297 | |
| 312 | - if ($query->num_rows() !== 1) |
|
| 313 | - { |
|
| 298 | + if ($query->num_rows() !== 1) { |
|
| 314 | 299 | return FALSE; |
| 315 | 300 | } |
| 316 | 301 | |
| 317 | 302 | // bcrypt |
| 318 | - if ($use_sha1_override === FALSE && $this->hash_method == 'bcrypt') |
|
| 319 | - { |
|
| 320 | - if ($this->bcrypt->verify($password,$hash_password_db->password)) |
|
| 321 | - { |
|
| 303 | + if ($use_sha1_override === FALSE && $this->hash_method == 'bcrypt') { |
|
| 304 | + if ($this->bcrypt->verify($password,$hash_password_db->password)) { |
|
| 322 | 305 | return TRUE; |
| 323 | 306 | } |
| 324 | 307 | |
@@ -326,23 +309,17 @@ discard block |
||
| 326 | 309 | } |
| 327 | 310 | |
| 328 | 311 | // sha1 |
| 329 | - if ($this->store_salt) |
|
| 330 | - { |
|
| 312 | + if ($this->store_salt) { |
|
| 331 | 313 | $db_password = sha1($password . $hash_password_db->salt); |
| 332 | - } |
|
| 333 | - else |
|
| 334 | - { |
|
| 314 | + } else { |
|
| 335 | 315 | $salt = substr($hash_password_db->password, 0, $this->salt_length); |
| 336 | 316 | |
| 337 | 317 | $db_password = $salt . substr(sha1($salt . $password), 0, -$this->salt_length); |
| 338 | 318 | } |
| 339 | 319 | |
| 340 | - if($db_password == $hash_password_db->password) |
|
| 341 | - { |
|
| 320 | + if($db_password == $hash_password_db->password) { |
|
| 342 | 321 | return TRUE; |
| 343 | - } |
|
| 344 | - else |
|
| 345 | - { |
|
| 322 | + } else { |
|
| 346 | 323 | return FALSE; |
| 347 | 324 | } |
| 348 | 325 | } |
@@ -353,8 +330,7 @@ discard block |
||
| 353 | 330 | * @return void |
| 354 | 331 | * @author Mathew |
| 355 | 332 | **/ |
| 356 | - public function hash_code($password) |
|
| 357 | - { |
|
| 333 | + public function hash_code($password) { |
|
| 358 | 334 | return $this->hash_password($password, FALSE, TRUE); |
| 359 | 335 | } |
| 360 | 336 | |
@@ -366,8 +342,7 @@ discard block |
||
| 366 | 342 | * @return void |
| 367 | 343 | * @author Anthony Ferrera |
| 368 | 344 | **/ |
| 369 | - public function salt() |
|
| 370 | - { |
|
| 345 | + public function salt() { |
|
| 371 | 346 | |
| 372 | 347 | $raw_salt_len = 16; |
| 373 | 348 | |
@@ -449,12 +424,10 @@ discard block |
||
| 449 | 424 | * @return void |
| 450 | 425 | * @author Mathew |
| 451 | 426 | **/ |
| 452 | - public function activate($id, $code = false) |
|
| 453 | - { |
|
| 427 | + public function activate($id, $code = false) { |
|
| 454 | 428 | $this->trigger_events('pre_activate'); |
| 455 | 429 | |
| 456 | - if ($code !== FALSE) |
|
| 457 | - { |
|
| 430 | + if ($code !== FALSE) { |
|
| 458 | 431 | $query = $this->db->select($this->identity_column) |
| 459 | 432 | ->where('activation_code', $code) |
| 460 | 433 | ->where('id', $id) |
@@ -464,8 +437,7 @@ discard block |
||
| 464 | 437 | |
| 465 | 438 | $result = $query->row(); |
| 466 | 439 | |
| 467 | - if ($query->num_rows() !== 1) |
|
| 468 | - { |
|
| 440 | + if ($query->num_rows() !== 1) { |
|
| 469 | 441 | $this->trigger_events(array('post_activate', 'post_activate_unsuccessful')); |
| 470 | 442 | $this->set_error('activate_unsuccessful'); |
| 471 | 443 | return FALSE; |
@@ -478,9 +450,7 @@ discard block |
||
| 478 | 450 | |
| 479 | 451 | $this->trigger_events('extra_where'); |
| 480 | 452 | $this->db->update($this->tables['users'], $data, array('id' => $id)); |
| 481 | - } |
|
| 482 | - else |
|
| 483 | - { |
|
| 453 | + } else { |
|
| 484 | 454 | $data = array( |
| 485 | 455 | 'activation_code' => NULL, |
| 486 | 456 | 'active' => 1 |
@@ -493,13 +463,10 @@ discard block |
||
| 493 | 463 | |
| 494 | 464 | |
| 495 | 465 | $return = $this->db->affected_rows() == 1; |
| 496 | - if ($return) |
|
| 497 | - { |
|
| 466 | + if ($return) { |
|
| 498 | 467 | $this->trigger_events(array('post_activate', 'post_activate_successful')); |
| 499 | 468 | $this->set_message('activate_successful'); |
| 500 | - } |
|
| 501 | - else |
|
| 502 | - { |
|
| 469 | + } else { |
|
| 503 | 470 | $this->trigger_events(array('post_activate', 'post_activate_unsuccessful')); |
| 504 | 471 | $this->set_error('activate_unsuccessful'); |
| 505 | 472 | } |
@@ -515,17 +482,13 @@ discard block |
||
| 515 | 482 | * @return void |
| 516 | 483 | * @author Mathew |
| 517 | 484 | **/ |
| 518 | - public function deactivate($id = NULL) |
|
| 519 | - { |
|
| 485 | + public function deactivate($id = NULL) { |
|
| 520 | 486 | $this->trigger_events('deactivate'); |
| 521 | 487 | |
| 522 | - if (!isset($id)) |
|
| 523 | - { |
|
| 488 | + if (!isset($id)) { |
|
| 524 | 489 | $this->set_error('deactivate_unsuccessful'); |
| 525 | 490 | return FALSE; |
| 526 | - } |
|
| 527 | - elseif($this->ion_auth->logged_in() && $this->user()->row()->id == $id) |
|
| 528 | - { |
|
| 491 | + } elseif($this->ion_auth->logged_in() && $this->user()->row()->id == $id) { |
|
| 529 | 492 | $this->set_error('deactivate_current_user_unsuccessful'); |
| 530 | 493 | return FALSE; |
| 531 | 494 | } |
@@ -542,25 +505,24 @@ discard block |
||
| 542 | 505 | $this->db->update($this->tables['users'], $data, array('id' => $id)); |
| 543 | 506 | |
| 544 | 507 | $return = $this->db->affected_rows() == 1; |
| 545 | - if ($return) |
|
| 546 | - $this->set_message('deactivate_successful'); |
|
| 547 | - else |
|
| 548 | - $this->set_error('deactivate_unsuccessful'); |
|
| 508 | + if ($return) { |
|
| 509 | + $this->set_message('deactivate_successful'); |
|
| 510 | + } else { |
|
| 511 | + $this->set_error('deactivate_unsuccessful'); |
|
| 512 | + } |
|
| 549 | 513 | |
| 550 | 514 | return $return; |
| 551 | 515 | } |
| 552 | 516 | |
| 553 | 517 | public function clear_forgotten_password_code($code) { |
| 554 | 518 | |
| 555 | - if (empty($code)) |
|
| 556 | - { |
|
| 519 | + if (empty($code)) { |
|
| 557 | 520 | return FALSE; |
| 558 | 521 | } |
| 559 | 522 | |
| 560 | 523 | $this->db->where('forgotten_password_code', $code); |
| 561 | 524 | |
| 562 | - if ($this->db->count_all_results($this->tables['users']) > 0) |
|
| 563 | - { |
|
| 525 | + if ($this->db->count_all_results($this->tables['users']) > 0) { |
|
| 564 | 526 | $data = array( |
| 565 | 527 | 'forgotten_password_code' => NULL, |
| 566 | 528 | 'forgotten_password_time' => NULL |
@@ -596,8 +558,7 @@ discard block |
||
| 596 | 558 | ->order_by('id', 'desc') |
| 597 | 559 | ->get($this->tables['users']); |
| 598 | 560 | |
| 599 | - if ($query->num_rows() !== 1) |
|
| 600 | - { |
|
| 561 | + if ($query->num_rows() !== 1) { |
|
| 601 | 562 | $this->trigger_events(array('post_change_password', 'post_change_password_unsuccessful')); |
| 602 | 563 | $this->set_error('password_change_unsuccessful'); |
| 603 | 564 | return FALSE; |
@@ -620,13 +581,10 @@ discard block |
||
| 620 | 581 | $this->db->update($this->tables['users'], $data, array($this->identity_column => $identity)); |
| 621 | 582 | |
| 622 | 583 | $return = $this->db->affected_rows() == 1; |
| 623 | - if ($return) |
|
| 624 | - { |
|
| 584 | + if ($return) { |
|
| 625 | 585 | $this->trigger_events(array('post_change_password', 'post_change_password_successful')); |
| 626 | 586 | $this->set_message('password_change_successful'); |
| 627 | - } |
|
| 628 | - else |
|
| 629 | - { |
|
| 587 | + } else { |
|
| 630 | 588 | $this->trigger_events(array('post_change_password', 'post_change_password_unsuccessful')); |
| 631 | 589 | $this->set_error('password_change_unsuccessful'); |
| 632 | 590 | } |
@@ -640,8 +598,7 @@ discard block |
||
| 640 | 598 | * @return bool |
| 641 | 599 | * @author Mathew |
| 642 | 600 | **/ |
| 643 | - public function change_password($identity, $old, $new) |
|
| 644 | - { |
|
| 601 | + public function change_password($identity, $old, $new) { |
|
| 645 | 602 | $this->trigger_events('pre_change_password'); |
| 646 | 603 | |
| 647 | 604 | $this->trigger_events('extra_where'); |
@@ -652,8 +609,7 @@ discard block |
||
| 652 | 609 | ->order_by('id', 'desc') |
| 653 | 610 | ->get($this->tables['users']); |
| 654 | 611 | |
| 655 | - if ($query->num_rows() !== 1) |
|
| 656 | - { |
|
| 612 | + if ($query->num_rows() !== 1) { |
|
| 657 | 613 | $this->trigger_events(array('post_change_password', 'post_change_password_unsuccessful')); |
| 658 | 614 | $this->set_error('password_change_unsuccessful'); |
| 659 | 615 | return FALSE; |
@@ -663,8 +619,7 @@ discard block |
||
| 663 | 619 | |
| 664 | 620 | $old_password_matches = $this->hash_password_db($user->id, $old); |
| 665 | 621 | |
| 666 | - if ($old_password_matches === TRUE) |
|
| 667 | - { |
|
| 622 | + if ($old_password_matches === TRUE) { |
|
| 668 | 623 | // store the new password and reset the remember code so all remembered instances have to re-login |
| 669 | 624 | $hashed_new_password = $this->hash_password($new, $user->salt); |
| 670 | 625 | $data = array( |
@@ -675,13 +630,10 @@ discard block |
||
| 675 | 630 | $this->trigger_events('extra_where'); |
| 676 | 631 | |
| 677 | 632 | $successfully_changed_password_in_db = $this->db->update($this->tables['users'], $data, array($this->identity_column => $identity)); |
| 678 | - if ($successfully_changed_password_in_db) |
|
| 679 | - { |
|
| 633 | + if ($successfully_changed_password_in_db) { |
|
| 680 | 634 | $this->trigger_events(array('post_change_password', 'post_change_password_successful')); |
| 681 | 635 | $this->set_message('password_change_successful'); |
| 682 | - } |
|
| 683 | - else |
|
| 684 | - { |
|
| 636 | + } else { |
|
| 685 | 637 | $this->trigger_events(array('post_change_password', 'post_change_password_unsuccessful')); |
| 686 | 638 | $this->set_error('password_change_unsuccessful'); |
| 687 | 639 | } |
@@ -699,12 +651,10 @@ discard block |
||
| 699 | 651 | * @return bool |
| 700 | 652 | * @author Mathew |
| 701 | 653 | **/ |
| 702 | - public function username_check($username = '') |
|
| 703 | - { |
|
| 654 | + public function username_check($username = '') { |
|
| 704 | 655 | $this->trigger_events('username_check'); |
| 705 | 656 | |
| 706 | - if (empty($username)) |
|
| 707 | - { |
|
| 657 | + if (empty($username)) { |
|
| 708 | 658 | return FALSE; |
| 709 | 659 | } |
| 710 | 660 | |
@@ -723,12 +673,10 @@ discard block |
||
| 723 | 673 | * @return bool |
| 724 | 674 | * @author Mathew |
| 725 | 675 | **/ |
| 726 | - public function email_check($email = '') |
|
| 727 | - { |
|
| 676 | + public function email_check($email = '') { |
|
| 728 | 677 | $this->trigger_events('email_check'); |
| 729 | 678 | |
| 730 | - if (empty($email)) |
|
| 731 | - { |
|
| 679 | + if (empty($email)) { |
|
| 732 | 680 | return FALSE; |
| 733 | 681 | } |
| 734 | 682 | |
@@ -747,12 +695,10 @@ discard block |
||
| 747 | 695 | * @return bool |
| 748 | 696 | * @author Mathew |
| 749 | 697 | **/ |
| 750 | - public function identity_check($identity = '') |
|
| 751 | - { |
|
| 698 | + public function identity_check($identity = '') { |
|
| 752 | 699 | $this->trigger_events('identity_check'); |
| 753 | 700 | |
| 754 | - if (empty($identity)) |
|
| 755 | - { |
|
| 701 | + if (empty($identity)) { |
|
| 756 | 702 | return FALSE; |
| 757 | 703 | } |
| 758 | 704 | |
@@ -768,10 +714,8 @@ discard block |
||
| 768 | 714 | * @updated Ryan |
| 769 | 715 | * @updated 52aa456eef8b60ad6754b31fbdcc77bb |
| 770 | 716 | **/ |
| 771 | - public function forgotten_password($identity) |
|
| 772 | - { |
|
| 773 | - if (empty($identity)) |
|
| 774 | - { |
|
| 717 | + public function forgotten_password($identity) { |
|
| 718 | + if (empty($identity)) { |
|
| 775 | 719 | $this->trigger_events(array('post_forgotten_password', 'post_forgotten_password_unsuccessful')); |
| 776 | 720 | return FALSE; |
| 777 | 721 | } |
@@ -789,12 +733,10 @@ discard block |
||
| 789 | 733 | $key = $this->hash_code($activation_code_part.$identity); |
| 790 | 734 | |
| 791 | 735 | // If enable query strings is set, then we need to replace any unsafe characters so that the code can still work |
| 792 | - if ($key != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) |
|
| 793 | - { |
|
| 736 | + if ($key != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) { |
|
| 794 | 737 | // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards |
| 795 | 738 | // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern |
| 796 | - if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $key)) |
|
| 797 | - { |
|
| 739 | + if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $key)) { |
|
| 798 | 740 | $key = preg_replace("/[^".$this->config->item('permitted_uri_chars')."]+/i", "-", $key); |
| 799 | 741 | } |
| 800 | 742 | } |
@@ -813,10 +755,11 @@ discard block |
||
| 813 | 755 | |
| 814 | 756 | $return = $this->db->affected_rows() == 1; |
| 815 | 757 | |
| 816 | - if ($return) |
|
| 817 | - $this->trigger_events(array('post_forgotten_password', 'post_forgotten_password_successful')); |
|
| 818 | - else |
|
| 819 | - $this->trigger_events(array('post_forgotten_password', 'post_forgotten_password_unsuccessful')); |
|
| 758 | + if ($return) { |
|
| 759 | + $this->trigger_events(array('post_forgotten_password', 'post_forgotten_password_successful')); |
|
| 760 | + } else { |
|
| 761 | + $this->trigger_events(array('post_forgotten_password', 'post_forgotten_password_unsuccessful')); |
|
| 762 | + } |
|
| 820 | 763 | |
| 821 | 764 | return $return; |
| 822 | 765 | } |
@@ -827,12 +770,10 @@ discard block |
||
| 827 | 770 | * @return string |
| 828 | 771 | * @author Mathew |
| 829 | 772 | **/ |
| 830 | - public function forgotten_password_complete($code, $salt=FALSE) |
|
| 831 | - { |
|
| 773 | + public function forgotten_password_complete($code, $salt=FALSE) { |
|
| 832 | 774 | $this->trigger_events('pre_forgotten_password_complete'); |
| 833 | 775 | |
| 834 | - if (empty($code)) |
|
| 835 | - { |
|
| 776 | + if (empty($code)) { |
|
| 836 | 777 | $this->trigger_events(array('post_forgotten_password_complete', 'post_forgotten_password_complete_unsuccessful')); |
| 837 | 778 | return FALSE; |
| 838 | 779 | } |
@@ -876,27 +817,22 @@ discard block |
||
| 876 | 817 | * @return bool |
| 877 | 818 | * @author Mathew |
| 878 | 819 | **/ |
| 879 | - public function register($identity, $password, $email, $additional_data = array(), $groups = array()) |
|
| 880 | - { |
|
| 820 | + public function register($identity, $password, $email, $additional_data = array(), $groups = array()) { |
|
| 881 | 821 | $this->trigger_events('pre_register'); |
| 882 | 822 | |
| 883 | 823 | $manual_activation = $this->config->item('manual_activation', 'ion_auth'); |
| 884 | 824 | |
| 885 | - if ($this->identity_check($identity)) |
|
| 886 | - { |
|
| 825 | + if ($this->identity_check($identity)) { |
|
| 887 | 826 | $this->set_error('account_creation_duplicate_identity'); |
| 888 | 827 | return FALSE; |
| 889 | - } |
|
| 890 | - elseif ( !$this->config->item('default_group', 'ion_auth') && empty($groups) ) |
|
| 891 | - { |
|
| 828 | + } elseif ( !$this->config->item('default_group', 'ion_auth') && empty($groups) ) { |
|
| 892 | 829 | $this->set_error('account_creation_missing_default_group'); |
| 893 | 830 | return FALSE; |
| 894 | 831 | } |
| 895 | 832 | |
| 896 | 833 | // check if the default set in config exists in database |
| 897 | 834 | $query = $this->db->get_where($this->tables['groups'],array('name' => $this->config->item('default_group', 'ion_auth')),1)->row(); |
| 898 | - if( !isset($query->id) && empty($groups) ) |
|
| 899 | - { |
|
| 835 | + if( !isset($query->id) && empty($groups) ) { |
|
| 900 | 836 | $this->set_error('account_creation_invalid_default_group'); |
| 901 | 837 | return FALSE; |
| 902 | 838 | } |
@@ -920,8 +856,7 @@ discard block |
||
| 920 | 856 | 'active' => ($manual_activation === false ? 1 : 0) |
| 921 | 857 | ); |
| 922 | 858 | |
| 923 | - if ($this->store_salt) |
|
| 924 | - { |
|
| 859 | + if ($this->store_salt) { |
|
| 925 | 860 | $data['salt'] = $salt; |
| 926 | 861 | } |
| 927 | 862 | |
@@ -936,16 +871,13 @@ discard block |
||
| 936 | 871 | $id = $this->db->insert_id($this->tables['users'] . '_id_seq'); |
| 937 | 872 | |
| 938 | 873 | // add in groups array if it doesn't exists and stop adding into default group if default group ids are set |
| 939 | - if( isset($default_group->id) && empty($groups) ) |
|
| 940 | - { |
|
| 874 | + if( isset($default_group->id) && empty($groups) ) { |
|
| 941 | 875 | $groups[] = $default_group->id; |
| 942 | 876 | } |
| 943 | 877 | |
| 944 | - if (!empty($groups)) |
|
| 945 | - { |
|
| 878 | + if (!empty($groups)) { |
|
| 946 | 879 | // add to groups |
| 947 | - foreach ($groups as $group) |
|
| 948 | - { |
|
| 880 | + foreach ($groups as $group) { |
|
| 949 | 881 | $this->add_to_group($group, $id); |
| 950 | 882 | } |
| 951 | 883 | } |
@@ -961,12 +893,10 @@ discard block |
||
| 961 | 893 | * @return bool |
| 962 | 894 | * @author Mathew |
| 963 | 895 | **/ |
| 964 | - public function login($identity, $password, $remember=FALSE) |
|
| 965 | - { |
|
| 896 | + public function login($identity, $password, $remember=FALSE) { |
|
| 966 | 897 | $this->trigger_events('pre_login'); |
| 967 | 898 | |
| 968 | - if (empty($identity) || empty($password)) |
|
| 969 | - { |
|
| 899 | + if (empty($identity) || empty($password)) { |
|
| 970 | 900 | $this->set_error('login_unsuccessful'); |
| 971 | 901 | return FALSE; |
| 972 | 902 | } |
@@ -979,8 +909,7 @@ discard block |
||
| 979 | 909 | ->order_by('id', 'desc') |
| 980 | 910 | ->get($this->tables['users']); |
| 981 | 911 | |
| 982 | - if($this->is_max_login_attempts_exceeded($identity)) |
|
| 983 | - { |
|
| 912 | + if($this->is_max_login_attempts_exceeded($identity)) { |
|
| 984 | 913 | // Hash something anyway, just to take up time |
| 985 | 914 | $this->hash_password($password); |
| 986 | 915 | |
@@ -990,16 +919,13 @@ discard block |
||
| 990 | 919 | return FALSE; |
| 991 | 920 | } |
| 992 | 921 | |
| 993 | - if ($query->num_rows() === 1) |
|
| 994 | - { |
|
| 922 | + if ($query->num_rows() === 1) { |
|
| 995 | 923 | $user = $query->row(); |
| 996 | 924 | |
| 997 | 925 | $password = $this->hash_password_db($user->id, $password); |
| 998 | 926 | |
| 999 | - if ($password === TRUE) |
|
| 1000 | - { |
|
| 1001 | - if ($user->active == 0) |
|
| 1002 | - { |
|
| 927 | + if ($password === TRUE) { |
|
| 928 | + if ($user->active == 0) { |
|
| 1003 | 929 | $this->trigger_events('post_login_unsuccessful'); |
| 1004 | 930 | $this->set_error('login_unsuccessful_not_active'); |
| 1005 | 931 | |
@@ -1012,8 +938,7 @@ discard block |
||
| 1012 | 938 | |
| 1013 | 939 | $this->clear_login_attempts($identity); |
| 1014 | 940 | |
| 1015 | - if ($remember && $this->config->item('remember_users', 'ion_auth')) |
|
| 1016 | - { |
|
| 941 | + if ($remember && $this->config->item('remember_users', 'ion_auth')) { |
|
| 1017 | 942 | $this->remember_user($user->id); |
| 1018 | 943 | } |
| 1019 | 944 | |
@@ -1040,36 +965,27 @@ discard block |
||
| 1040 | 965 | * the configuration item recheck_timer. If it does, then it will check if the user is still active |
| 1041 | 966 | * @return bool |
| 1042 | 967 | */ |
| 1043 | - public function recheck_session() |
|
| 1044 | - { |
|
| 968 | + public function recheck_session() { |
|
| 1045 | 969 | $recheck = (null !== $this->config->item('recheck_timer', 'ion_auth')) ? $this->config->item('recheck_timer', 'ion_auth') : 0; |
| 1046 | 970 | |
| 1047 | - if($recheck!==0) |
|
| 1048 | - { |
|
| 971 | + if($recheck!==0) { |
|
| 1049 | 972 | $last_login = $this->session->userdata('last_check'); |
| 1050 | - if($last_login+$recheck < time()) |
|
| 1051 | - { |
|
| 973 | + if($last_login+$recheck < time()) { |
|
| 1052 | 974 | $query = $this->db->select('id') |
| 1053 | 975 | ->where(array($this->identity_column=>$this->session->userdata('identity'),'active'=>'1')) |
| 1054 | 976 | ->limit(1) |
| 1055 | 977 | ->order_by('id', 'desc') |
| 1056 | 978 | ->get($this->tables['users']); |
| 1057 | - if ($query->num_rows() === 1) |
|
| 1058 | - { |
|
| 979 | + if ($query->num_rows() === 1) { |
|
| 1059 | 980 | $this->session->set_userdata('last_check',time()); |
| 1060 | - } |
|
| 1061 | - else |
|
| 1062 | - { |
|
| 981 | + } else { |
|
| 1063 | 982 | $this->trigger_events('logout'); |
| 1064 | 983 | |
| 1065 | 984 | $identity = $this->config->item('identity', 'ion_auth'); |
| 1066 | 985 | |
| 1067 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 1068 | - { |
|
| 986 | + if (substr(CI_VERSION, 0, 1) == '2') { |
|
| 1069 | 987 | $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
| 1070 | - } |
|
| 1071 | - else |
|
| 1072 | - { |
|
| 988 | + } else { |
|
| 1073 | 989 | $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
| 1074 | 990 | } |
| 1075 | 991 | return false; |
@@ -1113,8 +1029,7 @@ discard block |
||
| 1113 | 1029 | * Use get_last_attempt_ip($identity) to retrieve user's last IP |
| 1114 | 1030 | * @return int |
| 1115 | 1031 | */ |
| 1116 | - public function get_attempts_num($identity, $ip_address = NULL) |
|
| 1117 | - { |
|
| 1032 | + public function get_attempts_num($identity, $ip_address = NULL) { |
|
| 1118 | 1033 | if ($this->config->item('track_login_attempts', 'ion_auth')) { |
| 1119 | 1034 | $this->db->select('1', FALSE); |
| 1120 | 1035 | $this->db->where('login', $identity); |
@@ -1257,28 +1172,24 @@ discard block |
||
| 1257 | 1172 | return FALSE; |
| 1258 | 1173 | } |
| 1259 | 1174 | |
| 1260 | - public function limit($limit) |
|
| 1261 | - { |
|
| 1175 | + public function limit($limit) { |
|
| 1262 | 1176 | $this->trigger_events('limit'); |
| 1263 | 1177 | $this->_ion_limit = $limit; |
| 1264 | 1178 | |
| 1265 | 1179 | return $this; |
| 1266 | 1180 | } |
| 1267 | 1181 | |
| 1268 | - public function offset($offset) |
|
| 1269 | - { |
|
| 1182 | + public function offset($offset) { |
|
| 1270 | 1183 | $this->trigger_events('offset'); |
| 1271 | 1184 | $this->_ion_offset = $offset; |
| 1272 | 1185 | |
| 1273 | 1186 | return $this; |
| 1274 | 1187 | } |
| 1275 | 1188 | |
| 1276 | - public function where($where, $value = NULL) |
|
| 1277 | - { |
|
| 1189 | + public function where($where, $value = NULL) { |
|
| 1278 | 1190 | $this->trigger_events('where'); |
| 1279 | 1191 | |
| 1280 | - if (!is_array($where)) |
|
| 1281 | - { |
|
| 1192 | + if (!is_array($where)) { |
|
| 1282 | 1193 | $where = array($where => $value); |
| 1283 | 1194 | } |
| 1284 | 1195 | |
@@ -1287,8 +1198,7 @@ discard block |
||
| 1287 | 1198 | return $this; |
| 1288 | 1199 | } |
| 1289 | 1200 | |
| 1290 | - public function like($like, $value = NULL, $position = 'both') |
|
| 1291 | - { |
|
| 1201 | + public function like($like, $value = NULL, $position = 'both') { |
|
| 1292 | 1202 | $this->trigger_events('like'); |
| 1293 | 1203 | |
| 1294 | 1204 | array_push($this->_ion_like, array( |
@@ -1300,8 +1210,7 @@ discard block |
||
| 1300 | 1210 | return $this; |
| 1301 | 1211 | } |
| 1302 | 1212 | |
| 1303 | - public function select($select) |
|
| 1304 | - { |
|
| 1213 | + public function select($select) { |
|
| 1305 | 1214 | $this->trigger_events('select'); |
| 1306 | 1215 | |
| 1307 | 1216 | $this->_ion_select[] = $select; |
@@ -1309,8 +1218,7 @@ discard block |
||
| 1309 | 1218 | return $this; |
| 1310 | 1219 | } |
| 1311 | 1220 | |
| 1312 | - public function order_by($by, $order='desc') |
|
| 1313 | - { |
|
| 1221 | + public function order_by($by, $order='desc') { |
|
| 1314 | 1222 | $this->trigger_events('order_by'); |
| 1315 | 1223 | |
| 1316 | 1224 | $this->_ion_order_by = $by; |
@@ -1319,8 +1227,7 @@ discard block |
||
| 1319 | 1227 | return $this; |
| 1320 | 1228 | } |
| 1321 | 1229 | |
| 1322 | - public function row() |
|
| 1323 | - { |
|
| 1230 | + public function row() { |
|
| 1324 | 1231 | $this->trigger_events('row'); |
| 1325 | 1232 | |
| 1326 | 1233 | $row = $this->response->row(); |
@@ -1328,8 +1235,7 @@ discard block |
||
| 1328 | 1235 | return $row; |
| 1329 | 1236 | } |
| 1330 | 1237 | |
| 1331 | - public function row_array() |
|
| 1332 | - { |
|
| 1238 | + public function row_array() { |
|
| 1333 | 1239 | $this->trigger_events(array('row', 'row_array')); |
| 1334 | 1240 | |
| 1335 | 1241 | $row = $this->response->row_array(); |
@@ -1337,8 +1243,7 @@ discard block |
||
| 1337 | 1243 | return $row; |
| 1338 | 1244 | } |
| 1339 | 1245 | |
| 1340 | - public function result() |
|
| 1341 | - { |
|
| 1246 | + public function result() { |
|
| 1342 | 1247 | $this->trigger_events('result'); |
| 1343 | 1248 | |
| 1344 | 1249 | $result = $this->response->result(); |
@@ -1346,8 +1251,7 @@ discard block |
||
| 1346 | 1251 | return $result; |
| 1347 | 1252 | } |
| 1348 | 1253 | |
| 1349 | - public function result_array() |
|
| 1350 | - { |
|
| 1254 | + public function result_array() { |
|
| 1351 | 1255 | $this->trigger_events(array('result', 'result_array')); |
| 1352 | 1256 | |
| 1353 | 1257 | $result = $this->response->result_array(); |
@@ -1355,8 +1259,7 @@ discard block |
||
| 1355 | 1259 | return $result; |
| 1356 | 1260 | } |
| 1357 | 1261 | |
| 1358 | - public function num_rows() |
|
| 1359 | - { |
|
| 1262 | + public function num_rows() { |
|
| 1360 | 1263 | $this->trigger_events(array('num_rows')); |
| 1361 | 1264 | |
| 1362 | 1265 | $result = $this->response->num_rows(); |
@@ -1370,21 +1273,16 @@ discard block |
||
| 1370 | 1273 | * @return object Users |
| 1371 | 1274 | * @author Ben Edmunds |
| 1372 | 1275 | **/ |
| 1373 | - public function users($groups = NULL) |
|
| 1374 | - { |
|
| 1276 | + public function users($groups = NULL) { |
|
| 1375 | 1277 | $this->trigger_events('users'); |
| 1376 | 1278 | |
| 1377 | - if (isset($this->_ion_select) && !empty($this->_ion_select)) |
|
| 1378 | - { |
|
| 1379 | - foreach ($this->_ion_select as $select) |
|
| 1380 | - { |
|
| 1279 | + if (isset($this->_ion_select) && !empty($this->_ion_select)) { |
|
| 1280 | + foreach ($this->_ion_select as $select) { |
|
| 1381 | 1281 | $this->db->select($select); |
| 1382 | 1282 | } |
| 1383 | 1283 | |
| 1384 | 1284 | $this->_ion_select = array(); |
| 1385 | - } |
|
| 1386 | - else |
|
| 1387 | - { |
|
| 1285 | + } else { |
|
| 1388 | 1286 | //default selects |
| 1389 | 1287 | $this->db->select(array( |
| 1390 | 1288 | $this->tables['users'].'.*', |
@@ -1394,17 +1292,14 @@ discard block |
||
| 1394 | 1292 | } |
| 1395 | 1293 | |
| 1396 | 1294 | // filter by group id(s) if passed |
| 1397 | - if (isset($groups)) |
|
| 1398 | - { |
|
| 1295 | + if (isset($groups)) { |
|
| 1399 | 1296 | // build an array if only one group was passed |
| 1400 | - if (!is_array($groups)) |
|
| 1401 | - { |
|
| 1297 | + if (!is_array($groups)) { |
|
| 1402 | 1298 | $groups = Array($groups); |
| 1403 | 1299 | } |
| 1404 | 1300 | |
| 1405 | 1301 | // join and then run a where_in against the group ids |
| 1406 | - if (isset($groups) && !empty($groups)) |
|
| 1407 | - { |
|
| 1302 | + if (isset($groups) && !empty($groups)) { |
|
| 1408 | 1303 | $this->db->distinct(); |
| 1409 | 1304 | $this->db->join( |
| 1410 | 1305 | $this->tables['users_groups'], |
@@ -1416,20 +1311,20 @@ discard block |
||
| 1416 | 1311 | // verify if group name or group id was used and create and put elements in different arrays |
| 1417 | 1312 | $group_ids = array(); |
| 1418 | 1313 | $group_names = array(); |
| 1419 | - foreach($groups as $group) |
|
| 1420 | - { |
|
| 1421 | - if(is_numeric($group)) $group_ids[] = $group; |
|
| 1422 | - else $group_names[] = $group; |
|
| 1314 | + foreach($groups as $group) { |
|
| 1315 | + if(is_numeric($group)) { |
|
| 1316 | + $group_ids[] = $group; |
|
| 1317 | + } else { |
|
| 1318 | + $group_names[] = $group; |
|
| 1319 | + } |
|
| 1423 | 1320 | } |
| 1424 | 1321 | $or_where_in = (!empty($group_ids) && !empty($group_names)) ? 'or_where_in' : 'where_in'; |
| 1425 | 1322 | // if group name was used we do one more join with groups |
| 1426 | - if(!empty($group_names)) |
|
| 1427 | - { |
|
| 1323 | + if(!empty($group_names)) { |
|
| 1428 | 1324 | $this->db->join($this->tables['groups'], $this->tables['users_groups'] . '.' . $this->join['groups'] . ' = ' . $this->tables['groups'] . '.id', 'inner'); |
| 1429 | 1325 | $this->db->where_in($this->tables['groups'] . '.name', $group_names); |
| 1430 | 1326 | } |
| 1431 | - if(!empty($group_ids)) |
|
| 1432 | - { |
|
| 1327 | + if(!empty($group_ids)) { |
|
| 1433 | 1328 | $this->db->{$or_where_in}($this->tables['users_groups'].'.'.$this->join['groups'], $group_ids); |
| 1434 | 1329 | } |
| 1435 | 1330 | } |
@@ -1437,43 +1332,35 @@ discard block |
||
| 1437 | 1332 | $this->trigger_events('extra_where'); |
| 1438 | 1333 | |
| 1439 | 1334 | // run each where that was passed |
| 1440 | - if (isset($this->_ion_where) && !empty($this->_ion_where)) |
|
| 1441 | - { |
|
| 1442 | - foreach ($this->_ion_where as $where) |
|
| 1443 | - { |
|
| 1335 | + if (isset($this->_ion_where) && !empty($this->_ion_where)) { |
|
| 1336 | + foreach ($this->_ion_where as $where) { |
|
| 1444 | 1337 | $this->db->where($where); |
| 1445 | 1338 | } |
| 1446 | 1339 | |
| 1447 | 1340 | $this->_ion_where = array(); |
| 1448 | 1341 | } |
| 1449 | 1342 | |
| 1450 | - if (isset($this->_ion_like) && !empty($this->_ion_like)) |
|
| 1451 | - { |
|
| 1452 | - foreach ($this->_ion_like as $like) |
|
| 1453 | - { |
|
| 1343 | + if (isset($this->_ion_like) && !empty($this->_ion_like)) { |
|
| 1344 | + foreach ($this->_ion_like as $like) { |
|
| 1454 | 1345 | $this->db->or_like($like['like'], $like['value'], $like['position']); |
| 1455 | 1346 | } |
| 1456 | 1347 | |
| 1457 | 1348 | $this->_ion_like = array(); |
| 1458 | 1349 | } |
| 1459 | 1350 | |
| 1460 | - if (isset($this->_ion_limit) && isset($this->_ion_offset)) |
|
| 1461 | - { |
|
| 1351 | + if (isset($this->_ion_limit) && isset($this->_ion_offset)) { |
|
| 1462 | 1352 | $this->db->limit($this->_ion_limit, $this->_ion_offset); |
| 1463 | 1353 | |
| 1464 | 1354 | $this->_ion_limit = NULL; |
| 1465 | 1355 | $this->_ion_offset = NULL; |
| 1466 | - } |
|
| 1467 | - else if (isset($this->_ion_limit)) |
|
| 1468 | - { |
|
| 1356 | + } else if (isset($this->_ion_limit)) { |
|
| 1469 | 1357 | $this->db->limit($this->_ion_limit); |
| 1470 | 1358 | |
| 1471 | 1359 | $this->_ion_limit = NULL; |
| 1472 | 1360 | } |
| 1473 | 1361 | |
| 1474 | 1362 | // set the order |
| 1475 | - if (isset($this->_ion_order_by) && isset($this->_ion_order)) |
|
| 1476 | - { |
|
| 1363 | + if (isset($this->_ion_order_by) && isset($this->_ion_order)) { |
|
| 1477 | 1364 | $this->db->order_by($this->_ion_order_by, $this->_ion_order); |
| 1478 | 1365 | |
| 1479 | 1366 | $this->_ion_order = NULL; |
@@ -1491,8 +1378,7 @@ discard block |
||
| 1491 | 1378 | * @return object |
| 1492 | 1379 | * @author Ben Edmunds |
| 1493 | 1380 | **/ |
| 1494 | - public function user($id = NULL) |
|
| 1495 | - { |
|
| 1381 | + public function user($id = NULL) { |
|
| 1496 | 1382 | $this->trigger_events('user'); |
| 1497 | 1383 | |
| 1498 | 1384 | // if no id was passed use the current users id |
@@ -1513,8 +1399,7 @@ discard block |
||
| 1513 | 1399 | * @return array |
| 1514 | 1400 | * @author Ben Edmunds |
| 1515 | 1401 | **/ |
| 1516 | - public function get_users_groups($id=FALSE) |
|
| 1517 | - { |
|
| 1402 | + public function get_users_groups($id=FALSE) { |
|
| 1518 | 1403 | $this->trigger_events('get_users_group'); |
| 1519 | 1404 | |
| 1520 | 1405 | // if no id was passed use the current users id |
@@ -1532,29 +1417,24 @@ discard block |
||
| 1532 | 1417 | * @return bool |
| 1533 | 1418 | * @author Ben Edmunds |
| 1534 | 1419 | **/ |
| 1535 | - public function add_to_group($group_ids, $user_id=false) |
|
| 1536 | - { |
|
| 1420 | + public function add_to_group($group_ids, $user_id=false) { |
|
| 1537 | 1421 | $this->trigger_events('add_to_group'); |
| 1538 | 1422 | |
| 1539 | 1423 | // if no id was passed use the current users id |
| 1540 | 1424 | $user_id || $user_id = $this->session->userdata('user_id'); |
| 1541 | 1425 | |
| 1542 | - if(!is_array($group_ids)) |
|
| 1543 | - { |
|
| 1426 | + if(!is_array($group_ids)) { |
|
| 1544 | 1427 | $group_ids = array($group_ids); |
| 1545 | 1428 | } |
| 1546 | 1429 | |
| 1547 | 1430 | $return = 0; |
| 1548 | 1431 | |
| 1549 | 1432 | // Then insert each into the database |
| 1550 | - foreach ($group_ids as $group_id) |
|
| 1551 | - { |
|
| 1552 | - if ($this->db->insert($this->tables['users_groups'], array( $this->join['groups'] => (float)$group_id, $this->join['users'] => (float)$user_id))) |
|
| 1553 | - { |
|
| 1433 | + foreach ($group_ids as $group_id) { |
|
| 1434 | + if ($this->db->insert($this->tables['users_groups'], array( $this->join['groups'] => (float)$group_id, $this->join['users'] => (float)$user_id))) { |
|
| 1554 | 1435 | if (isset($this->_cache_groups[$group_id])) { |
| 1555 | 1436 | $group_name = $this->_cache_groups[$group_id]; |
| 1556 | - } |
|
| 1557 | - else { |
|
| 1437 | + } else { |
|
| 1558 | 1438 | $group = $this->group($group_id)->result(); |
| 1559 | 1439 | $group_name = $group[0]->name; |
| 1560 | 1440 | $this->_cache_groups[$group_id] = $group_name; |
@@ -1575,29 +1455,23 @@ discard block |
||
| 1575 | 1455 | * @return bool |
| 1576 | 1456 | * @author Ben Edmunds |
| 1577 | 1457 | **/ |
| 1578 | - public function remove_from_group($group_ids=false, $user_id=false) |
|
| 1579 | - { |
|
| 1458 | + public function remove_from_group($group_ids=false, $user_id=false) { |
|
| 1580 | 1459 | $this->trigger_events('remove_from_group'); |
| 1581 | 1460 | |
| 1582 | 1461 | // user id is required |
| 1583 | - if(empty($user_id)) |
|
| 1584 | - { |
|
| 1462 | + if(empty($user_id)) { |
|
| 1585 | 1463 | return FALSE; |
| 1586 | 1464 | } |
| 1587 | 1465 | |
| 1588 | 1466 | // if group id(s) are passed remove user from the group(s) |
| 1589 | - if( ! empty($group_ids)) |
|
| 1590 | - { |
|
| 1591 | - if(!is_array($group_ids)) |
|
| 1592 | - { |
|
| 1467 | + if( ! empty($group_ids)) { |
|
| 1468 | + if(!is_array($group_ids)) { |
|
| 1593 | 1469 | $group_ids = array($group_ids); |
| 1594 | 1470 | } |
| 1595 | 1471 | |
| 1596 | - foreach($group_ids as $group_id) |
|
| 1597 | - { |
|
| 1472 | + foreach($group_ids as $group_id) { |
|
| 1598 | 1473 | $this->db->delete($this->tables['users_groups'], array($this->join['groups'] => (float)$group_id, $this->join['users'] => (float)$user_id)); |
| 1599 | - if (isset($this->_cache_user_in_group[$user_id]) && isset($this->_cache_user_in_group[$user_id][$group_id])) |
|
| 1600 | - { |
|
| 1474 | + if (isset($this->_cache_user_in_group[$user_id]) && isset($this->_cache_user_in_group[$user_id][$group_id])) { |
|
| 1601 | 1475 | unset($this->_cache_user_in_group[$user_id][$group_id]); |
| 1602 | 1476 | } |
| 1603 | 1477 | } |
@@ -1605,8 +1479,7 @@ discard block |
||
| 1605 | 1479 | $return = TRUE; |
| 1606 | 1480 | } |
| 1607 | 1481 | // otherwise remove user from all groups |
| 1608 | - else |
|
| 1609 | - { |
|
| 1482 | + else { |
|
| 1610 | 1483 | if ($return = $this->db->delete($this->tables['users_groups'], array($this->join['users'] => (float)$user_id))) { |
| 1611 | 1484 | $this->_cache_user_in_group[$user_id] = array(); |
| 1612 | 1485 | } |
@@ -1620,37 +1493,30 @@ discard block |
||
| 1620 | 1493 | * @return object |
| 1621 | 1494 | * @author Ben Edmunds |
| 1622 | 1495 | **/ |
| 1623 | - public function groups() |
|
| 1624 | - { |
|
| 1496 | + public function groups() { |
|
| 1625 | 1497 | $this->trigger_events('groups'); |
| 1626 | 1498 | |
| 1627 | 1499 | // run each where that was passed |
| 1628 | - if (isset($this->_ion_where) && !empty($this->_ion_where)) |
|
| 1629 | - { |
|
| 1630 | - foreach ($this->_ion_where as $where) |
|
| 1631 | - { |
|
| 1500 | + if (isset($this->_ion_where) && !empty($this->_ion_where)) { |
|
| 1501 | + foreach ($this->_ion_where as $where) { |
|
| 1632 | 1502 | $this->db->where($where); |
| 1633 | 1503 | } |
| 1634 | 1504 | $this->_ion_where = array(); |
| 1635 | 1505 | } |
| 1636 | 1506 | |
| 1637 | - if (isset($this->_ion_limit) && isset($this->_ion_offset)) |
|
| 1638 | - { |
|
| 1507 | + if (isset($this->_ion_limit) && isset($this->_ion_offset)) { |
|
| 1639 | 1508 | $this->db->limit($this->_ion_limit, $this->_ion_offset); |
| 1640 | 1509 | |
| 1641 | 1510 | $this->_ion_limit = NULL; |
| 1642 | 1511 | $this->_ion_offset = NULL; |
| 1643 | - } |
|
| 1644 | - else if (isset($this->_ion_limit)) |
|
| 1645 | - { |
|
| 1512 | + } else if (isset($this->_ion_limit)) { |
|
| 1646 | 1513 | $this->db->limit($this->_ion_limit); |
| 1647 | 1514 | |
| 1648 | 1515 | $this->_ion_limit = NULL; |
| 1649 | 1516 | } |
| 1650 | 1517 | |
| 1651 | 1518 | // set the order |
| 1652 | - if (isset($this->_ion_order_by) && isset($this->_ion_order)) |
|
| 1653 | - { |
|
| 1519 | + if (isset($this->_ion_order_by) && isset($this->_ion_order)) { |
|
| 1654 | 1520 | $this->db->order_by($this->_ion_order_by, $this->_ion_order); |
| 1655 | 1521 | } |
| 1656 | 1522 | |
@@ -1665,12 +1531,10 @@ discard block |
||
| 1665 | 1531 | * @return object |
| 1666 | 1532 | * @author Ben Edmunds |
| 1667 | 1533 | **/ |
| 1668 | - public function group($id = NULL) |
|
| 1669 | - { |
|
| 1534 | + public function group($id = NULL) { |
|
| 1670 | 1535 | $this->trigger_events('group'); |
| 1671 | 1536 | |
| 1672 | - if (isset($id)) |
|
| 1673 | - { |
|
| 1537 | + if (isset($id)) { |
|
| 1674 | 1538 | $this->where($this->tables['groups'].'.id', $id); |
| 1675 | 1539 | } |
| 1676 | 1540 | |
@@ -1686,16 +1550,14 @@ discard block |
||
| 1686 | 1550 | * @return bool |
| 1687 | 1551 | * @author Phil Sturgeon |
| 1688 | 1552 | **/ |
| 1689 | - public function update($id, array $data) |
|
| 1690 | - { |
|
| 1553 | + public function update($id, array $data) { |
|
| 1691 | 1554 | $this->trigger_events('pre_update_user'); |
| 1692 | 1555 | |
| 1693 | 1556 | $user = $this->user($id)->row(); |
| 1694 | 1557 | |
| 1695 | 1558 | $this->db->trans_begin(); |
| 1696 | 1559 | |
| 1697 | - if (array_key_exists($this->identity_column, $data) && $this->identity_check($data[$this->identity_column]) && $user->{$this->identity_column} !== $data[$this->identity_column]) |
|
| 1698 | - { |
|
| 1560 | + if (array_key_exists($this->identity_column, $data) && $this->identity_check($data[$this->identity_column]) && $user->{$this->identity_column} !== $data[$this->identity_column]) { |
|
| 1699 | 1561 | $this->db->trans_rollback(); |
| 1700 | 1562 | $this->set_error('account_creation_duplicate_identity'); |
| 1701 | 1563 | |
@@ -1708,16 +1570,11 @@ discard block |
||
| 1708 | 1570 | // Filter the data passed |
| 1709 | 1571 | $data = $this->_filter_data($this->tables['users'], $data); |
| 1710 | 1572 | |
| 1711 | - if (array_key_exists($this->identity_column, $data) || array_key_exists('password', $data) || array_key_exists('email', $data)) |
|
| 1712 | - { |
|
| 1713 | - if (array_key_exists('password', $data)) |
|
| 1714 | - { |
|
| 1715 | - if( ! empty($data['password'])) |
|
| 1716 | - { |
|
| 1573 | + if (array_key_exists($this->identity_column, $data) || array_key_exists('password', $data) || array_key_exists('email', $data)) { |
|
| 1574 | + if (array_key_exists('password', $data)) { |
|
| 1575 | + if( ! empty($data['password'])) { |
|
| 1717 | 1576 | $data['password'] = $this->hash_password($data['password'], $user->salt); |
| 1718 | - } |
|
| 1719 | - else |
|
| 1720 | - { |
|
| 1577 | + } else { |
|
| 1721 | 1578 | // unset password so it doesn't effect database entry if no password passed |
| 1722 | 1579 | unset($data['password']); |
| 1723 | 1580 | } |
@@ -1727,8 +1584,7 @@ discard block |
||
| 1727 | 1584 | $this->trigger_events('extra_where'); |
| 1728 | 1585 | $this->db->update($this->tables['users'], $data, array('id' => $user->id)); |
| 1729 | 1586 | |
| 1730 | - if ($this->db->trans_status() === FALSE) |
|
| 1731 | - { |
|
| 1587 | + if ($this->db->trans_status() === FALSE) { |
|
| 1732 | 1588 | $this->db->trans_rollback(); |
| 1733 | 1589 | |
| 1734 | 1590 | $this->trigger_events(array('post_update_user', 'post_update_user_unsuccessful')); |
@@ -1749,8 +1605,7 @@ discard block |
||
| 1749 | 1605 | * @return bool |
| 1750 | 1606 | * @author Phil Sturgeon |
| 1751 | 1607 | **/ |
| 1752 | - public function delete_user($id) |
|
| 1753 | - { |
|
| 1608 | + public function delete_user($id) { |
|
| 1754 | 1609 | $this->trigger_events('pre_delete_user'); |
| 1755 | 1610 | |
| 1756 | 1611 | $this->db->trans_begin(); |
@@ -1762,8 +1617,7 @@ discard block |
||
| 1762 | 1617 | $this->db->delete($this->tables['users'], array('id' => $id)); |
| 1763 | 1618 | |
| 1764 | 1619 | |
| 1765 | - if ($this->db->trans_status() === FALSE) |
|
| 1766 | - { |
|
| 1620 | + if ($this->db->trans_status() === FALSE) { |
|
| 1767 | 1621 | $this->db->trans_rollback(); |
| 1768 | 1622 | $this->trigger_events(array('post_delete_user', 'post_delete_user_unsuccessful')); |
| 1769 | 1623 | $this->set_error('delete_unsuccessful'); |
@@ -1783,8 +1637,7 @@ discard block |
||
| 1783 | 1637 | * @return bool |
| 1784 | 1638 | * @author Ben Edmunds |
| 1785 | 1639 | **/ |
| 1786 | - public function update_last_login($id) |
|
| 1787 | - { |
|
| 1640 | + public function update_last_login($id) { |
|
| 1788 | 1641 | $this->trigger_events('update_last_login'); |
| 1789 | 1642 | |
| 1790 | 1643 | $this->load->helper('date'); |
@@ -1802,18 +1655,15 @@ discard block |
||
| 1802 | 1655 | * @return bool |
| 1803 | 1656 | * @author Ben Edmunds |
| 1804 | 1657 | **/ |
| 1805 | - public function set_lang($lang = 'en') |
|
| 1806 | - { |
|
| 1658 | + public function set_lang($lang = 'en') { |
|
| 1807 | 1659 | $this->trigger_events('set_lang'); |
| 1808 | 1660 | |
| 1809 | 1661 | // if the user_expire is set to zero we'll set the expiration two years from now. |
| 1810 | - if($this->config->item('user_expire', 'ion_auth') === 0) |
|
| 1811 | - { |
|
| 1662 | + if($this->config->item('user_expire', 'ion_auth') === 0) { |
|
| 1812 | 1663 | $expire = (60*60*24*365*2); |
| 1813 | 1664 | } |
| 1814 | 1665 | // otherwise use what is set |
| 1815 | - else |
|
| 1816 | - { |
|
| 1666 | + else { |
|
| 1817 | 1667 | $expire = $this->config->item('user_expire', 'ion_auth'); |
| 1818 | 1668 | } |
| 1819 | 1669 | |
@@ -1832,8 +1682,7 @@ discard block |
||
| 1832 | 1682 | * @return bool |
| 1833 | 1683 | * @author jrmadsen67 |
| 1834 | 1684 | **/ |
| 1835 | - public function set_session($user) |
|
| 1836 | - { |
|
| 1685 | + public function set_session($user) { |
|
| 1837 | 1686 | |
| 1838 | 1687 | $this->trigger_events('pre_set_session'); |
| 1839 | 1688 | |
@@ -1859,12 +1708,10 @@ discard block |
||
| 1859 | 1708 | * @return bool |
| 1860 | 1709 | * @author Ben Edmunds |
| 1861 | 1710 | **/ |
| 1862 | - public function remember_user($id) |
|
| 1863 | - { |
|
| 1711 | + public function remember_user($id) { |
|
| 1864 | 1712 | $this->trigger_events('pre_remember_user'); |
| 1865 | 1713 | |
| 1866 | - if (!$id) |
|
| 1867 | - { |
|
| 1714 | + if (!$id) { |
|
| 1868 | 1715 | return FALSE; |
| 1869 | 1716 | } |
| 1870 | 1717 | |
@@ -1874,16 +1721,13 @@ discard block |
||
| 1874 | 1721 | |
| 1875 | 1722 | $this->db->update($this->tables['users'], array('remember_code' => $salt), array('id' => $id)); |
| 1876 | 1723 | |
| 1877 | - if ($this->db->affected_rows() > -1) |
|
| 1878 | - { |
|
| 1724 | + if ($this->db->affected_rows() > -1) { |
|
| 1879 | 1725 | // if the user_expire is set to zero we'll set the expiration two years from now. |
| 1880 | - if($this->config->item('user_expire', 'ion_auth') === 0) |
|
| 1881 | - { |
|
| 1726 | + if($this->config->item('user_expire', 'ion_auth') === 0) { |
|
| 1882 | 1727 | $expire = (60*60*24*365*2); |
| 1883 | 1728 | } |
| 1884 | 1729 | // otherwise use what is set |
| 1885 | - else |
|
| 1886 | - { |
|
| 1730 | + else { |
|
| 1887 | 1731 | $expire = $this->config->item('user_expire', 'ion_auth'); |
| 1888 | 1732 | } |
| 1889 | 1733 | |
@@ -1913,15 +1757,13 @@ discard block |
||
| 1913 | 1757 | * @return bool |
| 1914 | 1758 | * @author Ben Edmunds |
| 1915 | 1759 | **/ |
| 1916 | - public function login_remembered_user() |
|
| 1917 | - { |
|
| 1760 | + public function login_remembered_user() { |
|
| 1918 | 1761 | $this->trigger_events('pre_login_remembered_user'); |
| 1919 | 1762 | |
| 1920 | 1763 | // check for valid data |
| 1921 | 1764 | if (!get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) |
| 1922 | 1765 | || !get_cookie($this->config->item('remember_cookie_name', 'ion_auth')) |
| 1923 | - || !$this->identity_check(get_cookie($this->config->item('identity_cookie_name', 'ion_auth')))) |
|
| 1924 | - { |
|
| 1766 | + || !$this->identity_check(get_cookie($this->config->item('identity_cookie_name', 'ion_auth')))) { |
|
| 1925 | 1767 | $this->trigger_events(array('post_login_remembered_user', 'post_login_remembered_user_unsuccessful')); |
| 1926 | 1768 | return FALSE; |
| 1927 | 1769 | } |
@@ -1937,8 +1779,7 @@ discard block |
||
| 1937 | 1779 | ->get($this->tables['users']); |
| 1938 | 1780 | |
| 1939 | 1781 | // if the user was found, sign them in |
| 1940 | - if ($query->num_rows() == 1) |
|
| 1941 | - { |
|
| 1782 | + if ($query->num_rows() == 1) { |
|
| 1942 | 1783 | $user = $query->row(); |
| 1943 | 1784 | |
| 1944 | 1785 | $this->update_last_login($user->id); |
@@ -1946,8 +1787,7 @@ discard block |
||
| 1946 | 1787 | $this->set_session($user); |
| 1947 | 1788 | |
| 1948 | 1789 | // extend the users cookies if the option is enabled |
| 1949 | - if ($this->config->item('user_extend_on_login', 'ion_auth')) |
|
| 1950 | - { |
|
| 1790 | + if ($this->config->item('user_extend_on_login', 'ion_auth')) { |
|
| 1951 | 1791 | $this->remember_user($user->id); |
| 1952 | 1792 | } |
| 1953 | 1793 | |
@@ -1965,19 +1805,16 @@ discard block |
||
| 1965 | 1805 | * |
| 1966 | 1806 | * @author aditya menon |
| 1967 | 1807 | */ |
| 1968 | - public function create_group($group_name = FALSE, $group_description = '', $additional_data = array()) |
|
| 1969 | - { |
|
| 1808 | + public function create_group($group_name = FALSE, $group_description = '', $additional_data = array()) { |
|
| 1970 | 1809 | // bail if the group name was not passed |
| 1971 | - if(!$group_name) |
|
| 1972 | - { |
|
| 1810 | + if(!$group_name) { |
|
| 1973 | 1811 | $this->set_error('group_name_required'); |
| 1974 | 1812 | return FALSE; |
| 1975 | 1813 | } |
| 1976 | 1814 | |
| 1977 | 1815 | // bail if the group name already exists |
| 1978 | 1816 | $existing_group = $this->db->get_where($this->tables['groups'], array('name' => $group_name))->num_rows(); |
| 1979 | - if($existing_group !== 0) |
|
| 1980 | - { |
|
| 1817 | + if($existing_group !== 0) { |
|
| 1981 | 1818 | $this->set_error('group_already_exists'); |
| 1982 | 1819 | return FALSE; |
| 1983 | 1820 | } |
@@ -1986,7 +1823,9 @@ discard block |
||
| 1986 | 1823 | |
| 1987 | 1824 | // filter out any data passed that doesnt have a matching column in the groups table |
| 1988 | 1825 | // and merge the set group data and the additional data |
| 1989 | - if (!empty($additional_data)) $data = array_merge($this->_filter_data($this->tables['groups'], $additional_data), $data); |
|
| 1826 | + if (!empty($additional_data)) { |
|
| 1827 | + $data = array_merge($this->_filter_data($this->tables['groups'], $additional_data), $data); |
|
| 1828 | + } |
|
| 1990 | 1829 | |
| 1991 | 1830 | $this->trigger_events('extra_group_set'); |
| 1992 | 1831 | |
@@ -2006,20 +1845,19 @@ discard block |
||
| 2006 | 1845 | * @return bool |
| 2007 | 1846 | * @author aditya menon |
| 2008 | 1847 | **/ |
| 2009 | - public function update_group($group_id = FALSE, $group_name = FALSE, $additional_data = array()) |
|
| 2010 | - { |
|
| 2011 | - if (empty($group_id)) return FALSE; |
|
| 1848 | + public function update_group($group_id = FALSE, $group_name = FALSE, $additional_data = array()) { |
|
| 1849 | + if (empty($group_id)) { |
|
| 1850 | + return FALSE; |
|
| 1851 | + } |
|
| 2012 | 1852 | |
| 2013 | 1853 | $data = array(); |
| 2014 | 1854 | |
| 2015 | - if (!empty($group_name)) |
|
| 2016 | - { |
|
| 1855 | + if (!empty($group_name)) { |
|
| 2017 | 1856 | // we are changing the name, so do some checks |
| 2018 | 1857 | |
| 2019 | 1858 | // bail if the group name already exists |
| 2020 | 1859 | $existing_group = $this->db->get_where($this->tables['groups'], array('name' => $group_name))->row(); |
| 2021 | - if(isset($existing_group->id) && $existing_group->id != $group_id) |
|
| 2022 | - { |
|
| 1860 | + if(isset($existing_group->id) && $existing_group->id != $group_id) { |
|
| 2023 | 1861 | $this->set_error('group_already_exists'); |
| 2024 | 1862 | return FALSE; |
| 2025 | 1863 | } |
@@ -2029,8 +1867,7 @@ discard block |
||
| 2029 | 1867 | |
| 2030 | 1868 | // restrict change of name of the admin group |
| 2031 | 1869 | $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 | - { |
|
| 1870 | + if($this->config->item('admin_group', 'ion_auth') === $group->name && $group_name !== $group->name) { |
|
| 2034 | 1871 | $this->set_error('group_name_admin_not_alter'); |
| 2035 | 1872 | return FALSE; |
| 2036 | 1873 | } |
@@ -2038,12 +1875,16 @@ discard block |
||
| 2038 | 1875 | |
| 2039 | 1876 | // IMPORTANT!! Third parameter was string type $description; this following code is to maintain backward compatibility |
| 2040 | 1877 | // New projects should work with 3rd param as array |
| 2041 | - if (is_string($additional_data)) $additional_data = array('description' => $additional_data); |
|
| 1878 | + if (is_string($additional_data)) { |
|
| 1879 | + $additional_data = array('description' => $additional_data); |
|
| 1880 | + } |
|
| 2042 | 1881 | |
| 2043 | 1882 | |
| 2044 | 1883 | // filter out any data passed that doesnt have a matching column in the groups table |
| 2045 | 1884 | // and merge the set group data and the additional data |
| 2046 | - if (!empty($additional_data)) $data = array_merge($this->_filter_data($this->tables['groups'], $additional_data), $data); |
|
| 1885 | + if (!empty($additional_data)) { |
|
| 1886 | + $data = array_merge($this->_filter_data($this->tables['groups'], $additional_data), $data); |
|
| 1887 | + } |
|
| 2047 | 1888 | |
| 2048 | 1889 | |
| 2049 | 1890 | $this->db->update($this->tables['groups'], $data, array('id' => $group_id)); |
@@ -2059,16 +1900,13 @@ discard block |
||
| 2059 | 1900 | * @return bool |
| 2060 | 1901 | * @author aditya menon |
| 2061 | 1902 | **/ |
| 2062 | - public function delete_group($group_id = FALSE) |
|
| 2063 | - { |
|
| 1903 | + public function delete_group($group_id = FALSE) { |
|
| 2064 | 1904 | // bail if mandatory param not set |
| 2065 | - if(!$group_id || empty($group_id)) |
|
| 2066 | - { |
|
| 1905 | + if(!$group_id || empty($group_id)) { |
|
| 2067 | 1906 | return FALSE; |
| 2068 | 1907 | } |
| 2069 | 1908 | $group = $this->group($group_id)->row(); |
| 2070 | - if($group->name == $this->config->item('admin_group', 'ion_auth')) |
|
| 2071 | - { |
|
| 1909 | + if($group->name == $this->config->item('admin_group', 'ion_auth')) { |
|
| 2072 | 1910 | $this->trigger_events(array('post_delete_group', 'post_delete_group_notallowed')); |
| 2073 | 1911 | $this->set_error('group_delete_notallowed'); |
| 2074 | 1912 | return FALSE; |
@@ -2083,8 +1921,7 @@ discard block |
||
| 2083 | 1921 | // remove the group itself |
| 2084 | 1922 | $this->db->delete($this->tables['groups'], array('id' => $group_id)); |
| 2085 | 1923 | |
| 2086 | - if ($this->db->trans_status() === FALSE) |
|
| 2087 | - { |
|
| 1924 | + if ($this->db->trans_status() === FALSE) { |
|
| 2088 | 1925 | $this->db->trans_rollback(); |
| 2089 | 1926 | $this->trigger_events(array('post_delete_group', 'post_delete_group_unsuccessful')); |
| 2090 | 1927 | $this->set_error('group_delete_unsuccessful'); |
@@ -2098,34 +1935,27 @@ discard block |
||
| 2098 | 1935 | return TRUE; |
| 2099 | 1936 | } |
| 2100 | 1937 | |
| 2101 | - public function set_hook($event, $name, $class, $method, $arguments) |
|
| 2102 | - { |
|
| 1938 | + public function set_hook($event, $name, $class, $method, $arguments) { |
|
| 2103 | 1939 | $this->_ion_hooks->{$event}[$name] = new stdClass; |
| 2104 | 1940 | $this->_ion_hooks->{$event}[$name]->class = $class; |
| 2105 | 1941 | $this->_ion_hooks->{$event}[$name]->method = $method; |
| 2106 | 1942 | $this->_ion_hooks->{$event}[$name]->arguments = $arguments; |
| 2107 | 1943 | } |
| 2108 | 1944 | |
| 2109 | - public function remove_hook($event, $name) |
|
| 2110 | - { |
|
| 2111 | - if (isset($this->_ion_hooks->{$event}[$name])) |
|
| 2112 | - { |
|
| 1945 | + public function remove_hook($event, $name) { |
|
| 1946 | + if (isset($this->_ion_hooks->{$event}[$name])) { |
|
| 2113 | 1947 | unset($this->_ion_hooks->{$event}[$name]); |
| 2114 | 1948 | } |
| 2115 | 1949 | } |
| 2116 | 1950 | |
| 2117 | - public function remove_hooks($event) |
|
| 2118 | - { |
|
| 2119 | - if (isset($this->_ion_hooks->$event)) |
|
| 2120 | - { |
|
| 1951 | + public function remove_hooks($event) { |
|
| 1952 | + if (isset($this->_ion_hooks->$event)) { |
|
| 2121 | 1953 | unset($this->_ion_hooks->$event); |
| 2122 | 1954 | } |
| 2123 | 1955 | } |
| 2124 | 1956 | |
| 2125 | - protected function _call_hook($event, $name) |
|
| 2126 | - { |
|
| 2127 | - if (isset($this->_ion_hooks->{$event}[$name]) && method_exists($this->_ion_hooks->{$event}[$name]->class, $this->_ion_hooks->{$event}[$name]->method)) |
|
| 2128 | - { |
|
| 1957 | + protected function _call_hook($event, $name) { |
|
| 1958 | + if (isset($this->_ion_hooks->{$event}[$name]) && method_exists($this->_ion_hooks->{$event}[$name]->class, $this->_ion_hooks->{$event}[$name]->method)) { |
|
| 2129 | 1959 | $hook = $this->_ion_hooks->{$event}[$name]; |
| 2130 | 1960 | |
| 2131 | 1961 | return call_user_func_array(array($hook->class, $hook->method), $hook->arguments); |
@@ -2134,21 +1964,14 @@ discard block |
||
| 2134 | 1964 | return FALSE; |
| 2135 | 1965 | } |
| 2136 | 1966 | |
| 2137 | - public function trigger_events($events) |
|
| 2138 | - { |
|
| 2139 | - if (is_array($events) && !empty($events)) |
|
| 2140 | - { |
|
| 2141 | - foreach ($events as $event) |
|
| 2142 | - { |
|
| 1967 | + public function trigger_events($events) { |
|
| 1968 | + if (is_array($events) && !empty($events)) { |
|
| 1969 | + foreach ($events as $event) { |
|
| 2143 | 1970 | $this->trigger_events($event); |
| 2144 | 1971 | } |
| 2145 | - } |
|
| 2146 | - else |
|
| 2147 | - { |
|
| 2148 | - if (isset($this->_ion_hooks->$events) && !empty($this->_ion_hooks->$events)) |
|
| 2149 | - { |
|
| 2150 | - foreach ($this->_ion_hooks->$events as $name => $hook) |
|
| 2151 | - { |
|
| 1972 | + } else { |
|
| 1973 | + if (isset($this->_ion_hooks->$events) && !empty($this->_ion_hooks->$events)) { |
|
| 1974 | + foreach ($this->_ion_hooks->$events as $name => $hook) { |
|
| 2152 | 1975 | $this->_call_hook($events, $name); |
| 2153 | 1976 | } |
| 2154 | 1977 | } |
@@ -2163,8 +1986,7 @@ discard block |
||
| 2163 | 1986 | * @return void |
| 2164 | 1987 | * @author Ben Edmunds |
| 2165 | 1988 | **/ |
| 2166 | - public function set_message_delimiters($start_delimiter, $end_delimiter) |
|
| 2167 | - { |
|
| 1989 | + public function set_message_delimiters($start_delimiter, $end_delimiter) { |
|
| 2168 | 1990 | $this->message_start_delimiter = $start_delimiter; |
| 2169 | 1991 | $this->message_end_delimiter = $end_delimiter; |
| 2170 | 1992 | |
@@ -2179,8 +2001,7 @@ discard block |
||
| 2179 | 2001 | * @return void |
| 2180 | 2002 | * @author Ben Edmunds |
| 2181 | 2003 | **/ |
| 2182 | - public function set_error_delimiters($start_delimiter, $end_delimiter) |
|
| 2183 | - { |
|
| 2004 | + public function set_error_delimiters($start_delimiter, $end_delimiter) { |
|
| 2184 | 2005 | $this->error_start_delimiter = $start_delimiter; |
| 2185 | 2006 | $this->error_end_delimiter = $end_delimiter; |
| 2186 | 2007 | |
@@ -2195,8 +2016,7 @@ discard block |
||
| 2195 | 2016 | * @return void |
| 2196 | 2017 | * @author Ben Edmunds |
| 2197 | 2018 | **/ |
| 2198 | - public function set_message($message) |
|
| 2199 | - { |
|
| 2019 | + public function set_message($message) { |
|
| 2200 | 2020 | $this->messages[] = $message; |
| 2201 | 2021 | |
| 2202 | 2022 | return $message; |
@@ -2212,11 +2032,9 @@ discard block |
||
| 2212 | 2032 | * @return void |
| 2213 | 2033 | * @author Ben Edmunds |
| 2214 | 2034 | **/ |
| 2215 | - public function messages() |
|
| 2216 | - { |
|
| 2035 | + public function messages() { |
|
| 2217 | 2036 | $_output = ''; |
| 2218 | - foreach ($this->messages as $message) |
|
| 2219 | - { |
|
| 2037 | + foreach ($this->messages as $message) { |
|
| 2220 | 2038 | $messageLang = $this->lang->line($message) ? $this->lang->line($message) : '##' . $message . '##'; |
| 2221 | 2039 | $_output .= $this->message_start_delimiter . $messageLang . $this->message_end_delimiter; |
| 2222 | 2040 | } |
@@ -2232,20 +2050,15 @@ discard block |
||
| 2232 | 2050 | * @return array |
| 2233 | 2051 | * @author Raul Baldner Junior |
| 2234 | 2052 | **/ |
| 2235 | - public function messages_array($langify = TRUE) |
|
| 2236 | - { |
|
| 2237 | - if ($langify) |
|
| 2238 | - { |
|
| 2053 | + public function messages_array($langify = TRUE) { |
|
| 2054 | + if ($langify) { |
|
| 2239 | 2055 | $_output = array(); |
| 2240 | - foreach ($this->messages as $message) |
|
| 2241 | - { |
|
| 2056 | + foreach ($this->messages as $message) { |
|
| 2242 | 2057 | $messageLang = $this->lang->line($message) ? $this->lang->line($message) : '##' . $message . '##'; |
| 2243 | 2058 | $_output[] = $this->message_start_delimiter . $messageLang . $this->message_end_delimiter; |
| 2244 | 2059 | } |
| 2245 | 2060 | return $_output; |
| 2246 | - } |
|
| 2247 | - else |
|
| 2248 | - { |
|
| 2061 | + } else { |
|
| 2249 | 2062 | return $this->messages; |
| 2250 | 2063 | } |
| 2251 | 2064 | } |
@@ -2259,8 +2072,7 @@ discard block |
||
| 2259 | 2072 | * @return void |
| 2260 | 2073 | * @author Ben Edmunds |
| 2261 | 2074 | **/ |
| 2262 | - public function clear_messages() |
|
| 2263 | - { |
|
| 2075 | + public function clear_messages() { |
|
| 2264 | 2076 | $this->messages = array(); |
| 2265 | 2077 | |
| 2266 | 2078 | return TRUE; |
@@ -2275,8 +2087,7 @@ discard block |
||
| 2275 | 2087 | * @return void |
| 2276 | 2088 | * @author Ben Edmunds |
| 2277 | 2089 | **/ |
| 2278 | - public function set_error($error) |
|
| 2279 | - { |
|
| 2090 | + public function set_error($error) { |
|
| 2280 | 2091 | $this->errors[] = $error; |
| 2281 | 2092 | |
| 2282 | 2093 | return $error; |
@@ -2290,11 +2101,9 @@ discard block |
||
| 2290 | 2101 | * @return void |
| 2291 | 2102 | * @author Ben Edmunds |
| 2292 | 2103 | **/ |
| 2293 | - public function errors() |
|
| 2294 | - { |
|
| 2104 | + public function errors() { |
|
| 2295 | 2105 | $_output = ''; |
| 2296 | - foreach ($this->errors as $error) |
|
| 2297 | - { |
|
| 2106 | + foreach ($this->errors as $error) { |
|
| 2298 | 2107 | $errorLang = $this->lang->line($error) ? $this->lang->line($error) : '##' . $error . '##'; |
| 2299 | 2108 | $_output .= $this->error_start_delimiter . $errorLang . $this->error_end_delimiter; |
| 2300 | 2109 | } |
@@ -2310,20 +2119,15 @@ discard block |
||
| 2310 | 2119 | * @return array |
| 2311 | 2120 | * @author Raul Baldner Junior |
| 2312 | 2121 | **/ |
| 2313 | - public function errors_array($langify = TRUE) |
|
| 2314 | - { |
|
| 2315 | - if ($langify) |
|
| 2316 | - { |
|
| 2122 | + public function errors_array($langify = TRUE) { |
|
| 2123 | + if ($langify) { |
|
| 2317 | 2124 | $_output = array(); |
| 2318 | - foreach ($this->errors as $error) |
|
| 2319 | - { |
|
| 2125 | + foreach ($this->errors as $error) { |
|
| 2320 | 2126 | $errorLang = $this->lang->line($error) ? $this->lang->line($error) : '##' . $error . '##'; |
| 2321 | 2127 | $_output[] = $this->error_start_delimiter . $errorLang . $this->error_end_delimiter; |
| 2322 | 2128 | } |
| 2323 | 2129 | return $_output; |
| 2324 | - } |
|
| 2325 | - else |
|
| 2326 | - { |
|
| 2130 | + } else { |
|
| 2327 | 2131 | return $this->errors; |
| 2328 | 2132 | } |
| 2329 | 2133 | } |
@@ -2337,8 +2141,7 @@ discard block |
||
| 2337 | 2141 | * @return void |
| 2338 | 2142 | * @author Ben Edmunds |
| 2339 | 2143 | **/ |
| 2340 | - public function clear_errors() |
|
| 2341 | - { |
|
| 2144 | + public function clear_errors() { |
|
| 2342 | 2145 | $this->errors = array(); |
| 2343 | 2146 | |
| 2344 | 2147 | return TRUE; |
@@ -2346,17 +2149,15 @@ discard block |
||
| 2346 | 2149 | |
| 2347 | 2150 | |
| 2348 | 2151 | |
| 2349 | - protected function _filter_data($table, $data) |
|
| 2350 | - { |
|
| 2152 | + protected function _filter_data($table, $data) { |
|
| 2351 | 2153 | $filtered_data = array(); |
| 2352 | 2154 | $columns = $this->db->list_fields($table); |
| 2353 | 2155 | |
| 2354 | - if (is_array($data)) |
|
| 2355 | - { |
|
| 2356 | - foreach ($columns as $column) |
|
| 2357 | - { |
|
| 2358 | - if (array_key_exists($column, $data)) |
|
| 2359 | - $filtered_data[$column] = $data[$column]; |
|
| 2156 | + if (is_array($data)) { |
|
| 2157 | + foreach ($columns as $column) { |
|
| 2158 | + if (array_key_exists($column, $data)) { |
|
| 2159 | + $filtered_data[$column] = $data[$column]; |
|
| 2160 | + } |
|
| 2360 | 2161 | } |
| 2361 | 2162 | } |
| 2362 | 2163 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | |
| 4 | 6 | class Bcrypt { |
@@ -49,34 +51,26 @@ discard block |
||
| 49 | 51 | * @param string $user_string |
| 50 | 52 | * @return bool |
| 51 | 53 | */ |
| 52 | - private function hashEquals($known_string, $user_string) |
|
| 53 | - { |
|
| 54 | + private function hashEquals($known_string, $user_string) { |
|
| 54 | 55 | // For CI3 or PHP >= 5.6 |
| 55 | - if (function_exists('hash_equals')) |
|
| 56 | - { |
|
| 56 | + if (function_exists('hash_equals')) { |
|
| 57 | 57 | return hash_equals($known_string, $user_string); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // For CI2 with PHP < 5.6 |
| 61 | 61 | // Code from CI3 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/compat/hash.php |
| 62 | - if ( ! is_string($known_string)) |
|
| 63 | - { |
|
| 62 | + if ( ! is_string($known_string)) { |
|
| 64 | 63 | trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING); |
| 65 | 64 | return FALSE; |
| 66 | - } |
|
| 67 | - elseif ( ! is_string($user_string)) |
|
| 68 | - { |
|
| 65 | + } elseif ( ! is_string($user_string)) { |
|
| 69 | 66 | trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING); |
| 70 | 67 | return FALSE; |
| 71 | - } |
|
| 72 | - elseif (($length = strlen($known_string)) !== strlen($user_string)) |
|
| 73 | - { |
|
| 68 | + } elseif (($length = strlen($known_string)) !== strlen($user_string)) { |
|
| 74 | 69 | return FALSE; |
| 75 | 70 | } |
| 76 | 71 | |
| 77 | 72 | $diff = 0; |
| 78 | - for ($i = 0; $i < $length; $i++) |
|
| 79 | - { |
|
| 73 | + for ($i = 0; $i < $length; $i++) { |
|
| 80 | 74 | $diff |= ord($known_string[$i]) ^ ord($user_string[$i]); |
| 81 | 75 | } |
| 82 | 76 | |
@@ -104,7 +98,8 @@ discard block |
||
| 104 | 98 | $bytes = ''; |
| 105 | 99 | |
| 106 | 100 | if(function_exists('openssl_random_pseudo_bytes') && |
| 107 | - (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win |
|
| 101 | + (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { |
|
| 102 | +// OpenSSL slow on Win |
|
| 108 | 103 | $bytes = openssl_random_pseudo_bytes($count); |
| 109 | 104 | } |
| 110 | 105 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Ion Auth |
| 4 | 6 | * |
@@ -19,8 +21,7 @@ discard block |
||
| 19 | 21 | * |
| 20 | 22 | */ |
| 21 | 23 | |
| 22 | -class Ion_auth |
|
| 23 | -{ |
|
| 24 | +class Ion_auth { |
|
| 24 | 25 | /** |
| 25 | 26 | * account status ('not_activated', etc ...) |
| 26 | 27 | * |
@@ -54,8 +55,7 @@ discard block |
||
| 54 | 55 | * |
| 55 | 56 | * @author Ben |
| 56 | 57 | */ |
| 57 | - public function __construct() |
|
| 58 | - { |
|
| 58 | + public function __construct() { |
|
| 59 | 59 | $this->config->load('ion_auth', TRUE); |
| 60 | 60 | $this->load->library(array('email')); |
| 61 | 61 | $this->lang->load('ion_auth'); |
@@ -69,8 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $email_config = $this->config->item('email_config', 'ion_auth'); |
| 71 | 71 | |
| 72 | - if ($this->config->item('use_ci_email', 'ion_auth') && isset($email_config) && is_array($email_config)) |
|
| 73 | - { |
|
| 72 | + if ($this->config->item('use_ci_email', 'ion_auth') && isset($email_config) && is_array($email_config)) { |
|
| 74 | 73 | $this->email->initialize($email_config); |
| 75 | 74 | } |
| 76 | 75 | |
@@ -87,18 +86,14 @@ discard block |
||
| 87 | 86 | * @return mixed |
| 88 | 87 | * @throws Exception |
| 89 | 88 | */ |
| 90 | - public function __call($method, $arguments) |
|
| 91 | - { |
|
| 92 | - if (!method_exists( $this->ion_auth_model, $method) ) |
|
| 93 | - { |
|
| 89 | + public function __call($method, $arguments) { |
|
| 90 | + if (!method_exists( $this->ion_auth_model, $method) ) { |
|
| 94 | 91 | throw new Exception('Undefined method Ion_auth::' . $method . '() called'); |
| 95 | 92 | } |
| 96 | - if($method == 'create_user') |
|
| 97 | - { |
|
| 93 | + if($method == 'create_user') { |
|
| 98 | 94 | return call_user_func_array(array($this, 'register'), $arguments); |
| 99 | 95 | } |
| 100 | - if($method=='update_user') |
|
| 101 | - { |
|
| 96 | + if($method=='update_user') { |
|
| 102 | 97 | return call_user_func_array(array($this, 'update'), $arguments); |
| 103 | 98 | } |
| 104 | 99 | return call_user_func_array( array($this->ion_auth_model, $method), $arguments); |
@@ -115,8 +110,7 @@ discard block |
||
| 115 | 110 | * @param $var |
| 116 | 111 | * @return mixed |
| 117 | 112 | */ |
| 118 | - public function __get($var) |
|
| 119 | - { |
|
| 113 | + public function __get($var) { |
|
| 120 | 114 | return get_instance()->$var; |
| 121 | 115 | } |
| 122 | 116 | |
@@ -130,26 +124,25 @@ discard block |
||
| 130 | 124 | */ |
| 131 | 125 | public function forgotten_password($identity) //changed $email to $identity |
| 132 | 126 | { |
| 133 | - if ( $this->ion_auth_model->forgotten_password($identity) ) //changed |
|
| 127 | + if ( $this->ion_auth_model->forgotten_password($identity) ) { |
|
| 128 | + //changed |
|
| 134 | 129 | { |
| 135 | 130 | // Get user information |
| 136 | - $identifier = $this->ion_auth_model->identity_column; // use model identity column, so it can be overridden in a controller |
|
| 131 | + $identifier = $this->ion_auth_model->identity_column; |
|
| 132 | + } |
|
| 133 | + // use model identity column, so it can be overridden in a controller |
|
| 137 | 134 | $user = $this->where($identifier, $identity)->where('active', 1)->users()->row(); // changed to get_user_by_identity from email |
| 138 | 135 | |
| 139 | - if ($user) |
|
| 140 | - { |
|
| 136 | + if ($user) { |
|
| 141 | 137 | $data = array( |
| 142 | 138 | 'identity' => $user->{$this->config->item('identity', 'ion_auth')}, |
| 143 | 139 | 'forgotten_password_code' => $user->forgotten_password_code |
| 144 | 140 | ); |
| 145 | 141 | |
| 146 | - if(!$this->config->item('use_ci_email', 'ion_auth')) |
|
| 147 | - { |
|
| 142 | + if(!$this->config->item('use_ci_email', 'ion_auth')) { |
|
| 148 | 143 | $this->set_message('forgot_password_successful'); |
| 149 | 144 | return $data; |
| 150 | - } |
|
| 151 | - else |
|
| 152 | - { |
|
| 145 | + } else { |
|
| 153 | 146 | $message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_forgot_password', 'ion_auth'), $data, true); |
| 154 | 147 | $this->email->clear(); |
| 155 | 148 | $this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth')); |
@@ -157,26 +150,19 @@ discard block |
||
| 157 | 150 | $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject')); |
| 158 | 151 | $this->email->message($message); |
| 159 | 152 | |
| 160 | - if ($this->email->send()) |
|
| 161 | - { |
|
| 153 | + if ($this->email->send()) { |
|
| 162 | 154 | $this->set_message('forgot_password_successful'); |
| 163 | 155 | return TRUE; |
| 164 | - } |
|
| 165 | - else |
|
| 166 | - { |
|
| 156 | + } else { |
|
| 167 | 157 | $this->set_error('forgot_password_unsuccessful'); |
| 168 | 158 | return FALSE; |
| 169 | 159 | } |
| 170 | 160 | } |
| 171 | - } |
|
| 172 | - else |
|
| 173 | - { |
|
| 161 | + } else { |
|
| 174 | 162 | $this->set_error('forgot_password_unsuccessful'); |
| 175 | 163 | return FALSE; |
| 176 | 164 | } |
| 177 | - } |
|
| 178 | - else |
|
| 179 | - { |
|
| 165 | + } else { |
|
| 180 | 166 | $this->set_error('forgot_password_unsuccessful'); |
| 181 | 167 | return FALSE; |
| 182 | 168 | } |
@@ -189,15 +175,13 @@ discard block |
||
| 189 | 175 | * @author Mathew |
| 190 | 176 | * @return bool |
| 191 | 177 | */ |
| 192 | - public function forgotten_password_complete($code) |
|
| 193 | - { |
|
| 178 | + public function forgotten_password_complete($code) { |
|
| 194 | 179 | $this->ion_auth_model->trigger_events('pre_password_change'); |
| 195 | 180 | |
| 196 | 181 | $identity = $this->config->item('identity', 'ion_auth'); |
| 197 | 182 | $profile = $this->where('forgotten_password_code', $code)->users()->row(); //pass the code to profile |
| 198 | 183 | |
| 199 | - if (!$profile) |
|
| 200 | - { |
|
| 184 | + if (!$profile) { |
|
| 201 | 185 | $this->ion_auth_model->trigger_events(array('post_password_change', 'password_change_unsuccessful')); |
| 202 | 186 | $this->set_error('password_change_unsuccessful'); |
| 203 | 187 | return FALSE; |
@@ -205,20 +189,16 @@ discard block |
||
| 205 | 189 | |
| 206 | 190 | $new_password = $this->ion_auth_model->forgotten_password_complete($code, $profile->salt); |
| 207 | 191 | |
| 208 | - if ($new_password) |
|
| 209 | - { |
|
| 192 | + if ($new_password) { |
|
| 210 | 193 | $data = array( |
| 211 | 194 | 'identity' => $profile->{$identity}, |
| 212 | 195 | 'new_password' => $new_password |
| 213 | 196 | ); |
| 214 | - if(!$this->config->item('use_ci_email', 'ion_auth')) |
|
| 215 | - { |
|
| 197 | + if(!$this->config->item('use_ci_email', 'ion_auth')) { |
|
| 216 | 198 | $this->set_message('password_change_successful'); |
| 217 | 199 | $this->ion_auth_model->trigger_events(array('post_password_change', 'password_change_successful')); |
| 218 | 200 | return $data; |
| 219 | - } |
|
| 220 | - else |
|
| 221 | - { |
|
| 201 | + } else { |
|
| 222 | 202 | $message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_forgot_password_complete', 'ion_auth'), $data, true); |
| 223 | 203 | |
| 224 | 204 | $this->email->clear(); |
@@ -227,14 +207,11 @@ discard block |
||
| 227 | 207 | $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_new_password_subject')); |
| 228 | 208 | $this->email->message($message); |
| 229 | 209 | |
| 230 | - if ($this->email->send()) |
|
| 231 | - { |
|
| 210 | + if ($this->email->send()) { |
|
| 232 | 211 | $this->set_message('password_change_successful'); |
| 233 | 212 | $this->ion_auth_model->trigger_events(array('post_password_change', 'password_change_successful')); |
| 234 | 213 | return TRUE; |
| 235 | - } |
|
| 236 | - else |
|
| 237 | - { |
|
| 214 | + } else { |
|
| 238 | 215 | $this->set_error('password_change_unsuccessful'); |
| 239 | 216 | $this->ion_auth_model->trigger_events(array('post_password_change', 'password_change_unsuccessful')); |
| 240 | 217 | return FALSE; |
@@ -254,17 +231,13 @@ discard block |
||
| 254 | 231 | * @author Michael |
| 255 | 232 | * @return bool |
| 256 | 233 | */ |
| 257 | - public function forgotten_password_check($code) |
|
| 258 | - { |
|
| 234 | + public function forgotten_password_check($code) { |
|
| 259 | 235 | $profile = $this->where('forgotten_password_code', $code)->users()->row(); //pass the code to profile |
| 260 | 236 | |
| 261 | - if (!is_object($profile)) |
|
| 262 | - { |
|
| 237 | + if (!is_object($profile)) { |
|
| 263 | 238 | $this->set_error('password_change_unsuccessful'); |
| 264 | 239 | return FALSE; |
| 265 | - } |
|
| 266 | - else |
|
| 267 | - { |
|
| 240 | + } else { |
|
| 268 | 241 | if ($this->config->item('forgot_password_expiration', 'ion_auth') > 0) { |
| 269 | 242 | //Make sure it isn't expired |
| 270 | 243 | $expiration = $this->config->item('forgot_password_expiration', 'ion_auth'); |
@@ -298,25 +271,18 @@ discard block |
||
| 298 | 271 | |
| 299 | 272 | $id = $this->ion_auth_model->register($identity, $password, $email, $additional_data, $group_ids); |
| 300 | 273 | |
| 301 | - if (!$email_activation) |
|
| 302 | - { |
|
| 303 | - if ($id !== FALSE) |
|
| 304 | - { |
|
| 274 | + if (!$email_activation) { |
|
| 275 | + if ($id !== FALSE) { |
|
| 305 | 276 | $this->set_message('account_creation_successful'); |
| 306 | 277 | $this->ion_auth_model->trigger_events(array('post_account_creation', 'post_account_creation_successful')); |
| 307 | 278 | return $id; |
| 308 | - } |
|
| 309 | - else |
|
| 310 | - { |
|
| 279 | + } else { |
|
| 311 | 280 | $this->set_error('account_creation_unsuccessful'); |
| 312 | 281 | $this->ion_auth_model->trigger_events(array('post_account_creation', 'post_account_creation_unsuccessful')); |
| 313 | 282 | return FALSE; |
| 314 | 283 | } |
| 315 | - } |
|
| 316 | - else |
|
| 317 | - { |
|
| 318 | - if (!$id) |
|
| 319 | - { |
|
| 284 | + } else { |
|
| 285 | + if (!$id) { |
|
| 320 | 286 | $this->set_error('account_creation_unsuccessful'); |
| 321 | 287 | return FALSE; |
| 322 | 288 | } |
@@ -328,8 +294,7 @@ discard block |
||
| 328 | 294 | $this->ion_auth_model->clear_messages(); |
| 329 | 295 | |
| 330 | 296 | |
| 331 | - if (!$deactivate) |
|
| 332 | - { |
|
| 297 | + if (!$deactivate) { |
|
| 333 | 298 | $this->set_error('deactivate_unsuccessful'); |
| 334 | 299 | $this->ion_auth_model->trigger_events(array('post_account_creation', 'post_account_creation_unsuccessful')); |
| 335 | 300 | return FALSE; |
@@ -345,14 +310,11 @@ discard block |
||
| 345 | 310 | 'email' => $email, |
| 346 | 311 | 'activation' => $activation_code, |
| 347 | 312 | ); |
| 348 | - if(!$this->config->item('use_ci_email', 'ion_auth')) |
|
| 349 | - { |
|
| 313 | + if(!$this->config->item('use_ci_email', 'ion_auth')) { |
|
| 350 | 314 | $this->ion_auth_model->trigger_events(array('post_account_creation', 'post_account_creation_successful', 'activation_email_successful')); |
| 351 | 315 | $this->set_message('activation_email_successful'); |
| 352 | 316 | return $data; |
| 353 | - } |
|
| 354 | - else |
|
| 355 | - { |
|
| 317 | + } else { |
|
| 356 | 318 | $message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_activate', 'ion_auth'), $data, true); |
| 357 | 319 | |
| 358 | 320 | $this->email->clear(); |
@@ -361,8 +323,7 @@ discard block |
||
| 361 | 323 | $this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_activation_subject')); |
| 362 | 324 | $this->email->message($message); |
| 363 | 325 | |
| 364 | - if ($this->email->send() == TRUE) |
|
| 365 | - { |
|
| 326 | + if ($this->email->send() == TRUE) { |
|
| 366 | 327 | $this->ion_auth_model->trigger_events(array('post_account_creation', 'post_account_creation_successful', 'activation_email_successful')); |
| 367 | 328 | $this->set_message('activation_email_successful'); |
| 368 | 329 | return $id; |
@@ -382,28 +343,22 @@ discard block |
||
| 382 | 343 | * @return void |
| 383 | 344 | * @author Mathew |
| 384 | 345 | **/ |
| 385 | - public function logout() |
|
| 386 | - { |
|
| 346 | + public function logout() { |
|
| 387 | 347 | $this->ion_auth_model->trigger_events('logout'); |
| 388 | 348 | |
| 389 | 349 | $identity = $this->config->item('identity', 'ion_auth'); |
| 390 | 350 | |
| 391 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 392 | - { |
|
| 351 | + if (substr(CI_VERSION, 0, 1) == '2') { |
|
| 393 | 352 | $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
| 394 | - } |
|
| 395 | - else |
|
| 396 | - { |
|
| 353 | + } else { |
|
| 397 | 354 | $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
| 398 | 355 | } |
| 399 | 356 | |
| 400 | 357 | // delete the remember me cookies if they exist |
| 401 | - if (get_cookie($this->config->item('identity_cookie_name', 'ion_auth'))) |
|
| 402 | - { |
|
| 358 | + if (get_cookie($this->config->item('identity_cookie_name', 'ion_auth'))) { |
|
| 403 | 359 | delete_cookie($this->config->item('identity_cookie_name', 'ion_auth')); |
| 404 | 360 | } |
| 405 | - if (get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 406 | - { |
|
| 361 | + if (get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) { |
|
| 407 | 362 | delete_cookie($this->config->item('remember_cookie_name', 'ion_auth')); |
| 408 | 363 | } |
| 409 | 364 | |
@@ -411,12 +366,9 @@ discard block |
||
| 411 | 366 | $this->session->sess_destroy(); |
| 412 | 367 | |
| 413 | 368 | //Recreate the session |
| 414 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 415 | - { |
|
| 369 | + if (substr(CI_VERSION, 0, 1) == '2') { |
|
| 416 | 370 | $this->session->sess_create(); |
| 417 | - } |
|
| 418 | - else |
|
| 419 | - { |
|
| 371 | + } else { |
|
| 420 | 372 | if (version_compare(PHP_VERSION, '7.0.0') >= 0) { |
| 421 | 373 | session_start(); |
| 422 | 374 | } |
@@ -433,15 +385,13 @@ discard block |
||
| 433 | 385 | * @return bool |
| 434 | 386 | * @author Mathew |
| 435 | 387 | **/ |
| 436 | - public function logged_in() |
|
| 437 | - { |
|
| 388 | + public function logged_in() { |
|
| 438 | 389 | $this->ion_auth_model->trigger_events('logged_in'); |
| 439 | 390 | |
| 440 | 391 | $recheck= $this->ion_auth_model->recheck_session(); |
| 441 | 392 | |
| 442 | 393 | //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 | - { |
|
| 394 | + if ( ! $recheck && get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) && get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) { |
|
| 445 | 395 | $recheck = $this->ion_auth_model->login_remembered_user(); |
| 446 | 396 | } |
| 447 | 397 | |
@@ -454,11 +404,9 @@ discard block |
||
| 454 | 404 | * @return integer |
| 455 | 405 | * @author jrmadsen67 |
| 456 | 406 | **/ |
| 457 | - public function get_user_id() |
|
| 458 | - { |
|
| 407 | + public function get_user_id() { |
|
| 459 | 408 | $user_id = $this->session->userdata('user_id'); |
| 460 | - if (!empty($user_id)) |
|
| 461 | - { |
|
| 409 | + if (!empty($user_id)) { |
|
| 462 | 410 | return $user_id; |
| 463 | 411 | } |
| 464 | 412 | return null; |
@@ -471,8 +419,7 @@ discard block |
||
| 471 | 419 | * @return bool |
| 472 | 420 | * @author Ben Edmunds |
| 473 | 421 | **/ |
| 474 | - public function is_admin($id=false) |
|
| 475 | - { |
|
| 422 | + public function is_admin($id=false) { |
|
| 476 | 423 | $this->ion_auth_model->trigger_events('is_admin'); |
| 477 | 424 | |
| 478 | 425 | $admin_group = $this->config->item('admin_group', 'ion_auth'); |
@@ -490,41 +437,33 @@ discard block |
||
| 490 | 437 | * @return bool |
| 491 | 438 | * @author Phil Sturgeon |
| 492 | 439 | **/ |
| 493 | - public function in_group($check_group, $id=false, $check_all = false) |
|
| 494 | - { |
|
| 440 | + public function in_group($check_group, $id=false, $check_all = false) { |
|
| 495 | 441 | $this->ion_auth_model->trigger_events('in_group'); |
| 496 | 442 | |
| 497 | 443 | $id || $id = $this->session->userdata('user_id'); |
| 498 | 444 | |
| 499 | - if (!is_array($check_group)) |
|
| 500 | - { |
|
| 445 | + if (!is_array($check_group)) { |
|
| 501 | 446 | $check_group = array($check_group); |
| 502 | 447 | } |
| 503 | 448 | |
| 504 | - if (isset($this->_cache_user_in_group[$id])) |
|
| 505 | - { |
|
| 449 | + if (isset($this->_cache_user_in_group[$id])) { |
|
| 506 | 450 | $groups_array = $this->_cache_user_in_group[$id]; |
| 507 | - } |
|
| 508 | - else |
|
| 509 | - { |
|
| 451 | + } else { |
|
| 510 | 452 | $users_groups = $this->ion_auth_model->get_users_groups($id)->result(); |
| 511 | 453 | $groups_array = array(); |
| 512 | - foreach ($users_groups as $group) |
|
| 513 | - { |
|
| 454 | + foreach ($users_groups as $group) { |
|
| 514 | 455 | $groups_array[$group->id] = $group->name; |
| 515 | 456 | } |
| 516 | 457 | $this->_cache_user_in_group[$id] = $groups_array; |
| 517 | 458 | } |
| 518 | - foreach ($check_group as $key => $value) |
|
| 519 | - { |
|
| 459 | + foreach ($check_group as $key => $value) { |
|
| 520 | 460 | $groups = (is_string($value)) ? $groups_array : array_keys($groups_array); |
| 521 | 461 | |
| 522 | 462 | /** |
| 523 | 463 | * if !all (default), in_array |
| 524 | 464 | * if all, !in_array |
| 525 | 465 | */ |
| 526 | - if (in_array($value, $groups) xor $check_all) |
|
| 527 | - { |
|
| 466 | + if (in_array($value, $groups) xor $check_all) { |
|
| 528 | 467 | /** |
| 529 | 468 | * if !all (default), true |
| 530 | 469 | * if all, false |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if (!defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /** |
| 4 | 6 | * Sekati CodeIgniter Asset Helper |
@@ -52,8 +54,7 @@ discard block |
||
| 52 | 54 | */ |
| 53 | 55 | |
| 54 | 56 | if (!function_exists('asset_url')) { |
| 55 | - function asset_url() |
|
| 56 | - { |
|
| 57 | + function asset_url() { |
|
| 57 | 58 | //get an instance of CI so we can access our configuration |
| 58 | 59 | $CI =& get_instance(); |
| 59 | 60 | |
@@ -69,8 +70,7 @@ discard block |
||
| 69 | 70 | * @return string |
| 70 | 71 | */ |
| 71 | 72 | if (!function_exists('css_url')) { |
| 72 | - function css_url() |
|
| 73 | - { |
|
| 73 | + function css_url() { |
|
| 74 | 74 | $CI =& get_instance(); |
| 75 | 75 | |
| 76 | 76 | return $CI->config->slash_item('static_url') . $CI->config->item('css_path'); |
@@ -84,8 +84,7 @@ discard block |
||
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | 86 | if (!function_exists('less_url')) { |
| 87 | - function less_url() |
|
| 88 | - { |
|
| 87 | + function less_url() { |
|
| 89 | 88 | $CI =& get_instance(); |
| 90 | 89 | |
| 91 | 90 | return $CI->config->slash_item('static_url') . $CI->config->item('less_path'); |
@@ -99,8 +98,7 @@ discard block |
||
| 99 | 98 | * @return string |
| 100 | 99 | */ |
| 101 | 100 | if (!function_exists('js_url')) { |
| 102 | - function js_url() |
|
| 103 | - { |
|
| 101 | + function js_url() { |
|
| 104 | 102 | $CI =& get_instance(); |
| 105 | 103 | |
| 106 | 104 | return $CI->config->slash_item('static_url') . $CI->config->item('js_path'); |
@@ -114,8 +112,7 @@ discard block |
||
| 114 | 112 | * @return string |
| 115 | 113 | */ |
| 116 | 114 | if (!function_exists('img_url')) { |
| 117 | - function img_url() |
|
| 118 | - { |
|
| 115 | + function img_url() { |
|
| 119 | 116 | $CI =& get_instance(); |
| 120 | 117 | |
| 121 | 118 | return $CI->config->slash_item('static_url') . $CI->config->item('img_path'); |
@@ -129,8 +126,7 @@ discard block |
||
| 129 | 126 | * @return string |
| 130 | 127 | */ |
| 131 | 128 | if (!function_exists('swf_url')) { |
| 132 | - function swf_url() |
|
| 133 | - { |
|
| 129 | + function swf_url() { |
|
| 134 | 130 | $CI =& get_instance(); |
| 135 | 131 | |
| 136 | 132 | return $CI->config->slash_item('static_url') . $CI->config->item('swf_path'); |
@@ -144,8 +140,7 @@ discard block |
||
| 144 | 140 | * @return string |
| 145 | 141 | */ |
| 146 | 142 | if (!function_exists('upload_url')) { |
| 147 | - function upload_url() |
|
| 148 | - { |
|
| 143 | + function upload_url() { |
|
| 149 | 144 | $CI =& get_instance(); |
| 150 | 145 | |
| 151 | 146 | return base_url() . $CI->config->item('upload_path'); |
@@ -159,8 +154,7 @@ discard block |
||
| 159 | 154 | * @return string |
| 160 | 155 | */ |
| 161 | 156 | if (!function_exists('download_url')) { |
| 162 | - function download_url() |
|
| 163 | - { |
|
| 157 | + function download_url() { |
|
| 164 | 158 | $CI =& get_instance(); |
| 165 | 159 | |
| 166 | 160 | return base_url() . $CI->config->item('download_path'); |
@@ -174,8 +168,7 @@ discard block |
||
| 174 | 168 | * @return string |
| 175 | 169 | */ |
| 176 | 170 | if (!function_exists('xml_url')) { |
| 177 | - function xml_url() |
|
| 178 | - { |
|
| 171 | + function xml_url() { |
|
| 179 | 172 | $CI =& get_instance(); |
| 180 | 173 | |
| 181 | 174 | return base_url() . $CI->config->item('xml_path'); |
@@ -193,8 +186,7 @@ discard block |
||
| 193 | 186 | * @return string |
| 194 | 187 | */ |
| 195 | 188 | if (!function_exists('asset_path')) { |
| 196 | - function asset_path() |
|
| 197 | - { |
|
| 189 | + function asset_path() { |
|
| 198 | 190 | //get an instance of CI so we can access our configuration |
| 199 | 191 | $CI =& get_instance(); |
| 200 | 192 | |
@@ -209,8 +201,7 @@ discard block |
||
| 209 | 201 | * @return string |
| 210 | 202 | */ |
| 211 | 203 | if (!function_exists('css_path')) { |
| 212 | - function css_path() |
|
| 213 | - { |
|
| 204 | + function css_path() { |
|
| 214 | 205 | //get an instance of CI so we can access our configuration |
| 215 | 206 | $CI =& get_instance(); |
| 216 | 207 | |
@@ -225,8 +216,7 @@ discard block |
||
| 225 | 216 | * @return string |
| 226 | 217 | */ |
| 227 | 218 | if (!function_exists('less_path')) { |
| 228 | - function less_path() |
|
| 229 | - { |
|
| 219 | + function less_path() { |
|
| 230 | 220 | //get an instance of CI so we can access our configuration |
| 231 | 221 | $CI =& get_instance(); |
| 232 | 222 | |
@@ -241,8 +231,7 @@ discard block |
||
| 241 | 231 | * @return string |
| 242 | 232 | */ |
| 243 | 233 | if (!function_exists('js_path')) { |
| 244 | - function js_path() |
|
| 245 | - { |
|
| 234 | + function js_path() { |
|
| 246 | 235 | //get an instance of CI so we can access our configuration |
| 247 | 236 | $CI =& get_instance(); |
| 248 | 237 | |
@@ -257,8 +246,7 @@ discard block |
||
| 257 | 246 | * @return string |
| 258 | 247 | */ |
| 259 | 248 | if (!function_exists('img_path')) { |
| 260 | - function img_path() |
|
| 261 | - { |
|
| 249 | + function img_path() { |
|
| 262 | 250 | //get an instance of CI so we can access our configuration |
| 263 | 251 | $CI =& get_instance(); |
| 264 | 252 | |
@@ -273,8 +261,7 @@ discard block |
||
| 273 | 261 | * @return string |
| 274 | 262 | */ |
| 275 | 263 | if (!function_exists('swf_path')) { |
| 276 | - function swf_path() |
|
| 277 | - { |
|
| 264 | + function swf_path() { |
|
| 278 | 265 | $CI =& get_instance(); |
| 279 | 266 | |
| 280 | 267 | return FCPATH . $CI->config->item('swf_path'); |
@@ -288,8 +275,7 @@ discard block |
||
| 288 | 275 | * @return string |
| 289 | 276 | */ |
| 290 | 277 | if (!function_exists('xml_path')) { |
| 291 | - function xml_path() |
|
| 292 | - { |
|
| 278 | + function xml_path() { |
|
| 293 | 279 | $CI =& get_instance(); |
| 294 | 280 | |
| 295 | 281 | return FCPATH . $CI->config->item('xml_path'); |
@@ -303,8 +289,7 @@ discard block |
||
| 303 | 289 | * @return string |
| 304 | 290 | */ |
| 305 | 291 | if (!function_exists('upload_path')) { |
| 306 | - function upload_path() |
|
| 307 | - { |
|
| 292 | + function upload_path() { |
|
| 308 | 293 | $CI =& get_instance(); |
| 309 | 294 | |
| 310 | 295 | return FCPATH . $CI->config->item('upload_path'); |
@@ -318,8 +303,7 @@ discard block |
||
| 318 | 303 | * @return string |
| 319 | 304 | */ |
| 320 | 305 | if (!function_exists('upload_path_relative')) { |
| 321 | - function upload_path_relative() |
|
| 322 | - { |
|
| 306 | + function upload_path_relative() { |
|
| 323 | 307 | $CI =& get_instance(); |
| 324 | 308 | |
| 325 | 309 | return './' . $CI->config->item('upload_path'); |
@@ -333,8 +317,7 @@ discard block |
||
| 333 | 317 | * @return string |
| 334 | 318 | */ |
| 335 | 319 | if (!function_exists('download_path')) { |
| 336 | - function download_path() |
|
| 337 | - { |
|
| 320 | + function download_path() { |
|
| 338 | 321 | $CI =& get_instance(); |
| 339 | 322 | |
| 340 | 323 | return FCPATH . $CI->config->item('download_path'); |
@@ -348,8 +331,7 @@ discard block |
||
| 348 | 331 | * @return string |
| 349 | 332 | */ |
| 350 | 333 | if (!function_exists('download_path_relative')) { |
| 351 | - function download_path_relative() |
|
| 352 | - { |
|
| 334 | + function download_path_relative() { |
|
| 353 | 335 | $CI =& get_instance(); |
| 354 | 336 | |
| 355 | 337 | return './' . $CI->config->item('download_path'); |
@@ -370,8 +352,7 @@ discard block |
||
| 370 | 352 | * @return string |
| 371 | 353 | */ |
| 372 | 354 | if (!function_exists('css')) { |
| 373 | - function css($file, $media = 'all') |
|
| 374 | - { |
|
| 355 | + function css($file, $media = 'all') { |
|
| 375 | 356 | return '<link rel="stylesheet" type="text/css" href="' . css_url() . $file . '" media="' . $media . '">' . "\n"; |
| 376 | 357 | } |
| 377 | 358 | } |
@@ -386,8 +367,7 @@ discard block |
||
| 386 | 367 | * @return string |
| 387 | 368 | */ |
| 388 | 369 | if (!function_exists('less')) { |
| 389 | - function less($file) |
|
| 390 | - { |
|
| 370 | + function less($file) { |
|
| 391 | 371 | return '<link rel="stylesheet/less" type="text/css" href="' . less_url() . $file . '">' . "\n"; |
| 392 | 372 | } |
| 393 | 373 | } |
@@ -403,12 +383,12 @@ discard block |
||
| 403 | 383 | * @return string |
| 404 | 384 | */ |
| 405 | 385 | if (!function_exists('js')) { |
| 406 | - function js($file, $atts = array()) |
|
| 407 | - { |
|
| 386 | + function js($file, $atts = array()) { |
|
| 408 | 387 | $element = '<script type="text/javascript" src="' . js_url() . $file . '"'; |
| 409 | 388 | |
| 410 | - foreach ($atts as $key => $val) |
|
| 411 | - $element .= ' ' . $key . '="' . $val . '"'; |
|
| 389 | + foreach ($atts as $key => $val) { |
|
| 390 | + $element .= ' ' . $key . '="' . $val . '"'; |
|
| 391 | + } |
|
| 412 | 392 | $element .= '></script>' . "\n"; |
| 413 | 393 | |
| 414 | 394 | return $element; |
@@ -426,11 +406,11 @@ discard block |
||
| 426 | 406 | * @return string |
| 427 | 407 | */ |
| 428 | 408 | if (!function_exists('img')) { |
| 429 | - function img($file, $atts = array()) |
|
| 430 | - { |
|
| 409 | + function img($file, $atts = array()) { |
|
| 431 | 410 | $url = '<img src="' . img_url() . $file . '"'; |
| 432 | - foreach ($atts as $key => $val) |
|
| 433 | - $url .= ' ' . $key . '="' . $val . '"'; |
|
| 411 | + foreach ($atts as $key => $val) { |
|
| 412 | + $url .= ' ' . $key . '="' . $val . '"'; |
|
| 413 | + } |
|
| 434 | 414 | $url .= " />\n"; |
| 435 | 415 | |
| 436 | 416 | return $url; |
@@ -447,8 +427,7 @@ discard block |
||
| 447 | 427 | * @return string |
| 448 | 428 | */ |
| 449 | 429 | if (!function_exists('jquery')) { |
| 450 | - function jquery($version = '') |
|
| 451 | - { |
|
| 430 | + function jquery($version = '') { |
|
| 452 | 431 | // Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline |
| 453 | 432 | $out = '<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $version . '/jquery.min.js"></script>' . "\n"; |
| 454 | 433 | $out .= '<script>window.jQuery || document.write(\'<script src="' . js_url() . 'jquery-' . $version . '.min.js"><\/script>\')</script>' . "\n"; |
@@ -467,8 +446,7 @@ discard block |
||
| 467 | 446 | * @return string |
| 468 | 447 | */ |
| 469 | 448 | if (!function_exists('google_analytics')) { |
| 470 | - function google_analytics($ua = '') |
|
| 471 | - { |
|
| 449 | + function google_analytics($ua = '') { |
|
| 472 | 450 | // Change UA-XXXXX-X to be your site's ID |
| 473 | 451 | $out = "<!-- Google Webmaster Tools & Analytics -->\n"; |
| 474 | 452 | $out .= '<script type="text/javascript">'; |
@@ -367,12 +367,10 @@ discard block |
||
| 367 | 367 | * |
| 368 | 368 | * @deprecated |
| 369 | 369 | */ |
| 370 | - public function set_email($email) |
|
| 371 | - { |
|
| 370 | + public function set_email($email) { |
|
| 372 | 371 | $email = trim(strtolower($email)); |
| 373 | 372 | |
| 374 | - if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 375 | - { |
|
| 373 | + if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 376 | 374 | return md5($email); |
| 377 | 375 | } |
| 378 | 376 | |
@@ -393,12 +391,10 @@ discard block |
||
| 393 | 391 | * |
| 394 | 392 | * @deprecated |
| 395 | 393 | */ |
| 396 | - public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) |
|
| 397 | - { |
|
| 394 | + public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) { |
|
| 398 | 395 | $hash = $this->set_email($email); |
| 399 | 396 | |
| 400 | - if ($hash === NULL) |
|
| 401 | - { |
|
| 397 | + if ($hash === NULL) { |
|
| 402 | 398 | // $hash has to be set to a value so the gravatar site can return a default image |
| 403 | 399 | $hash = 'invalid_email'; |
| 404 | 400 | } |
@@ -406,32 +402,25 @@ discard block |
||
| 406 | 402 | $query_string = NULL; |
| 407 | 403 | $options = array(); |
| 408 | 404 | |
| 409 | - if ($rating !== NULL) |
|
| 410 | - { |
|
| 405 | + if ($rating !== NULL) { |
|
| 411 | 406 | $options['r'] = $rating; |
| 412 | 407 | } |
| 413 | 408 | |
| 414 | - if ($size !== NULL) |
|
| 415 | - { |
|
| 409 | + if ($size !== NULL) { |
|
| 416 | 410 | $options['s'] = $size; |
| 417 | 411 | } |
| 418 | 412 | |
| 419 | - if ($default_image !== NULL) |
|
| 420 | - { |
|
| 413 | + if ($default_image !== NULL) { |
|
| 421 | 414 | $options['d'] = urlencode($default_image); |
| 422 | 415 | } |
| 423 | 416 | |
| 424 | - if (count($options) > 0) |
|
| 425 | - { |
|
| 417 | + if (count($options) > 0) { |
|
| 426 | 418 | $query_string = '?'. http_build_query($options); |
| 427 | 419 | } |
| 428 | 420 | |
| 429 | - if ($secure !== NULL) |
|
| 430 | - { |
|
| 421 | + if ($secure !== NULL) { |
|
| 431 | 422 | $base = $this->gravatar_secure_base_url; |
| 432 | - } |
|
| 433 | - else |
|
| 434 | - { |
|
| 423 | + } else { |
|
| 435 | 424 | $base = $this->gravatar_base_url; |
| 436 | 425 | } |
| 437 | 426 | |
@@ -448,32 +437,26 @@ discard block |
||
| 448 | 437 | * |
| 449 | 438 | * @deprecated |
| 450 | 439 | */ |
| 451 | - public function get_profile($email, $fetch_method = 'file') |
|
| 452 | - { |
|
| 440 | + public function get_profile($email, $fetch_method = 'file') { |
|
| 453 | 441 | $hash = $this->set_email($email); |
| 454 | 442 | |
| 455 | - if ($hash === NULL) |
|
| 456 | - { |
|
| 443 | + if ($hash === NULL) { |
|
| 457 | 444 | // A hash value of NULL will return no xml so the method returns NULL |
| 458 | 445 | return NULL; |
| 459 | 446 | } |
| 460 | 447 | |
| 461 | 448 | libxml_use_internal_errors(TRUE); |
| 462 | 449 | |
| 463 | - if ($fetch_method === 'file') |
|
| 464 | - { |
|
| 465 | - if (ini_get('allow_url_fopen') == FALSE) |
|
| 466 | - { |
|
| 450 | + if ($fetch_method === 'file') { |
|
| 451 | + if (ini_get('allow_url_fopen') == FALSE) { |
|
| 467 | 452 | return NULL; |
| 468 | 453 | } |
| 469 | 454 | |
| 470 | 455 | $str = file_get_contents($this->gravatar_base_url . $hash .'.xml'); |
| 471 | 456 | } |
| 472 | 457 | |
| 473 | - if ($fetch_method === 'curl') |
|
| 474 | - { |
|
| 475 | - if ( ! function_exists('curl_init')) |
|
| 476 | - { |
|
| 458 | + if ($fetch_method === 'curl') { |
|
| 459 | + if ( ! function_exists('curl_init')) { |
|
| 477 | 460 | return NULL; |
| 478 | 461 | } |
| 479 | 462 | |
@@ -490,18 +473,14 @@ discard block |
||
| 490 | 473 | |
| 491 | 474 | $xml = simplexml_load_string($str); |
| 492 | 475 | |
| 493 | - if ($xml === FALSE) |
|
| 494 | - { |
|
| 476 | + if ($xml === FALSE) { |
|
| 495 | 477 | $errors = array(); |
| 496 | - foreach(libxml_get_errors() as $error) |
|
| 497 | - { |
|
| 478 | + foreach(libxml_get_errors() as $error) { |
|
| 498 | 479 | $errors[] = $error->message.'\n'; |
| 499 | 480 | } |
| 500 | 481 | $error_string = implode('\n', $errors); |
| 501 | 482 | throw new Exception('Failed loading XML\n'. $error_string); |
| 502 | - } |
|
| 503 | - else |
|
| 504 | - { |
|
| 483 | + } else { |
|
| 505 | 484 | return $xml->entry; |
| 506 | 485 | } |
| 507 | 486 | } |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Auth Lang - English |
| 4 | 6 | * |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Auth Lang - English |
| 4 | 6 | * |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Auth Lang - English |
| 4 | 6 | * |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Name: Auth Lang - Slovenian |
| 4 | 6 | * |