@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | //-------------------------------------------------------------------- |
| 64 | 64 | |
| 65 | - public function __construct( $ci=null ) |
|
| 65 | + public function __construct($ci = null) |
|
| 66 | 66 | { |
| 67 | 67 | if ($ci) |
| 68 | 68 | { |
| 69 | - $this->ci= $ci; |
|
| 69 | + $this->ci = $ci; |
|
| 70 | 70 | } |
| 71 | 71 | else |
| 72 | 72 | { |
| 73 | - $this->ci =& get_instance(); |
|
| 73 | + $this->ci = & get_instance(); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Get our compatibility password file loaded up. |
| 77 | - if (! function_exists('password_hash')) |
|
| 77 | + if ( ! function_exists('password_hash')) |
|
| 78 | 78 | { |
| 79 | - require_once dirname(__FILE__) .'password.php'; |
|
| 79 | + require_once dirname(__FILE__).'password.php'; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if (empty($this->ci->session)) |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param bool $remember |
| 102 | 102 | * @return bool|mixed |
| 103 | 103 | */ |
| 104 | - public function login($credentials, $remember=false) |
|
| 104 | + public function login($credentials, $remember = false) |
|
| 105 | 105 | { |
| 106 | 106 | $user = $this->validate($credentials, true); |
| 107 | 107 | |
@@ -112,14 +112,14 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // If throttling time is above zero, we can't allow |
| 114 | 114 | // logins now. |
| 115 | - $time = (int)$this->isThrottled($user); |
|
| 115 | + $time = (int) $this->isThrottled($user); |
|
| 116 | 116 | if ($time > 0) |
| 117 | 117 | { |
| 118 | 118 | $this->error = sprintf(lang('auth.throttled'), $time); |
| 119 | 119 | return false; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if (! $user) |
|
| 122 | + if ( ! $user) |
|
| 123 | 123 | { |
| 124 | 124 | if (empty($this->error)) |
| 125 | 125 | { |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | * @param bool $return_user |
| 155 | 155 | * @return mixed |
| 156 | 156 | */ |
| 157 | - public function validate($credentials, $return_user=false) |
|
| 157 | + public function validate($credentials, $return_user = false) |
|
| 158 | 158 | { |
| 159 | 159 | // Get ip address |
| 160 | 160 | $ip_address = $this->ci->input->ip_address(); |
| 161 | 161 | |
| 162 | 162 | // We do not want to force case-sensitivity on things |
| 163 | 163 | // like username and email for usability sake. |
| 164 | - if (! empty($credentials['email'])) |
|
| 164 | + if ( ! empty($credentials['email'])) |
|
| 165 | 165 | { |
| 166 | 166 | $credentials['email'] = strtolower($credentials['email']); |
| 167 | 167 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Ensure that the fields are allowed validation fields |
| 189 | - if (! in_array(key($credentials), config_item('auth.valid_fields')) ) |
|
| 189 | + if ( ! in_array(key($credentials), config_item('auth.valid_fields'))) |
|
| 190 | 190 | { |
| 191 | 191 | $this->error = lang('auth.invalid_credentials'); |
| 192 | 192 | $this->ci->login_model->recordLoginAttempt($ip_address); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | ->where($credentials) |
| 199 | 199 | ->first(); |
| 200 | 200 | |
| 201 | - if (! $user) |
|
| 201 | + if ( ! $user) |
|
| 202 | 202 | { |
| 203 | 203 | $this->error = lang('auth.invalid_user'); |
| 204 | 204 | $this->ci->login_model->recordLoginAttempt($ip_address); |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Now, try matching the passwords. |
| 209 | - $result = password_verify($password, $user['password_hash']); |
|
| 209 | + $result = password_verify($password, $user['password_hash']); |
|
| 210 | 210 | |
| 211 | - if (! $result) |
|
| 211 | + if ( ! $result) |
|
| 212 | 212 | { |
| 213 | 213 | $this->error = lang('auth.invalid_password'); |
| 214 | 214 | $this->ci->login_model->recordLoginAttempt($ip_address, $user['id']); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | // This would be due to the hash algorithm or hash |
| 220 | 220 | // cost changing since the last time that a user |
| 221 | 221 | // logged in. |
| 222 | - if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')] )) |
|
| 222 | + if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')])) |
|
| 223 | 223 | { |
| 224 | 224 | $new_hash = Password::hashPassword($password); |
| 225 | 225 | $this->user_model->skip_validation() |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // Is the user active? |
| 231 | - if (! $user['active']) |
|
| 231 | + if ( ! $user['active']) |
|
| 232 | 232 | { |
| 233 | 233 | $this->error = lang('auth.inactive_account'); |
| 234 | 234 | return false; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | { |
| 249 | 249 | $this->ci->load->helper('cookie'); |
| 250 | 250 | |
| 251 | - if (! Events::trigger('beforeLogout', [$this->user])) |
|
| 251 | + if ( ! Events::trigger('beforeLogout', [$this->user])) |
|
| 252 | 252 | { |
| 253 | 253 | return false; |
| 254 | 254 | } |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | // available for flash messages, etc. |
| 258 | 258 | if (isset($_SESSION)) |
| 259 | 259 | { |
| 260 | - foreach ( $_SESSION as $key => $value ) |
|
| 260 | + foreach ($_SESSION as $key => $value) |
|
| 261 | 261 | { |
| 262 | - $_SESSION[ $key ] = NULL; |
|
| 263 | - unset( $_SESSION[ $key ] ); |
|
| 262 | + $_SESSION[$key] = NULL; |
|
| 263 | + unset($_SESSION[$key]); |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | // Also, regenerate the session ID for a touch of added safety. |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | { |
| 287 | 287 | $id = $this->ci->session->userdata('logged_in'); |
| 288 | 288 | |
| 289 | - if (! $id) |
|
| 289 | + if ( ! $id) |
|
| 290 | 290 | { |
| 291 | 291 | return false; |
| 292 | 292 | } |
@@ -294,10 +294,10 @@ discard block |
||
| 294 | 294 | // If the user var hasn't been filled in, we need to fill it in, |
| 295 | 295 | // since this method will typically be used as the only method |
| 296 | 296 | // to determine whether a user is logged in or not. |
| 297 | - if (! $this->user) |
|
| 297 | + if ( ! $this->user) |
|
| 298 | 298 | { |
| 299 | 299 | $this->user = $this->user_model->as_array() |
| 300 | - ->find_by('id', (int)$id); |
|
| 300 | + ->find_by('id', (int) $id); |
|
| 301 | 301 | |
| 302 | 302 | if (empty($this->user)) |
| 303 | 303 | { |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function viaRemember() |
| 323 | 323 | { |
| 324 | - if (! config_item('auth.allow_remembering')) |
|
| 324 | + if ( ! config_item('auth.allow_remembering')) |
|
| 325 | 325 | { |
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | $this->ci->load->helper('cookie'); |
| 330 | 330 | |
| 331 | - if (! $token = get_cookie('remember')) |
|
| 331 | + if ( ! $token = get_cookie('remember')) |
|
| 332 | 332 | { |
| 333 | 333 | return false; |
| 334 | 334 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $query = $this->ci->db->where('hash', $this->ci->login_model->hashRememberToken($token)) |
| 338 | 338 | ->get('auth_tokens'); |
| 339 | 339 | |
| 340 | - if (! $query->num_rows()) |
|
| 340 | + if ( ! $query->num_rows()) |
|
| 341 | 341 | { |
| 342 | 342 | return false; |
| 343 | 343 | } |
@@ -375,16 +375,16 @@ discard block |
||
| 375 | 375 | // If via email, we need to generate a hash |
| 376 | 376 | $this->ci->load->helper('string'); |
| 377 | 377 | $token = random_string('alnum', 24); |
| 378 | - $user_data['activate_hash'] = hash('sha1', config_item('auth.salt') . $token); |
|
| 378 | + $user_data['activate_hash'] = hash('sha1', config_item('auth.salt').$token); |
|
| 379 | 379 | |
| 380 | 380 | // Email should NOT be case sensitive. |
| 381 | - if (! empty($user_data['email'])) |
|
| 381 | + if ( ! empty($user_data['email'])) |
|
| 382 | 382 | { |
| 383 | 383 | $user_data['email'] = strtolower($user_data['email']); |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | // Save the user |
| 387 | - if (! $id = $this->user_model->insert($user_data)) |
|
| 387 | + if ( ! $id = $this->user_model->insert($user_data)) |
|
| 388 | 388 | { |
| 389 | 389 | $this->error = $this->user_model->error(); |
| 390 | 390 | return false; |
@@ -415,25 +415,25 @@ discard block |
||
| 415 | 415 | { |
| 416 | 416 | $post = [ |
| 417 | 417 | 'email' => $data['email'], |
| 418 | - 'activate_hash' => hash('sha1', config_item('auth.salt') . $data['code']) |
|
| 418 | + 'activate_hash' => hash('sha1', config_item('auth.salt').$data['code']) |
|
| 419 | 419 | ]; |
| 420 | 420 | |
| 421 | 421 | $user = $this->user_model->where($post) |
| 422 | 422 | ->first(); |
| 423 | 423 | |
| 424 | - if (! $user) { |
|
| 424 | + if ( ! $user) { |
|
| 425 | 425 | $this->error = $this->user_model->error() ? $this->user_model->error() : lang('auth.activate_no_user'); |
| 426 | 426 | |
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if (! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null])) |
|
| 430 | + if ( ! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null])) |
|
| 431 | 431 | { |
| 432 | 432 | $this->error = $this->user_model->error(); |
| 433 | 433 | return false; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - Events::trigger('didActivate', [(array)$user]); |
|
| 436 | + Events::trigger('didActivate', [(array) $user]); |
|
| 437 | 437 | |
| 438 | 438 | return true; |
| 439 | 439 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | */ |
| 449 | 449 | public function activateUserById($id) |
| 450 | 450 | { |
| 451 | - if (! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null])) |
|
| 451 | + if ( ! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null])) |
|
| 452 | 452 | { |
| 453 | 453 | $this->error = $this->user_model->error(); |
| 454 | 454 | return false; |
@@ -480,12 +480,12 @@ discard block |
||
| 480 | 480 | */ |
| 481 | 481 | public function id() |
| 482 | 482 | { |
| 483 | - if (! is_array($this->user) || empty($this->user['id'])) |
|
| 483 | + if ( ! is_array($this->user) || empty($this->user['id'])) |
|
| 484 | 484 | { |
| 485 | 485 | return null; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - return (int)$this->user['id']; |
|
| 488 | + return (int) $this->user['id']; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | //-------------------------------------------------------------------- |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | public function isThrottled($user) |
| 503 | 503 | { |
| 504 | 504 | // Not throttling? Get outta here! |
| 505 | - if (! config_item('auth.allow_throttling')) |
|
| 505 | + if ( ! config_item('auth.allow_throttling')) |
|
| 506 | 506 | { |
| 507 | 507 | return false; |
| 508 | 508 | } |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | { |
| 571 | 571 | $this->error = lang('auth.bruteBan_notice'); |
| 572 | 572 | |
| 573 | - $ban_time = 60 * 15; // 15 minutes |
|
| 573 | + $ban_time = 60 * 15; // 15 minutes |
|
| 574 | 574 | $_SESSION['bruteBan'] = time() + $ban_time; |
| 575 | 575 | return $ban_time; |
| 576 | 576 | } |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | // Is it a valid user? |
| 619 | 619 | $user = $this->user_model->find_by('email', $email); |
| 620 | 620 | |
| 621 | - if (! $user) |
|
| 621 | + if ( ! $user) |
|
| 622 | 622 | { |
| 623 | 623 | $this->error = lang('auth.invalid_email'); |
| 624 | 624 | return false; |
@@ -627,17 +627,17 @@ discard block |
||
| 627 | 627 | // Generate/store our codes |
| 628 | 628 | $this->ci->load->helper('string'); |
| 629 | 629 | $token = random_string('alnum', 24); |
| 630 | - $hash = hash('sha1', config_item('auth.salt') .$token); |
|
| 630 | + $hash = hash('sha1', config_item('auth.salt').$token); |
|
| 631 | 631 | |
| 632 | 632 | $result = $this->user_model->update($user->id, ['reset_hash' => $hash]); |
| 633 | 633 | |
| 634 | - if (! $result) |
|
| 634 | + if ( ! $result) |
|
| 635 | 635 | { |
| 636 | 636 | $this->error = $this->user_model->error(); |
| 637 | 637 | return false; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - Events::trigger('didRemindUser', [(array)$user, $token]); |
|
| 640 | + Events::trigger('didRemindUser', [(array) $user, $token]); |
|
| 641 | 641 | |
| 642 | 642 | return true; |
| 643 | 643 | } |
@@ -664,10 +664,10 @@ discard block |
||
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | // Generate a hash to match against the table. |
| 667 | - $reset_hash = hash('sha1', config_item('auth.salt') .$credentials['code']); |
|
| 667 | + $reset_hash = hash('sha1', config_item('auth.salt').$credentials['code']); |
|
| 668 | 668 | unset($credentials['code']); |
| 669 | 669 | |
| 670 | - if (! empty($credentials['email'])) |
|
| 670 | + if ( ! empty($credentials['email'])) |
|
| 671 | 671 | { |
| 672 | 672 | $credentials['email'] = strtolower($credentials['email']); |
| 673 | 673 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | |
| 680 | 680 | // If throttling time is above zero, we can't allow |
| 681 | 681 | // logins now. |
| 682 | - $time = (int)$this->isThrottled($user); |
|
| 682 | + $time = (int) $this->isThrottled($user); |
|
| 683 | 683 | if ($time > 0) |
| 684 | 684 | { |
| 685 | 685 | $this->error = sprintf(lang('auth.throttled'), $time); |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | // Get ip address |
| 690 | 690 | $ip_address = $this->ci->input->ip_address(); |
| 691 | 691 | |
| 692 | - if (! $user) |
|
| 692 | + if ( ! $user) |
|
| 693 | 693 | { |
| 694 | 694 | $this->error = lang('auth.reset_no_user'); |
| 695 | 695 | $this->ci->login_model->recordLoginAttempt($ip_address); |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | 'reset_hash' => null |
| 712 | 712 | ]; |
| 713 | 713 | |
| 714 | - if (! $this->user_model->update($user['id'], $data)) |
|
| 714 | + if ( ! $this->user_model->update($user['id'], $data)) |
|
| 715 | 715 | { |
| 716 | 716 | $this->error = $this->user_model->error(); |
| 717 | 717 | return false; |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | * @param null $message |
| 737 | 737 | * @return mixed |
| 738 | 738 | */ |
| 739 | - public function changeStatus($newStatus, $message=null) |
|
| 739 | + public function changeStatus($newStatus, $message = null) |
|
| 740 | 740 | { |
| 741 | 741 | // todo actually record new users status! |
| 742 | 742 | } |
@@ -753,14 +753,14 @@ discard block |
||
| 753 | 753 | * @param bool $allow_any_parent |
| 754 | 754 | * @return mixed |
| 755 | 755 | */ |
| 756 | - public function useModel($model, $allow_any_parent=false) |
|
| 756 | + public function useModel($model, $allow_any_parent = false) |
|
| 757 | 757 | { |
| 758 | - if (! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel') |
|
| 758 | + if ( ! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel') |
|
| 759 | 759 | { |
| 760 | 760 | throw new \RuntimeException('Models passed into LocalAuthenticate MUST extend Myth\Models\CIDbModel'); |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - $this->user_model =& $model; |
|
| 763 | + $this->user_model = & $model; |
|
| 764 | 764 | |
| 765 | 765 | return $this; |
| 766 | 766 | } |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | */ |
| 833 | 833 | protected function rememberUser($user) |
| 834 | 834 | { |
| 835 | - if (! config_item('auth.allow_remembering')) |
|
| 835 | + if ( ! config_item('auth.allow_remembering')) |
|
| 836 | 836 | { |
| 837 | 837 | log_message('debug', 'Auth library set to refuse "Remember Me" functionality.'); |
| 838 | 838 | return false; |
@@ -851,13 +851,13 @@ discard block |
||
| 851 | 851 | * @param null $token |
| 852 | 852 | * @return mixed |
| 853 | 853 | */ |
| 854 | - protected function refreshRememberCookie($user, $token=null) |
|
| 854 | + protected function refreshRememberCookie($user, $token = null) |
|
| 855 | 855 | { |
| 856 | 856 | $this->ci->load->helper('cookie'); |
| 857 | 857 | |
| 858 | 858 | // If a token is passed in, we know we're removing the |
| 859 | 859 | // old one. |
| 860 | - if (! empty($token)) |
|
| 860 | + if ( ! empty($token)) |
|
| 861 | 861 | { |
| 862 | 862 | $this->invalidateRememberCookie($user['email'], $token); |
| 863 | 863 | } |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | // Save the token to the database. |
| 868 | 868 | $data = [ |
| 869 | 869 | 'email' => $user['email'], |
| 870 | - 'hash' => sha1(config_item('auth.salt') . $new_token), |
|
| 870 | + 'hash' => sha1(config_item('auth.salt').$new_token), |
|
| 871 | 871 | 'created' => date('Y-m-d H:i:s') |
| 872 | 872 | ]; |
| 873 | 873 | |
@@ -875,13 +875,13 @@ discard block |
||
| 875 | 875 | |
| 876 | 876 | // Create the cookie |
| 877 | 877 | set_cookie( |
| 878 | - 'remember', // Cookie Name |
|
| 879 | - $new_token, // Value |
|
| 880 | - config_item('auth.remember_length'), // # Seconds until it expires |
|
| 878 | + 'remember', // Cookie Name |
|
| 879 | + $new_token, // Value |
|
| 880 | + config_item('auth.remember_length'), // # Seconds until it expires |
|
| 881 | 881 | config_item('cookie_domain'), |
| 882 | 882 | config_item('cookie_path'), |
| 883 | 883 | config_item('cookie_prefix'), |
| 884 | - false, // Only send over HTTPS? |
|
| 884 | + false, // Only send over HTTPS? |
|
| 885 | 885 | true // Hide from Javascript? |
| 886 | 886 | ); |
| 887 | 887 | |