GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( e54387...b62a26 )
by Lonnie
10s
created
system/libraries/Session/drivers/Session_memcached_driver.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -496,8 +496,7 @@
 block discarded – undo
496 496
 			if (empty($_SERVER['HTTP_REFERER']))
497 497
 			{
498 498
 				$this->referer = FALSE;
499
-			}
500
-			else
499
+			} else
501 500
 			{
502 501
 				$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
503 502
 				$own_host = parse_url(config_item('base_url'), PHP_URL_HOST);
Please login to merge, or discard this patch.
system/libraries/Cache/Cache.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -496,8 +496,7 @@
 block discarded – undo
496 496
 			if (empty($_SERVER['HTTP_REFERER']))
497 497
 			{
498 498
 				$this->referer = FALSE;
499
-			}
500
-			else
499
+			} else
501 500
 			{
502 501
 				$referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
503 502
 				$own_host = parse_url(config_item('base_url'), PHP_URL_HOST);
Please login to merge, or discard this patch.
myth/Auth/LocalAuthentication.php 4 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -253,8 +253,7 @@
 block discarded – undo
253 253
             {
254 254
                 $this->vars[$k] = $escape ? esc($v, $context, $this->escaper) : $v;
255 255
             }
256
-        }
257
-        else
256
+        } else
258 257
         {
259 258
             $this->vars[$name] = $escape ? esc($value, $context, $this->escaper) : $value;
260 259
         }
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
     /**
243 243
      * Logs a user out and removes all session information.
244 244
      *
245
-     * @return mixed
245
+     * @return false|null
246 246
      */
247 247
     public function logout()
248 248
     {
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
      * the passed in $email.
609 609
      *
610 610
      * @param $email
611
-     * @return mixed
611
+     * @return boolean
612 612
      */
613 613
     public function remindUser($email)
614 614
     {
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      * @param $credentials
654 654
      * @param $password
655 655
      * @param $passConfirm
656
-     * @return mixed
656
+     * @return boolean
657 657
      */
658 658
     public function resetPassword($credentials, $password, $passConfirm)
659 659
     {
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
      *
752 752
      * @param $model
753 753
      * @param bool $allow_any_parent
754
-     * @return mixed
754
+     * @return LocalAuthentication
755 755
      */
756 756
     public function useModel($model, $allow_any_parent=false)
757 757
     {
Please login to merge, or discard this patch.
Indentation   +908 added lines, -908 removed lines patch added patch discarded remove patch
@@ -52,915 +52,915 @@
 block discarded – undo
52 52
  */
53 53
 class LocalAuthentication implements AuthenticateInterface {
54 54
 
55
-    protected $ci;
56
-
57
-    protected $user = null;
58
-
59
-    public $user_model = null;
60
-
61
-    public $error = null;
62
-
63
-    //--------------------------------------------------------------------
64
-
65
-    public function __construct( $ci=null )
66
-    {
67
-        if ($ci)
68
-        {
69
-            $this->ci= $ci;
70
-        }
71
-        else
72
-        {
73
-            $this->ci =& get_instance();
74
-        }
75
-
76
-        // Get our compatibility password file loaded up.
77
-        if (! function_exists('password_hash'))
78
-        {
79
-            require_once dirname(__FILE__) .'password.php';
80
-        }
81
-
82
-        if (empty($this->ci->session))
83
-        {
84
-            $this->ci->load->library('session');
85
-        }
86
-
87
-        $this->ci->config->load('auth');
88
-        $this->ci->load->model('auth/login_model');
89
-        $this->ci->load->language('auth/auth');
90
-    }
91
-
92
-    //--------------------------------------------------------------------
93
-
94
-    /**
95
-     * Attempt to log a user into the system.
96
-     *
97
-     * $credentials is an array of key/value pairs needed to log the user in.
98
-     * This is often email/password, or username/password.
99
-     *
100
-     * @param array $credentials
101
-     * @param bool  $remember
102
-     * @return bool|mixed
103
-     */
104
-    public function login($credentials, $remember=false)
105
-    {
106
-        $user = $this->validate($credentials, true);
107
-
108
-        if (! $user)
109
-        {
110
-            $this->user = null;
111
-            return $user;
112
-        }       
113
-
114
-        $this->loginUser($user);
115
-
116
-        if ($remember)
117
-        {
118
-            $this->rememberUser($user);
119
-        }
120
-
121
-        Events::trigger('didLogin', [$user]);
122
-
123
-        return true;
124
-    }
125
-
126
-    //--------------------------------------------------------------------
127
-
128
-    /**
129
-     * Validates user login information without logging them in.
130
-     *
131
-     * $credentials is an array of key/value pairs needed to log the user in.
132
-     * This is often email/password, or username/password.
133
-     *
134
-     * @param $credentials
135
-     * @param bool $return_user
136
-     * @return mixed
137
-     */
138
-    public function validate($credentials, $return_user=false)
139
-    {
140
-        // Can't validate without a password.
141
-        if (empty($credentials['password']) || count($credentials) < 2)
142
-        {
143
-            return null;
144
-        }
145
-
146
-        $password = $credentials['password'];
147
-        unset($credentials['password']);
148
-
149
-        // We should only be allowed 1 single other credential to
150
-        // test against.
151
-        if (count($credentials) > 1)
152
-        {
153
-            $this->error = lang('auth.too_many_credentials');
154
-            return false;
155
-        }
156
-
157
-        // Ensure that the fields are allowed validation fields
158
-        if (! in_array(key($credentials), config_item('auth.valid_fields')) )
159
-        {
160
-            $this->error = lang('auth.invalid_credentials');
161
-            return false;
162
-        }
163
-
164
-        // We do not want to force case-sensitivity on things
165
-        // like username and email for usability sake.
166
-        if (! empty($credentials['email']))
167
-        {
168
-            $credentials['email'] = strtolower($credentials['email']);
169
-        }
170
-
171
-        // Can we find a user with those credentials?
172
-        $user = $this->user_model->as_array()
173
-                                 ->where($credentials)
174
-                                 ->first();
175
-
176
-        // If the user is throttled due to too many invalid logins
177
-        // or the system is under attack, kick them back.
178
-
179
-        // If throttling time is above zero, we can't allow
180
-        // logins now.
181
-        $time = (int)$this->isThrottled($user);
182
-        if ($time > 0)
183
-        {
184
-            $this->error = sprintf(lang('auth.throttled'), $time);
185
-            return false;
186
-        }
187
-
188
-        // Get ip address
189
-        $ip_address = $this->ci->input->ip_address();
190
-
191
-        if (! $user)
192
-        {
193
-            $this->error = lang('auth.invalid_user');
194
-            $this->ci->login_model->recordLoginAttempt($ip_address);
195
-            return false;
196
-        }
197
-
198
-        // Now, try matching the passwords.
199
-        $result =  password_verify($password, $user['password_hash']);
200
-
201
-        if (! $result)
202
-        {
203
-            $this->error = lang('auth.invalid_password');
204
-            $this->ci->login_model->recordLoginAttempt($ip_address, $user['id']);
205
-            return false;
206
-        }
207
-
208
-        // Check to see if the password needs to be rehashed.
209
-        // This would be due to the hash algorithm or hash
210
-        // cost changing since the last time that a user
211
-        // logged in.
212
-        if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')] ))
213
-        {
214
-            $new_hash = Password::hashPassword($password);
215
-            $this->user_model->skip_validation()
216
-                             ->update($user['id'], ['password_hash' => $new_hash]);
217
-            unset($new_hash);
218
-        }
219
-
220
-        // Is the user active?
221
-        if (! $user['active'])
222
-        {
223
-            $this->error = lang('auth.inactive_account');
224
-            return false;
225
-        }
226
-
227
-        return $return_user ? $user : true;
228
-    }
229
-
230
-    //--------------------------------------------------------------------
231
-
232
-    /**
233
-     * Logs a user out and removes all session information.
234
-     *
235
-     * @return mixed
236
-     */
237
-    public function logout()
238
-    {
239
-        $this->ci->load->helper('cookie');
240
-
241
-        if (! Events::trigger('beforeLogout', [$this->user]))
242
-        {
243
-            return false;
244
-        }
245
-
246
-        // Destroy the session data - but ensure a session is still
247
-        // available for flash messages, etc.
248
-        if (isset($_SESSION))
249
-        {
250
-            foreach ( $_SESSION as $key => $value )
251
-            {
252
-                $_SESSION[ $key ] = NULL;
253
-                unset( $_SESSION[ $key ] );
254
-            }
255
-        }
256
-        // Also, regenerate the session ID for a touch of added safety.
257
-        $this->ci->session->sess_regenerate(true);
258
-
259
-        // Take care of any rememberme functionality.
260
-        if (config_item('auth.allow_remembering'))
261
-        {
262
-            $token = get_cookie('remember');
263
-
264
-            $this->invalidateRememberCookie($this->user['email'], $token);
265
-        }
266
-    }
267
-
268
-    //--------------------------------------------------------------------
269
-
270
-    /**
271
-     * Checks whether a user is logged in or not.
272
-     *
273
-     * @return bool
274
-     */
275
-    public function isLoggedIn()
276
-    {
277
-        $id = $this->ci->session->userdata('logged_in');
278
-
279
-        if (! $id)
280
-        {
281
-            return false;
282
-        }
283
-
284
-        // If the user var hasn't been filled in, we need to fill it in,
285
-        // since this method will typically be used as the only method
286
-        // to determine whether a user is logged in or not.
287
-        if (! $this->user)
288
-        {
289
-            $this->user = $this->user_model->as_array()
290
-                                           ->find_by('id', (int)$id);
291
-
292
-            if (empty($this->user))
293
-            {
294
-                return false;
295
-            }
296
-        }
297
-
298
-        // If logged in, ensure cache control
299
-        // headers are in place
300
-        $this->setHeaders();
301
-
302
-        return true;
303
-    }
304
-
305
-    //--------------------------------------------------------------------
306
-
307
-    /**
308
-     * Attempts to log a user in based on the "remember me" cookie.
309
-     *
310
-     * @return bool
311
-     */
312
-    public function viaRemember()
313
-    {
314
-        if (! config_item('auth.allow_remembering'))
315
-        {
316
-            return false;
317
-        }
318
-
319
-        $this->ci->load->helper('cookie');
320
-
321
-        if (! $token = get_cookie('remember'))
322
-        {
323
-            return false;
324
-        }
325
-
326
-        // Attempt to match the token against our auth_tokens table.
327
-        $query = $this->ci->db->where('hash', $this->ci->login_model->hashRememberToken($token))
328
-                              ->get('auth_tokens');
329
-
330
-        if (! $query->num_rows())
331
-        {
332
-            return false;
333
-        }
334
-
335
-        // Grab the user
336
-        $email = $query->row()->email;
337
-
338
-        $user = $this->user_model->as_array()
339
-                                 ->find_by('email', $email);
340
-
341
-        $this->loginUser($user);
342
-
343
-        // We only want our remember me tokens to be valid
344
-        // for a single use.
345
-        $this->refreshRememberCookie($user, $token);
346
-
347
-        return true;
348
-    }
349
-
350
-    //--------------------------------------------------------------------
351
-
352
-    /**
353
-     * Registers a new user and handles activation method.
354
-     *
355
-     * @param $user_data
356
-     * @return bool
357
-     */
358
-    public function registerUser($user_data)
359
-    {
360
-        // Anything special needed for Activation?
361
-        $method = config_item('auth.activation_method');
362
-
363
-        $user_data['active'] = $method == 'auto' ? 1 : 0;
364
-
365
-        // If via email, we need to generate a hash
366
-        $this->ci->load->helper('string');
367
-        $token = random_string('alnum', 24);
368
-        $user_data['activate_hash'] = hash('sha1', config_item('auth.salt') . $token);
369
-
370
-        // Email should NOT be case sensitive.
371
-        if (! empty($user_data['email']))
372
-        {
373
-            $user_data['email'] = strtolower($user_data['email']);
374
-        }
375
-
376
-        // Save the user
377
-        if (! $id = $this->user_model->insert($user_data))
378
-        {
379
-            $this->error = $this->user_model->error();
380
-            return false;
381
-        }
382
-
383
-        $data = [
384
-            'user_id' => $id,
385
-            'email'   => $user_data['email'],
386
-            'token'   => $token,
387
-            'method'  => $method
388
-        ];
389
-
390
-        Events::trigger('didRegisterUser', [$data]);
391
-
392
-        return true;
393
-    }
394
-
395
-    //--------------------------------------------------------------------
396
-
397
-    /**
398
-     * Used to verify the user values and activate a user so they can
399
-     * visit the site.
400
-     *
401
-     * @param $data
402
-     * @return bool
403
-     */
404
-    public function activateUser($data)
405
-    {
406
-        $post = [
407
-            'email'         => $data['email'],
408
-            'activate_hash' => hash('sha1', config_item('auth.salt') . $data['code'])
409
-        ];
410
-
411
-        $user = $this->user_model->where($post)
412
-                                 ->first();
413
-
414
-        if (! $user) {
415
-            $this->error = $this->user_model->error() ? $this->user_model->error() : lang('auth.activate_no_user');
416
-
417
-            return false;
418
-        }
419
-
420
-        if (! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
421
-        {
422
-            $this->error = $this->user_model->error();
423
-            return false;
424
-        }
425
-
426
-        Events::trigger('didActivate', [(array)$user]);
427
-
428
-        return true;
429
-    }
430
-
431
-    //--------------------------------------------------------------------
432
-
433
-    /**
434
-     * Used to allow manual activation of a user with a known ID.
435
-     *
436
-     * @param $id
437
-     * @return bool
438
-     */
439
-    public function activateUserById($id)
440
-    {
441
-        if (! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
442
-        {
443
-            $this->error = $this->user_model->error();
444
-            return false;
445
-        }
446
-
447
-        Events::trigger('didActivate', [$this->user_model->as_array()->find($id)]);
448
-
449
-        return true;
450
-    }
451
-
452
-    //--------------------------------------------------------------------
453
-
454
-    /**
455
-     * Grabs the current user object. Returns NULL if nothing found.
456
-     *
457
-     * @return array|null
458
-     */
459
-    public function user()
460
-    {
461
-        return $this->user;
462
-    }
463
-
464
-    //--------------------------------------------------------------------
465
-
466
-    /**
467
-     * A convenience method to grab the current user's ID.
468
-     *
469
-     * @return int|null
470
-     */
471
-    public function id()
472
-    {
473
-        if (! is_array($this->user) || empty($this->user['id']))
474
-        {
475
-            return null;
476
-        }
477
-
478
-        return (int)$this->user['id'];
479
-    }
480
-
481
-    //--------------------------------------------------------------------
482
-
483
-    /**
484
-     * Checks to see if the user is currently being throttled.
485
-     *
486
-     *  - If they are NOT, will return FALSE.
487
-     *  - If they ARE, will return the number of seconds until they can try again.
488
-     *
489
-     * @param $user
490
-     * @return mixed
491
-     */
492
-    public function isThrottled($user)
493
-    {
494
-        // Not throttling? Get outta here!
495
-        if (! config_item('auth.allow_throttling'))
496
-        {
497
-            return false;
498
-        }
499
-
500
-        // Get user_id
501
-        $user_id = $user ? $user['id'] : null;
55
+	protected $ci;
56
+
57
+	protected $user = null;
58
+
59
+	public $user_model = null;
60
+
61
+	public $error = null;
62
+
63
+	//--------------------------------------------------------------------
64
+
65
+	public function __construct( $ci=null )
66
+	{
67
+		if ($ci)
68
+		{
69
+			$this->ci= $ci;
70
+		}
71
+		else
72
+		{
73
+			$this->ci =& get_instance();
74
+		}
75
+
76
+		// Get our compatibility password file loaded up.
77
+		if (! function_exists('password_hash'))
78
+		{
79
+			require_once dirname(__FILE__) .'password.php';
80
+		}
81
+
82
+		if (empty($this->ci->session))
83
+		{
84
+			$this->ci->load->library('session');
85
+		}
86
+
87
+		$this->ci->config->load('auth');
88
+		$this->ci->load->model('auth/login_model');
89
+		$this->ci->load->language('auth/auth');
90
+	}
91
+
92
+	//--------------------------------------------------------------------
93
+
94
+	/**
95
+	 * Attempt to log a user into the system.
96
+	 *
97
+	 * $credentials is an array of key/value pairs needed to log the user in.
98
+	 * This is often email/password, or username/password.
99
+	 *
100
+	 * @param array $credentials
101
+	 * @param bool  $remember
102
+	 * @return bool|mixed
103
+	 */
104
+	public function login($credentials, $remember=false)
105
+	{
106
+		$user = $this->validate($credentials, true);
107
+
108
+		if (! $user)
109
+		{
110
+			$this->user = null;
111
+			return $user;
112
+		}       
113
+
114
+		$this->loginUser($user);
115
+
116
+		if ($remember)
117
+		{
118
+			$this->rememberUser($user);
119
+		}
120
+
121
+		Events::trigger('didLogin', [$user]);
122
+
123
+		return true;
124
+	}
125
+
126
+	//--------------------------------------------------------------------
127
+
128
+	/**
129
+	 * Validates user login information without logging them in.
130
+	 *
131
+	 * $credentials is an array of key/value pairs needed to log the user in.
132
+	 * This is often email/password, or username/password.
133
+	 *
134
+	 * @param $credentials
135
+	 * @param bool $return_user
136
+	 * @return mixed
137
+	 */
138
+	public function validate($credentials, $return_user=false)
139
+	{
140
+		// Can't validate without a password.
141
+		if (empty($credentials['password']) || count($credentials) < 2)
142
+		{
143
+			return null;
144
+		}
145
+
146
+		$password = $credentials['password'];
147
+		unset($credentials['password']);
148
+
149
+		// We should only be allowed 1 single other credential to
150
+		// test against.
151
+		if (count($credentials) > 1)
152
+		{
153
+			$this->error = lang('auth.too_many_credentials');
154
+			return false;
155
+		}
156
+
157
+		// Ensure that the fields are allowed validation fields
158
+		if (! in_array(key($credentials), config_item('auth.valid_fields')) )
159
+		{
160
+			$this->error = lang('auth.invalid_credentials');
161
+			return false;
162
+		}
163
+
164
+		// We do not want to force case-sensitivity on things
165
+		// like username and email for usability sake.
166
+		if (! empty($credentials['email']))
167
+		{
168
+			$credentials['email'] = strtolower($credentials['email']);
169
+		}
170
+
171
+		// Can we find a user with those credentials?
172
+		$user = $this->user_model->as_array()
173
+								 ->where($credentials)
174
+								 ->first();
175
+
176
+		// If the user is throttled due to too many invalid logins
177
+		// or the system is under attack, kick them back.
178
+
179
+		// If throttling time is above zero, we can't allow
180
+		// logins now.
181
+		$time = (int)$this->isThrottled($user);
182
+		if ($time > 0)
183
+		{
184
+			$this->error = sprintf(lang('auth.throttled'), $time);
185
+			return false;
186
+		}
187
+
188
+		// Get ip address
189
+		$ip_address = $this->ci->input->ip_address();
190
+
191
+		if (! $user)
192
+		{
193
+			$this->error = lang('auth.invalid_user');
194
+			$this->ci->login_model->recordLoginAttempt($ip_address);
195
+			return false;
196
+		}
197
+
198
+		// Now, try matching the passwords.
199
+		$result =  password_verify($password, $user['password_hash']);
200
+
201
+		if (! $result)
202
+		{
203
+			$this->error = lang('auth.invalid_password');
204
+			$this->ci->login_model->recordLoginAttempt($ip_address, $user['id']);
205
+			return false;
206
+		}
207
+
208
+		// Check to see if the password needs to be rehashed.
209
+		// This would be due to the hash algorithm or hash
210
+		// cost changing since the last time that a user
211
+		// logged in.
212
+		if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')] ))
213
+		{
214
+			$new_hash = Password::hashPassword($password);
215
+			$this->user_model->skip_validation()
216
+							 ->update($user['id'], ['password_hash' => $new_hash]);
217
+			unset($new_hash);
218
+		}
219
+
220
+		// Is the user active?
221
+		if (! $user['active'])
222
+		{
223
+			$this->error = lang('auth.inactive_account');
224
+			return false;
225
+		}
226
+
227
+		return $return_user ? $user : true;
228
+	}
229
+
230
+	//--------------------------------------------------------------------
231
+
232
+	/**
233
+	 * Logs a user out and removes all session information.
234
+	 *
235
+	 * @return mixed
236
+	 */
237
+	public function logout()
238
+	{
239
+		$this->ci->load->helper('cookie');
240
+
241
+		if (! Events::trigger('beforeLogout', [$this->user]))
242
+		{
243
+			return false;
244
+		}
245
+
246
+		// Destroy the session data - but ensure a session is still
247
+		// available for flash messages, etc.
248
+		if (isset($_SESSION))
249
+		{
250
+			foreach ( $_SESSION as $key => $value )
251
+			{
252
+				$_SESSION[ $key ] = NULL;
253
+				unset( $_SESSION[ $key ] );
254
+			}
255
+		}
256
+		// Also, regenerate the session ID for a touch of added safety.
257
+		$this->ci->session->sess_regenerate(true);
258
+
259
+		// Take care of any rememberme functionality.
260
+		if (config_item('auth.allow_remembering'))
261
+		{
262
+			$token = get_cookie('remember');
263
+
264
+			$this->invalidateRememberCookie($this->user['email'], $token);
265
+		}
266
+	}
267
+
268
+	//--------------------------------------------------------------------
269
+
270
+	/**
271
+	 * Checks whether a user is logged in or not.
272
+	 *
273
+	 * @return bool
274
+	 */
275
+	public function isLoggedIn()
276
+	{
277
+		$id = $this->ci->session->userdata('logged_in');
278
+
279
+		if (! $id)
280
+		{
281
+			return false;
282
+		}
283
+
284
+		// If the user var hasn't been filled in, we need to fill it in,
285
+		// since this method will typically be used as the only method
286
+		// to determine whether a user is logged in or not.
287
+		if (! $this->user)
288
+		{
289
+			$this->user = $this->user_model->as_array()
290
+										   ->find_by('id', (int)$id);
291
+
292
+			if (empty($this->user))
293
+			{
294
+				return false;
295
+			}
296
+		}
297
+
298
+		// If logged in, ensure cache control
299
+		// headers are in place
300
+		$this->setHeaders();
301
+
302
+		return true;
303
+	}
304
+
305
+	//--------------------------------------------------------------------
306
+
307
+	/**
308
+	 * Attempts to log a user in based on the "remember me" cookie.
309
+	 *
310
+	 * @return bool
311
+	 */
312
+	public function viaRemember()
313
+	{
314
+		if (! config_item('auth.allow_remembering'))
315
+		{
316
+			return false;
317
+		}
318
+
319
+		$this->ci->load->helper('cookie');
320
+
321
+		if (! $token = get_cookie('remember'))
322
+		{
323
+			return false;
324
+		}
325
+
326
+		// Attempt to match the token against our auth_tokens table.
327
+		$query = $this->ci->db->where('hash', $this->ci->login_model->hashRememberToken($token))
328
+							  ->get('auth_tokens');
329
+
330
+		if (! $query->num_rows())
331
+		{
332
+			return false;
333
+		}
334
+
335
+		// Grab the user
336
+		$email = $query->row()->email;
337
+
338
+		$user = $this->user_model->as_array()
339
+								 ->find_by('email', $email);
340
+
341
+		$this->loginUser($user);
342
+
343
+		// We only want our remember me tokens to be valid
344
+		// for a single use.
345
+		$this->refreshRememberCookie($user, $token);
346
+
347
+		return true;
348
+	}
349
+
350
+	//--------------------------------------------------------------------
351
+
352
+	/**
353
+	 * Registers a new user and handles activation method.
354
+	 *
355
+	 * @param $user_data
356
+	 * @return bool
357
+	 */
358
+	public function registerUser($user_data)
359
+	{
360
+		// Anything special needed for Activation?
361
+		$method = config_item('auth.activation_method');
362
+
363
+		$user_data['active'] = $method == 'auto' ? 1 : 0;
364
+
365
+		// If via email, we need to generate a hash
366
+		$this->ci->load->helper('string');
367
+		$token = random_string('alnum', 24);
368
+		$user_data['activate_hash'] = hash('sha1', config_item('auth.salt') . $token);
369
+
370
+		// Email should NOT be case sensitive.
371
+		if (! empty($user_data['email']))
372
+		{
373
+			$user_data['email'] = strtolower($user_data['email']);
374
+		}
375
+
376
+		// Save the user
377
+		if (! $id = $this->user_model->insert($user_data))
378
+		{
379
+			$this->error = $this->user_model->error();
380
+			return false;
381
+		}
382
+
383
+		$data = [
384
+			'user_id' => $id,
385
+			'email'   => $user_data['email'],
386
+			'token'   => $token,
387
+			'method'  => $method
388
+		];
389
+
390
+		Events::trigger('didRegisterUser', [$data]);
391
+
392
+		return true;
393
+	}
394
+
395
+	//--------------------------------------------------------------------
396
+
397
+	/**
398
+	 * Used to verify the user values and activate a user so they can
399
+	 * visit the site.
400
+	 *
401
+	 * @param $data
402
+	 * @return bool
403
+	 */
404
+	public function activateUser($data)
405
+	{
406
+		$post = [
407
+			'email'         => $data['email'],
408
+			'activate_hash' => hash('sha1', config_item('auth.salt') . $data['code'])
409
+		];
410
+
411
+		$user = $this->user_model->where($post)
412
+								 ->first();
413
+
414
+		if (! $user) {
415
+			$this->error = $this->user_model->error() ? $this->user_model->error() : lang('auth.activate_no_user');
416
+
417
+			return false;
418
+		}
419
+
420
+		if (! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
421
+		{
422
+			$this->error = $this->user_model->error();
423
+			return false;
424
+		}
425
+
426
+		Events::trigger('didActivate', [(array)$user]);
427
+
428
+		return true;
429
+	}
430
+
431
+	//--------------------------------------------------------------------
432
+
433
+	/**
434
+	 * Used to allow manual activation of a user with a known ID.
435
+	 *
436
+	 * @param $id
437
+	 * @return bool
438
+	 */
439
+	public function activateUserById($id)
440
+	{
441
+		if (! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
442
+		{
443
+			$this->error = $this->user_model->error();
444
+			return false;
445
+		}
446
+
447
+		Events::trigger('didActivate', [$this->user_model->as_array()->find($id)]);
448
+
449
+		return true;
450
+	}
451
+
452
+	//--------------------------------------------------------------------
453
+
454
+	/**
455
+	 * Grabs the current user object. Returns NULL if nothing found.
456
+	 *
457
+	 * @return array|null
458
+	 */
459
+	public function user()
460
+	{
461
+		return $this->user;
462
+	}
463
+
464
+	//--------------------------------------------------------------------
465
+
466
+	/**
467
+	 * A convenience method to grab the current user's ID.
468
+	 *
469
+	 * @return int|null
470
+	 */
471
+	public function id()
472
+	{
473
+		if (! is_array($this->user) || empty($this->user['id']))
474
+		{
475
+			return null;
476
+		}
477
+
478
+		return (int)$this->user['id'];
479
+	}
480
+
481
+	//--------------------------------------------------------------------
482
+
483
+	/**
484
+	 * Checks to see if the user is currently being throttled.
485
+	 *
486
+	 *  - If they are NOT, will return FALSE.
487
+	 *  - If they ARE, will return the number of seconds until they can try again.
488
+	 *
489
+	 * @param $user
490
+	 * @return mixed
491
+	 */
492
+	public function isThrottled($user)
493
+	{
494
+		// Not throttling? Get outta here!
495
+		if (! config_item('auth.allow_throttling'))
496
+		{
497
+			return false;
498
+		}
499
+
500
+		// Get user_id
501
+		$user_id = $user ? $user['id'] : null;
502 502
         
503
-        // Get ip address
504
-        $ip_address = $this->ci->input->ip_address();
505
-
506
-        // Have any attempts been made?
507
-        $attempts = $this->ci->login_model->countLoginAttempts($ip_address, $user_id);
508
-
509
-        // Grab the amount of time to add if the system thinks we're
510
-        // under a distributed brute force attack.
511
-        // Affect users that have at least 1 failure login attempt
512
-        $dbrute_time = ($attempts === 0) ? 0 : $this->ci->login_model->distributedBruteForceTime();
513
-
514
-        // If this user was found to possibly be under a brute
515
-        // force attack, their account would have been banned
516
-        // for 15 minutes.
517
-        if ($time = isset($_SESSION['bruteBan']) ? $_SESSION['bruteBan'] : false)
518
-        {
519
-            // If the current time is less than the
520
-            // the ban expiration, plus any distributed time
521
-            // then the user can't login just yet.
522
-            if ($time + $dbrute_time > time())
523
-            {
524
-                // The user is banned still...
525
-                $this->error = lang('auth.bruteBan_notice');
526
-                return ($time + $dbrute_time) - time();
527
-            }
528
-
529
-            // Still here? The the ban time is over...
530
-            unset($_SESSION['bruteBan']);
531
-        }
532
-
533
-        // Grab the time of last attempt and
534
-        // determine if we're throttled by amount of time passed.
535
-        $last_time = $this->ci->login_model->lastLoginAttemptTime($ip_address, $user_id);
536
-
537
-        $allowed = config_item('auth.allowed_login_attempts');
538
-
539
-        // We're not throttling if there are 0 attempts or
540
-        // the number is less than or equal to the allowed free attempts
541
-        if ($attempts === 0 || $attempts < $allowed)
542
-        {
543
-            // Before we can say there's nothing up here,
544
-            // we need to check dbrute time.
545
-            $time_left = $last_time + $dbrute_time - time();
546
-
547
-            if ($time_left > 0)
548
-            {
549
-                return $time_left;
550
-            }
551
-
552
-            return false;
553
-        }
554
-
555
-        // If the number of attempts is excessive (above 100) we need
556
-        // to check the elapsed time of all of these attacks. If they are
557
-        // less than 1 minute it's obvious this is a brute force attack,
558
-        // so we'll set a session flag and block that user for 15 minutes.
559
-        if ($attempts > 100 && $this->ci->login_model->isBruteForced($ip_address, $user_id))
560
-        {
561
-            $this->error = lang('auth.bruteBan_notice');
562
-
563
-            $ban_time = 60 * 15;    // 15 minutes
564
-            $_SESSION['bruteBan'] = time() + $ban_time;
565
-            return $ban_time;
566
-        }
567
-
568
-        // Get our allowed attempts out of the picture.
569
-        $attempts = $attempts - $allowed;
570
-
571
-        $max_time = config_item('auth.max_throttle_time');
572
-
573
-        $add_time = 5 * pow(2, $attempts);
574
-
575
-        if ($add_time > $max_time)
576
-        {
577
-            $add_time = $max_time;
578
-        }
579
-
580
-        $next_time = $last_time + $add_time + $dbrute_time;
581
-
582
-        $current = time();
583
-
584
-        // We are NOT throttled if we are already
585
-        // past the allowed time.
586
-        if ($current > $next_time)
587
-        {
588
-            return false;
589
-        }
590
-
591
-        return $next_time - $current;
592
-    }
593
-
594
-    //--------------------------------------------------------------------
595
-
596
-    /**
597
-     * Sends a password reset link email to the user associated with
598
-     * the passed in $email.
599
-     *
600
-     * @param $email
601
-     * @return mixed
602
-     */
603
-    public function remindUser($email)
604
-    {
605
-        // Emails should NOT be case sensitive.
606
-        $email = strtolower($email);
607
-
608
-        // Is it a valid user?
609
-        $user = $this->user_model->find_by('email', $email);
610
-
611
-        if (! $user)
612
-        {
613
-            $this->error = lang('auth.invalid_email');
614
-            return false;
615
-        }
616
-
617
-        // Generate/store our codes
618
-        $this->ci->load->helper('string');
619
-        $token = random_string('alnum', 24);
620
-        $hash = hash('sha1', config_item('auth.salt') .$token);
621
-
622
-        $result = $this->user_model->update($user->id, ['reset_hash' => $hash]);
623
-
624
-        if (! $result)
625
-        {
626
-            $this->error = $this->user_model->error();
627
-            return false;
628
-        }
629
-
630
-        Events::trigger('didRemindUser', [(array)$user, $token]);
631
-
632
-        return true;
633
-    }
634
-
635
-    //--------------------------------------------------------------------
636
-
637
-    /**
638
-     * Validates the credentials provided and, if valid, resets the password.
639
-     *
640
-     * The $credentials array MUST contain a 'code' key with the string to
641
-     * hash and check against the reset_hash.
642
-     *
643
-     * @param $credentials
644
-     * @param $password
645
-     * @param $passConfirm
646
-     * @return mixed
647
-     */
648
-    public function resetPassword($credentials, $password, $passConfirm)
649
-    {
650
-        if (empty($credentials['code']))
651
-        {
652
-            $this->error = lang('auth.need_reset_code');
653
-            return false;
654
-        }
655
-
656
-        // Generate a hash to match against the table.
657
-        $reset_hash = hash('sha1', config_item('auth.salt') .$credentials['code']);
658
-        unset($credentials['code']);
659
-
660
-        if (! empty($credentials['email']))
661
-        {
662
-            $credentials['email'] = strtolower($credentials['email']);
663
-        }
664
-
665
-        // Is there a matching user?
666
-        $user = $this->user_model->as_array()
667
-                                 ->where($credentials)
668
-                                 ->first();
669
-
670
-        // If throttling time is above zero, we can't allow
671
-        // logins now.
672
-        $time = (int)$this->isThrottled($user);
673
-        if ($time > 0)
674
-        {
675
-            $this->error = sprintf(lang('auth.throttled'), $time);
676
-            return false;
677
-        }
678
-
679
-        // Get ip address
680
-        $ip_address = $this->ci->input->ip_address();
681
-
682
-        if (! $user)
683
-        {
684
-            $this->error = lang('auth.reset_no_user');
685
-            $this->ci->login_model->recordLoginAttempt($ip_address);
686
-            return false;
687
-        }
688
-
689
-        // Is generated reset_hash string matches one from the table?
690
-        if ($reset_hash !== $user['reset_hash'])
691
-        {
692
-            $this->error = lang('auth.reset_no_user');
693
-            $this->ci->login_model->recordLoginAttempt($ip_address, $user['id']);
694
-            return false;
695
-        }
696
-
697
-        // Update their password and reset their reset_hash
698
-        $data = [
699
-            'password'     => $password,
700
-            'pass_confirm' => $passConfirm,
701
-            'reset_hash'   => null
702
-        ];
703
-
704
-        if (! $this->user_model->update($user['id'], $data))
705
-        {
706
-            $this->error = $this->user_model->error();
707
-            return false;
708
-        }
709
-
710
-        // Clear our login attempts
711
-        $this->ci->login_model->purgeLoginAttempts($ip_address, $user['id']);
712
-
713
-        Events::trigger('didResetPassword', [$user]);
714
-
715
-        return true;
716
-    }
717
-
718
-    //--------------------------------------------------------------------
719
-
720
-    /**
721
-     * Provides a way for implementations to allow new statuses to be set
722
-     * on the user. The details will vary based upon implementation, but
723
-     * will often allow for banning or suspending users.
724
-     *
725
-     * @param $newStatus
726
-     * @param null $message
727
-     * @return mixed
728
-     */
729
-    public function changeStatus($newStatus, $message=null)
730
-    {
731
-        // todo actually record new users status!
732
-    }
733
-
734
-    //--------------------------------------------------------------------
735
-
736
-    /**
737
-     * Allows the consuming application to pass in a reference to the
738
-     * model that should be used.
739
-     *
740
-     * The model MUST extend Myth\Models\CIDbModel.
741
-     *
742
-     * @param $model
743
-     * @param bool $allow_any_parent
744
-     * @return mixed
745
-     */
746
-    public function useModel($model, $allow_any_parent=false)
747
-    {
748
-        if (! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
749
-        {
750
-            throw new \RuntimeException('Models passed into LocalAuthenticate MUST extend Myth\Models\CIDbModel');
751
-        }
752
-
753
-        $this->user_model =& $model;
754
-
755
-        return $this;
756
-    }
757
-
758
-    //--------------------------------------------------------------------
759
-
760
-    public function error()
761
-    {
762
-        if (validation_errors())
763
-        {
764
-            return validation_errors();
765
-        }
766
-
767
-        return $this->error;
768
-    }
769
-
770
-    //--------------------------------------------------------------------
771
-
772
-    //--------------------------------------------------------------------
773
-    // Login Records
774
-    //--------------------------------------------------------------------
775
-
776
-    /**
777
-     * Purges all login attempt records from the database.
778
-     *
779
-     * @param null $ip_address
780
-     * @param null $user_id
781
-     */
782
-    public function purgeLoginAttempts($ip_address = null, $user_id = null)
783
-    {
784
-        $this->ci->login_model->purgeLoginAttempts($ip_address, $user_id);
785
-
786
-        // @todo record activity of login attempts purge.
787
-        Events::trigger('didPurgeLoginAttempts', [$email]);
788
-    }
789
-
790
-    //--------------------------------------------------------------------
791
-
792
-    /**
793
-     * Purges all remember tokens for a single user. Effectively logs
794
-     * a user out of all devices. Intended to allow users to log themselves
795
-     * out of all devices as a security measure.
796
-     *
797
-     * @param $email
798
-     */
799
-    public function purgeRememberTokens($email)
800
-    {
801
-        // Emails should NOT be case sensitive.
802
-        $email = strtolower($email);
803
-
804
-        $this->ci->login_model->purgeRememberTokens($email);
805
-
806
-        // todo record activity of remember me purges.
807
-        Events::trigger('didPurgeRememberTokens', [$email]);
808
-    }
809
-
810
-    //--------------------------------------------------------------------
811
-
812
-    //--------------------------------------------------------------------
813
-    // Protected Methods
814
-    //--------------------------------------------------------------------
815
-
816
-    /**
817
-     * Check if Allow Persistent Login Cookies is enable
818
-     *
819
-     * @param $user
820
-     */
821
-    protected function rememberUser($user)
822
-    {
823
-        if (! config_item('auth.allow_remembering'))
824
-        {
825
-            log_message('debug', 'Auth library set to refuse "Remember Me" functionality.');
826
-            return false;
827
-        }
828
-
829
-        $this->refreshRememberCookie($user);
830
-    }
831
-
832
-    //--------------------------------------------------------------------
833
-
834
-    /**
835
-     * Invalidates the current rememberme cookie/database entry, creates
836
-     * a new one, stores it and returns the new value.
837
-     *
838
-     * @param $user
839
-     * @param null $token
840
-     * @return mixed
841
-     */
842
-    protected function refreshRememberCookie($user, $token=null)
843
-    {
844
-        $this->ci->load->helper('cookie');
845
-
846
-        // If a token is passed in, we know we're removing the
847
-        // old one.
848
-        if (! empty($token))
849
-        {
850
-            $this->invalidateRememberCookie($user['email'], $token);
851
-        }
852
-
853
-        $new_token = $this->ci->login_model->generateRememberToken($user);
854
-
855
-        // Save the token to the database.
856
-        $data = [
857
-            'email'   => $user['email'],
858
-            'hash'    => sha1(config_item('auth.salt') . $new_token),
859
-            'created' => date('Y-m-d H:i:s')
860
-        ];
861
-
862
-        $this->ci->db->insert('auth_tokens', $data);
863
-
864
-        // Create the cookie
865
-        set_cookie(
866
-            'remember',                             // Cookie Name
867
-            $new_token,                             // Value
868
-            config_item('auth.remember_length'),    // # Seconds until it expires
869
-            config_item('cookie_domain'),
870
-            config_item('cookie_path'),
871
-            config_item('cookie_prefix'),
872
-            false,                                  // Only send over HTTPS?
873
-            true                                    // Hide from Javascript?
874
-        );
875
-
876
-        return $new_token;
877
-    }
878
-
879
-    //--------------------------------------------------------------------
880
-
881
-    /**
882
-     * Deletes any current remember me cookies and database entries.
883
-     *
884
-     * @param $email
885
-     * @param $token
886
-     * @return string The new token (not the hash).
887
-     */
888
-    protected function invalidateRememberCookie($email, $token)
889
-    {
890
-        // Emails should NOT be case sensitive.
891
-        $email = strtolower($email);
892
-
893
-        // Remove from the database
894
-        $this->ci->login_model->deleteRememberToken($email, $token);
895
-
896
-        // Remove the cookie
897
-        delete_cookie(
898
-            'remember',
899
-            config_item('cookie_domain'),
900
-            config_item('cookie_path'),
901
-            config_item('cookie_prefix')
902
-        );
903
-    }
904
-
905
-    //--------------------------------------------------------------------
906
-
907
-    /**
908
-     * Handles the nitty gritty of actually logging our user into the system.
909
-     * Does NOT perform the authentication, just sets the system up so that
910
-     * it knows we're here.
911
-     *
912
-     * @param $user
913
-     */
914
-    protected function loginUser($user)
915
-    {
916
-        // Save the user for later access
917
-        $this->user = $user;
918
-
919
-        // Get ip address
920
-        $ip_address = $this->ci->input->ip_address();
921
-
922
-        // Regenerate the session ID to help protect
923
-        // against session fixation
924
-        $this->ci->session->sess_regenerate();
925
-
926
-        // Let the session know that we're logged in.
927
-        $this->ci->session->set_userdata('logged_in', $user['id']);
928
-
929
-        // Clear our login attempts
930
-        $this->ci->login_model->purgeLoginAttempts($ip_address, $user['id']);
931
-
932
-        // Record a new Login
933
-        $this->ci->login_model->recordLogin($user);
934
-
935
-        // If logged in, ensure cache control
936
-        // headers are in place
937
-        $this->setHeaders();
938
-
939
-        // We'll give a 20% chance to need to do a purge since we
940
-        // don't need to purge THAT often, it's just a maintenance issue.
941
-        // to keep the table from getting out of control.
942
-        if (mt_rand(1, 100) < 20)
943
-        {
944
-            $this->ci->login_model->purgeOldRememberTokens();
945
-        }
946
-    }
947
-
948
-    //--------------------------------------------------------------------
949
-
950
-    /**
951
-     * Sets the headers to ensure that pages are not cached when a user
952
-     * is logged in, helping to protect against logging out and then
953
-     * simply hitting the Back button on the browser and getting private
954
-     * information because the page was loaded from cache.
955
-     */
956
-    protected function setHeaders()
957
-    {
958
-        $this->ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
959
-        $this->ci->output->set_header('Cache-Control: post-check=0, pre-check=0');
960
-        $this->ci->output->set_header('Pragma: no-cache');
961
-    }
962
-
963
-    //--------------------------------------------------------------------
503
+		// Get ip address
504
+		$ip_address = $this->ci->input->ip_address();
505
+
506
+		// Have any attempts been made?
507
+		$attempts = $this->ci->login_model->countLoginAttempts($ip_address, $user_id);
508
+
509
+		// Grab the amount of time to add if the system thinks we're
510
+		// under a distributed brute force attack.
511
+		// Affect users that have at least 1 failure login attempt
512
+		$dbrute_time = ($attempts === 0) ? 0 : $this->ci->login_model->distributedBruteForceTime();
513
+
514
+		// If this user was found to possibly be under a brute
515
+		// force attack, their account would have been banned
516
+		// for 15 minutes.
517
+		if ($time = isset($_SESSION['bruteBan']) ? $_SESSION['bruteBan'] : false)
518
+		{
519
+			// If the current time is less than the
520
+			// the ban expiration, plus any distributed time
521
+			// then the user can't login just yet.
522
+			if ($time + $dbrute_time > time())
523
+			{
524
+				// The user is banned still...
525
+				$this->error = lang('auth.bruteBan_notice');
526
+				return ($time + $dbrute_time) - time();
527
+			}
528
+
529
+			// Still here? The the ban time is over...
530
+			unset($_SESSION['bruteBan']);
531
+		}
532
+
533
+		// Grab the time of last attempt and
534
+		// determine if we're throttled by amount of time passed.
535
+		$last_time = $this->ci->login_model->lastLoginAttemptTime($ip_address, $user_id);
536
+
537
+		$allowed = config_item('auth.allowed_login_attempts');
538
+
539
+		// We're not throttling if there are 0 attempts or
540
+		// the number is less than or equal to the allowed free attempts
541
+		if ($attempts === 0 || $attempts < $allowed)
542
+		{
543
+			// Before we can say there's nothing up here,
544
+			// we need to check dbrute time.
545
+			$time_left = $last_time + $dbrute_time - time();
546
+
547
+			if ($time_left > 0)
548
+			{
549
+				return $time_left;
550
+			}
551
+
552
+			return false;
553
+		}
554
+
555
+		// If the number of attempts is excessive (above 100) we need
556
+		// to check the elapsed time of all of these attacks. If they are
557
+		// less than 1 minute it's obvious this is a brute force attack,
558
+		// so we'll set a session flag and block that user for 15 minutes.
559
+		if ($attempts > 100 && $this->ci->login_model->isBruteForced($ip_address, $user_id))
560
+		{
561
+			$this->error = lang('auth.bruteBan_notice');
562
+
563
+			$ban_time = 60 * 15;    // 15 minutes
564
+			$_SESSION['bruteBan'] = time() + $ban_time;
565
+			return $ban_time;
566
+		}
567
+
568
+		// Get our allowed attempts out of the picture.
569
+		$attempts = $attempts - $allowed;
570
+
571
+		$max_time = config_item('auth.max_throttle_time');
572
+
573
+		$add_time = 5 * pow(2, $attempts);
574
+
575
+		if ($add_time > $max_time)
576
+		{
577
+			$add_time = $max_time;
578
+		}
579
+
580
+		$next_time = $last_time + $add_time + $dbrute_time;
581
+
582
+		$current = time();
583
+
584
+		// We are NOT throttled if we are already
585
+		// past the allowed time.
586
+		if ($current > $next_time)
587
+		{
588
+			return false;
589
+		}
590
+
591
+		return $next_time - $current;
592
+	}
593
+
594
+	//--------------------------------------------------------------------
595
+
596
+	/**
597
+	 * Sends a password reset link email to the user associated with
598
+	 * the passed in $email.
599
+	 *
600
+	 * @param $email
601
+	 * @return mixed
602
+	 */
603
+	public function remindUser($email)
604
+	{
605
+		// Emails should NOT be case sensitive.
606
+		$email = strtolower($email);
607
+
608
+		// Is it a valid user?
609
+		$user = $this->user_model->find_by('email', $email);
610
+
611
+		if (! $user)
612
+		{
613
+			$this->error = lang('auth.invalid_email');
614
+			return false;
615
+		}
616
+
617
+		// Generate/store our codes
618
+		$this->ci->load->helper('string');
619
+		$token = random_string('alnum', 24);
620
+		$hash = hash('sha1', config_item('auth.salt') .$token);
621
+
622
+		$result = $this->user_model->update($user->id, ['reset_hash' => $hash]);
623
+
624
+		if (! $result)
625
+		{
626
+			$this->error = $this->user_model->error();
627
+			return false;
628
+		}
629
+
630
+		Events::trigger('didRemindUser', [(array)$user, $token]);
631
+
632
+		return true;
633
+	}
634
+
635
+	//--------------------------------------------------------------------
636
+
637
+	/**
638
+	 * Validates the credentials provided and, if valid, resets the password.
639
+	 *
640
+	 * The $credentials array MUST contain a 'code' key with the string to
641
+	 * hash and check against the reset_hash.
642
+	 *
643
+	 * @param $credentials
644
+	 * @param $password
645
+	 * @param $passConfirm
646
+	 * @return mixed
647
+	 */
648
+	public function resetPassword($credentials, $password, $passConfirm)
649
+	{
650
+		if (empty($credentials['code']))
651
+		{
652
+			$this->error = lang('auth.need_reset_code');
653
+			return false;
654
+		}
655
+
656
+		// Generate a hash to match against the table.
657
+		$reset_hash = hash('sha1', config_item('auth.salt') .$credentials['code']);
658
+		unset($credentials['code']);
659
+
660
+		if (! empty($credentials['email']))
661
+		{
662
+			$credentials['email'] = strtolower($credentials['email']);
663
+		}
664
+
665
+		// Is there a matching user?
666
+		$user = $this->user_model->as_array()
667
+								 ->where($credentials)
668
+								 ->first();
669
+
670
+		// If throttling time is above zero, we can't allow
671
+		// logins now.
672
+		$time = (int)$this->isThrottled($user);
673
+		if ($time > 0)
674
+		{
675
+			$this->error = sprintf(lang('auth.throttled'), $time);
676
+			return false;
677
+		}
678
+
679
+		// Get ip address
680
+		$ip_address = $this->ci->input->ip_address();
681
+
682
+		if (! $user)
683
+		{
684
+			$this->error = lang('auth.reset_no_user');
685
+			$this->ci->login_model->recordLoginAttempt($ip_address);
686
+			return false;
687
+		}
688
+
689
+		// Is generated reset_hash string matches one from the table?
690
+		if ($reset_hash !== $user['reset_hash'])
691
+		{
692
+			$this->error = lang('auth.reset_no_user');
693
+			$this->ci->login_model->recordLoginAttempt($ip_address, $user['id']);
694
+			return false;
695
+		}
696
+
697
+		// Update their password and reset their reset_hash
698
+		$data = [
699
+			'password'     => $password,
700
+			'pass_confirm' => $passConfirm,
701
+			'reset_hash'   => null
702
+		];
703
+
704
+		if (! $this->user_model->update($user['id'], $data))
705
+		{
706
+			$this->error = $this->user_model->error();
707
+			return false;
708
+		}
709
+
710
+		// Clear our login attempts
711
+		$this->ci->login_model->purgeLoginAttempts($ip_address, $user['id']);
712
+
713
+		Events::trigger('didResetPassword', [$user]);
714
+
715
+		return true;
716
+	}
717
+
718
+	//--------------------------------------------------------------------
719
+
720
+	/**
721
+	 * Provides a way for implementations to allow new statuses to be set
722
+	 * on the user. The details will vary based upon implementation, but
723
+	 * will often allow for banning or suspending users.
724
+	 *
725
+	 * @param $newStatus
726
+	 * @param null $message
727
+	 * @return mixed
728
+	 */
729
+	public function changeStatus($newStatus, $message=null)
730
+	{
731
+		// todo actually record new users status!
732
+	}
733
+
734
+	//--------------------------------------------------------------------
735
+
736
+	/**
737
+	 * Allows the consuming application to pass in a reference to the
738
+	 * model that should be used.
739
+	 *
740
+	 * The model MUST extend Myth\Models\CIDbModel.
741
+	 *
742
+	 * @param $model
743
+	 * @param bool $allow_any_parent
744
+	 * @return mixed
745
+	 */
746
+	public function useModel($model, $allow_any_parent=false)
747
+	{
748
+		if (! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
749
+		{
750
+			throw new \RuntimeException('Models passed into LocalAuthenticate MUST extend Myth\Models\CIDbModel');
751
+		}
752
+
753
+		$this->user_model =& $model;
754
+
755
+		return $this;
756
+	}
757
+
758
+	//--------------------------------------------------------------------
759
+
760
+	public function error()
761
+	{
762
+		if (validation_errors())
763
+		{
764
+			return validation_errors();
765
+		}
766
+
767
+		return $this->error;
768
+	}
769
+
770
+	//--------------------------------------------------------------------
771
+
772
+	//--------------------------------------------------------------------
773
+	// Login Records
774
+	//--------------------------------------------------------------------
775
+
776
+	/**
777
+	 * Purges all login attempt records from the database.
778
+	 *
779
+	 * @param null $ip_address
780
+	 * @param null $user_id
781
+	 */
782
+	public function purgeLoginAttempts($ip_address = null, $user_id = null)
783
+	{
784
+		$this->ci->login_model->purgeLoginAttempts($ip_address, $user_id);
785
+
786
+		// @todo record activity of login attempts purge.
787
+		Events::trigger('didPurgeLoginAttempts', [$email]);
788
+	}
789
+
790
+	//--------------------------------------------------------------------
791
+
792
+	/**
793
+	 * Purges all remember tokens for a single user. Effectively logs
794
+	 * a user out of all devices. Intended to allow users to log themselves
795
+	 * out of all devices as a security measure.
796
+	 *
797
+	 * @param $email
798
+	 */
799
+	public function purgeRememberTokens($email)
800
+	{
801
+		// Emails should NOT be case sensitive.
802
+		$email = strtolower($email);
803
+
804
+		$this->ci->login_model->purgeRememberTokens($email);
805
+
806
+		// todo record activity of remember me purges.
807
+		Events::trigger('didPurgeRememberTokens', [$email]);
808
+	}
809
+
810
+	//--------------------------------------------------------------------
811
+
812
+	//--------------------------------------------------------------------
813
+	// Protected Methods
814
+	//--------------------------------------------------------------------
815
+
816
+	/**
817
+	 * Check if Allow Persistent Login Cookies is enable
818
+	 *
819
+	 * @param $user
820
+	 */
821
+	protected function rememberUser($user)
822
+	{
823
+		if (! config_item('auth.allow_remembering'))
824
+		{
825
+			log_message('debug', 'Auth library set to refuse "Remember Me" functionality.');
826
+			return false;
827
+		}
828
+
829
+		$this->refreshRememberCookie($user);
830
+	}
831
+
832
+	//--------------------------------------------------------------------
833
+
834
+	/**
835
+	 * Invalidates the current rememberme cookie/database entry, creates
836
+	 * a new one, stores it and returns the new value.
837
+	 *
838
+	 * @param $user
839
+	 * @param null $token
840
+	 * @return mixed
841
+	 */
842
+	protected function refreshRememberCookie($user, $token=null)
843
+	{
844
+		$this->ci->load->helper('cookie');
845
+
846
+		// If a token is passed in, we know we're removing the
847
+		// old one.
848
+		if (! empty($token))
849
+		{
850
+			$this->invalidateRememberCookie($user['email'], $token);
851
+		}
852
+
853
+		$new_token = $this->ci->login_model->generateRememberToken($user);
854
+
855
+		// Save the token to the database.
856
+		$data = [
857
+			'email'   => $user['email'],
858
+			'hash'    => sha1(config_item('auth.salt') . $new_token),
859
+			'created' => date('Y-m-d H:i:s')
860
+		];
861
+
862
+		$this->ci->db->insert('auth_tokens', $data);
863
+
864
+		// Create the cookie
865
+		set_cookie(
866
+			'remember',                             // Cookie Name
867
+			$new_token,                             // Value
868
+			config_item('auth.remember_length'),    // # Seconds until it expires
869
+			config_item('cookie_domain'),
870
+			config_item('cookie_path'),
871
+			config_item('cookie_prefix'),
872
+			false,                                  // Only send over HTTPS?
873
+			true                                    // Hide from Javascript?
874
+		);
875
+
876
+		return $new_token;
877
+	}
878
+
879
+	//--------------------------------------------------------------------
880
+
881
+	/**
882
+	 * Deletes any current remember me cookies and database entries.
883
+	 *
884
+	 * @param $email
885
+	 * @param $token
886
+	 * @return string The new token (not the hash).
887
+	 */
888
+	protected function invalidateRememberCookie($email, $token)
889
+	{
890
+		// Emails should NOT be case sensitive.
891
+		$email = strtolower($email);
892
+
893
+		// Remove from the database
894
+		$this->ci->login_model->deleteRememberToken($email, $token);
895
+
896
+		// Remove the cookie
897
+		delete_cookie(
898
+			'remember',
899
+			config_item('cookie_domain'),
900
+			config_item('cookie_path'),
901
+			config_item('cookie_prefix')
902
+		);
903
+	}
904
+
905
+	//--------------------------------------------------------------------
906
+
907
+	/**
908
+	 * Handles the nitty gritty of actually logging our user into the system.
909
+	 * Does NOT perform the authentication, just sets the system up so that
910
+	 * it knows we're here.
911
+	 *
912
+	 * @param $user
913
+	 */
914
+	protected function loginUser($user)
915
+	{
916
+		// Save the user for later access
917
+		$this->user = $user;
918
+
919
+		// Get ip address
920
+		$ip_address = $this->ci->input->ip_address();
921
+
922
+		// Regenerate the session ID to help protect
923
+		// against session fixation
924
+		$this->ci->session->sess_regenerate();
925
+
926
+		// Let the session know that we're logged in.
927
+		$this->ci->session->set_userdata('logged_in', $user['id']);
928
+
929
+		// Clear our login attempts
930
+		$this->ci->login_model->purgeLoginAttempts($ip_address, $user['id']);
931
+
932
+		// Record a new Login
933
+		$this->ci->login_model->recordLogin($user);
934
+
935
+		// If logged in, ensure cache control
936
+		// headers are in place
937
+		$this->setHeaders();
938
+
939
+		// We'll give a 20% chance to need to do a purge since we
940
+		// don't need to purge THAT often, it's just a maintenance issue.
941
+		// to keep the table from getting out of control.
942
+		if (mt_rand(1, 100) < 20)
943
+		{
944
+			$this->ci->login_model->purgeOldRememberTokens();
945
+		}
946
+	}
947
+
948
+	//--------------------------------------------------------------------
949
+
950
+	/**
951
+	 * Sets the headers to ensure that pages are not cached when a user
952
+	 * is logged in, helping to protect against logging out and then
953
+	 * simply hitting the Back button on the browser and getting private
954
+	 * information because the page was loaded from cache.
955
+	 */
956
+	protected function setHeaders()
957
+	{
958
+		$this->ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
959
+		$this->ci->output->set_header('Cache-Control: post-check=0, pre-check=0');
960
+		$this->ci->output->set_header('Pragma: no-cache');
961
+	}
962
+
963
+	//--------------------------------------------------------------------
964 964
 
965 965
 
966 966
 }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -62,21 +62,21 @@  discard block
 block discarded – undo
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,11 +101,11 @@  discard block
 block discarded – undo
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
 
108
-        if (! $user)
108
+        if ( ! $user)
109 109
         {
110 110
             $this->user = null;
111 111
             return $user;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * @param bool $return_user
136 136
      * @return mixed
137 137
      */
138
-    public function validate($credentials, $return_user=false)
138
+    public function validate($credentials, $return_user = false)
139 139
     {
140 140
         // Can't validate without a password.
141 141
         if (empty($credentials['password']) || count($credentials) < 2)
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Ensure that the fields are allowed validation fields
158
-        if (! in_array(key($credentials), config_item('auth.valid_fields')) )
158
+        if ( ! in_array(key($credentials), config_item('auth.valid_fields')))
159 159
         {
160 160
             $this->error = lang('auth.invalid_credentials');
161 161
             return false;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 
164 164
         // We do not want to force case-sensitivity on things
165 165
         // like username and email for usability sake.
166
-        if (! empty($credentials['email']))
166
+        if ( ! empty($credentials['email']))
167 167
         {
168 168
             $credentials['email'] = strtolower($credentials['email']);
169 169
         }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 
179 179
         // If throttling time is above zero, we can't allow
180 180
         // logins now.
181
-        $time = (int)$this->isThrottled($user);
181
+        $time = (int) $this->isThrottled($user);
182 182
         if ($time > 0)
183 183
         {
184 184
             $this->error = sprintf(lang('auth.throttled'), $time);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         // Get ip address
189 189
         $ip_address = $this->ci->input->ip_address();
190 190
 
191
-        if (! $user)
191
+        if ( ! $user)
192 192
         {
193 193
             $this->error = lang('auth.invalid_user');
194 194
             $this->ci->login_model->recordLoginAttempt($ip_address);
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
         }
197 197
 
198 198
         // Now, try matching the passwords.
199
-        $result =  password_verify($password, $user['password_hash']);
199
+        $result = password_verify($password, $user['password_hash']);
200 200
 
201
-        if (! $result)
201
+        if ( ! $result)
202 202
         {
203 203
             $this->error = lang('auth.invalid_password');
204 204
             $this->ci->login_model->recordLoginAttempt($ip_address, $user['id']);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         // This would be due to the hash algorithm or hash
210 210
         // cost changing since the last time that a user
211 211
         // logged in.
212
-        if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')] ))
212
+        if (password_needs_rehash($user['password_hash'], PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]))
213 213
         {
214 214
             $new_hash = Password::hashPassword($password);
215 215
             $this->user_model->skip_validation()
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
 
220 220
         // Is the user active?
221
-        if (! $user['active'])
221
+        if ( ! $user['active'])
222 222
         {
223 223
             $this->error = lang('auth.inactive_account');
224 224
             return false;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     {
239 239
         $this->ci->load->helper('cookie');
240 240
 
241
-        if (! Events::trigger('beforeLogout', [$this->user]))
241
+        if ( ! Events::trigger('beforeLogout', [$this->user]))
242 242
         {
243 243
             return false;
244 244
         }
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
         // available for flash messages, etc.
248 248
         if (isset($_SESSION))
249 249
         {
250
-            foreach ( $_SESSION as $key => $value )
250
+            foreach ($_SESSION as $key => $value)
251 251
             {
252
-                $_SESSION[ $key ] = NULL;
253
-                unset( $_SESSION[ $key ] );
252
+                $_SESSION[$key] = NULL;
253
+                unset($_SESSION[$key]);
254 254
             }
255 255
         }
256 256
         // Also, regenerate the session ID for a touch of added safety.
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     {
277 277
         $id = $this->ci->session->userdata('logged_in');
278 278
 
279
-        if (! $id)
279
+        if ( ! $id)
280 280
         {
281 281
             return false;
282 282
         }
@@ -284,10 +284,10 @@  discard block
 block discarded – undo
284 284
         // If the user var hasn't been filled in, we need to fill it in,
285 285
         // since this method will typically be used as the only method
286 286
         // to determine whether a user is logged in or not.
287
-        if (! $this->user)
287
+        if ( ! $this->user)
288 288
         {
289 289
             $this->user = $this->user_model->as_array()
290
-                                           ->find_by('id', (int)$id);
290
+                                           ->find_by('id', (int) $id);
291 291
 
292 292
             if (empty($this->user))
293 293
             {
@@ -311,14 +311,14 @@  discard block
 block discarded – undo
311 311
      */
312 312
     public function viaRemember()
313 313
     {
314
-        if (! config_item('auth.allow_remembering'))
314
+        if ( ! config_item('auth.allow_remembering'))
315 315
         {
316 316
             return false;
317 317
         }
318 318
 
319 319
         $this->ci->load->helper('cookie');
320 320
 
321
-        if (! $token = get_cookie('remember'))
321
+        if ( ! $token = get_cookie('remember'))
322 322
         {
323 323
             return false;
324 324
         }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         $query = $this->ci->db->where('hash', $this->ci->login_model->hashRememberToken($token))
328 328
                               ->get('auth_tokens');
329 329
 
330
-        if (! $query->num_rows())
330
+        if ( ! $query->num_rows())
331 331
         {
332 332
             return false;
333 333
         }
@@ -365,16 +365,16 @@  discard block
 block discarded – undo
365 365
         // If via email, we need to generate a hash
366 366
         $this->ci->load->helper('string');
367 367
         $token = random_string('alnum', 24);
368
-        $user_data['activate_hash'] = hash('sha1', config_item('auth.salt') . $token);
368
+        $user_data['activate_hash'] = hash('sha1', config_item('auth.salt').$token);
369 369
 
370 370
         // Email should NOT be case sensitive.
371
-        if (! empty($user_data['email']))
371
+        if ( ! empty($user_data['email']))
372 372
         {
373 373
             $user_data['email'] = strtolower($user_data['email']);
374 374
         }
375 375
 
376 376
         // Save the user
377
-        if (! $id = $this->user_model->insert($user_data))
377
+        if ( ! $id = $this->user_model->insert($user_data))
378 378
         {
379 379
             $this->error = $this->user_model->error();
380 380
             return false;
@@ -405,25 +405,25 @@  discard block
 block discarded – undo
405 405
     {
406 406
         $post = [
407 407
             'email'         => $data['email'],
408
-            'activate_hash' => hash('sha1', config_item('auth.salt') . $data['code'])
408
+            'activate_hash' => hash('sha1', config_item('auth.salt').$data['code'])
409 409
         ];
410 410
 
411 411
         $user = $this->user_model->where($post)
412 412
                                  ->first();
413 413
 
414
-        if (! $user) {
414
+        if ( ! $user) {
415 415
             $this->error = $this->user_model->error() ? $this->user_model->error() : lang('auth.activate_no_user');
416 416
 
417 417
             return false;
418 418
         }
419 419
 
420
-        if (! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
420
+        if ( ! $this->user_model->update($user->id, ['active' => 1, 'activate_hash' => null]))
421 421
         {
422 422
             $this->error = $this->user_model->error();
423 423
             return false;
424 424
         }
425 425
 
426
-        Events::trigger('didActivate', [(array)$user]);
426
+        Events::trigger('didActivate', [(array) $user]);
427 427
 
428 428
         return true;
429 429
     }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
      */
439 439
     public function activateUserById($id)
440 440
     {
441
-        if (! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
441
+        if ( ! $this->user_model->update($id, ['active' => 1, 'activate_hash' => null]))
442 442
         {
443 443
             $this->error = $this->user_model->error();
444 444
             return false;
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
      */
471 471
     public function id()
472 472
     {
473
-        if (! is_array($this->user) || empty($this->user['id']))
473
+        if ( ! is_array($this->user) || empty($this->user['id']))
474 474
         {
475 475
             return null;
476 476
         }
477 477
 
478
-        return (int)$this->user['id'];
478
+        return (int) $this->user['id'];
479 479
     }
480 480
 
481 481
     //--------------------------------------------------------------------
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
     public function isThrottled($user)
493 493
     {
494 494
         // Not throttling? Get outta here!
495
-        if (! config_item('auth.allow_throttling'))
495
+        if ( ! config_item('auth.allow_throttling'))
496 496
         {
497 497
             return false;
498 498
         }
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         {
561 561
             $this->error = lang('auth.bruteBan_notice');
562 562
 
563
-            $ban_time = 60 * 15;    // 15 minutes
563
+            $ban_time = 60 * 15; // 15 minutes
564 564
             $_SESSION['bruteBan'] = time() + $ban_time;
565 565
             return $ban_time;
566 566
         }
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
         // Is it a valid user?
609 609
         $user = $this->user_model->find_by('email', $email);
610 610
 
611
-        if (! $user)
611
+        if ( ! $user)
612 612
         {
613 613
             $this->error = lang('auth.invalid_email');
614 614
             return false;
@@ -617,17 +617,17 @@  discard block
 block discarded – undo
617 617
         // Generate/store our codes
618 618
         $this->ci->load->helper('string');
619 619
         $token = random_string('alnum', 24);
620
-        $hash = hash('sha1', config_item('auth.salt') .$token);
620
+        $hash = hash('sha1', config_item('auth.salt').$token);
621 621
 
622 622
         $result = $this->user_model->update($user->id, ['reset_hash' => $hash]);
623 623
 
624
-        if (! $result)
624
+        if ( ! $result)
625 625
         {
626 626
             $this->error = $this->user_model->error();
627 627
             return false;
628 628
         }
629 629
 
630
-        Events::trigger('didRemindUser', [(array)$user, $token]);
630
+        Events::trigger('didRemindUser', [(array) $user, $token]);
631 631
 
632 632
         return true;
633 633
     }
@@ -654,10 +654,10 @@  discard block
 block discarded – undo
654 654
         }
655 655
 
656 656
         // Generate a hash to match against the table.
657
-        $reset_hash = hash('sha1', config_item('auth.salt') .$credentials['code']);
657
+        $reset_hash = hash('sha1', config_item('auth.salt').$credentials['code']);
658 658
         unset($credentials['code']);
659 659
 
660
-        if (! empty($credentials['email']))
660
+        if ( ! empty($credentials['email']))
661 661
         {
662 662
             $credentials['email'] = strtolower($credentials['email']);
663 663
         }
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 
670 670
         // If throttling time is above zero, we can't allow
671 671
         // logins now.
672
-        $time = (int)$this->isThrottled($user);
672
+        $time = (int) $this->isThrottled($user);
673 673
         if ($time > 0)
674 674
         {
675 675
             $this->error = sprintf(lang('auth.throttled'), $time);
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
         // Get ip address
680 680
         $ip_address = $this->ci->input->ip_address();
681 681
 
682
-        if (! $user)
682
+        if ( ! $user)
683 683
         {
684 684
             $this->error = lang('auth.reset_no_user');
685 685
             $this->ci->login_model->recordLoginAttempt($ip_address);
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
             'reset_hash'   => null
702 702
         ];
703 703
 
704
-        if (! $this->user_model->update($user['id'], $data))
704
+        if ( ! $this->user_model->update($user['id'], $data))
705 705
         {
706 706
             $this->error = $this->user_model->error();
707 707
             return false;
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
      * @param null $message
727 727
      * @return mixed
728 728
      */
729
-    public function changeStatus($newStatus, $message=null)
729
+    public function changeStatus($newStatus, $message = null)
730 730
     {
731 731
         // todo actually record new users status!
732 732
     }
@@ -743,14 +743,14 @@  discard block
 block discarded – undo
743 743
      * @param bool $allow_any_parent
744 744
      * @return mixed
745 745
      */
746
-    public function useModel($model, $allow_any_parent=false)
746
+    public function useModel($model, $allow_any_parent = false)
747 747
     {
748
-        if (! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
748
+        if ( ! $allow_any_parent && get_parent_class($model) != 'Myth\Models\CIDbModel')
749 749
         {
750 750
             throw new \RuntimeException('Models passed into LocalAuthenticate MUST extend Myth\Models\CIDbModel');
751 751
         }
752 752
 
753
-        $this->user_model =& $model;
753
+        $this->user_model = & $model;
754 754
 
755 755
         return $this;
756 756
     }
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
      */
821 821
     protected function rememberUser($user)
822 822
     {
823
-        if (! config_item('auth.allow_remembering'))
823
+        if ( ! config_item('auth.allow_remembering'))
824 824
         {
825 825
             log_message('debug', 'Auth library set to refuse "Remember Me" functionality.');
826 826
             return false;
@@ -839,13 +839,13 @@  discard block
 block discarded – undo
839 839
      * @param null $token
840 840
      * @return mixed
841 841
      */
842
-    protected function refreshRememberCookie($user, $token=null)
842
+    protected function refreshRememberCookie($user, $token = null)
843 843
     {
844 844
         $this->ci->load->helper('cookie');
845 845
 
846 846
         // If a token is passed in, we know we're removing the
847 847
         // old one.
848
-        if (! empty($token))
848
+        if ( ! empty($token))
849 849
         {
850 850
             $this->invalidateRememberCookie($user['email'], $token);
851 851
         }
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
         // Save the token to the database.
856 856
         $data = [
857 857
             'email'   => $user['email'],
858
-            'hash'    => sha1(config_item('auth.salt') . $new_token),
858
+            'hash'    => sha1(config_item('auth.salt').$new_token),
859 859
             'created' => date('Y-m-d H:i:s')
860 860
         ];
861 861
 
@@ -863,13 +863,13 @@  discard block
 block discarded – undo
863 863
 
864 864
         // Create the cookie
865 865
         set_cookie(
866
-            'remember',                             // Cookie Name
867
-            $new_token,                             // Value
868
-            config_item('auth.remember_length'),    // # Seconds until it expires
866
+            'remember', // Cookie Name
867
+            $new_token, // Value
868
+            config_item('auth.remember_length'), // # Seconds until it expires
869 869
             config_item('cookie_domain'),
870 870
             config_item('cookie_path'),
871 871
             config_item('cookie_prefix'),
872
-            false,                                  // Only send over HTTPS?
872
+            false, // Only send over HTTPS?
873 873
             true                                    // Hide from Javascript?
874 874
         );
875 875
 
Please login to merge, or discard this patch.
application/config/auth.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
  * @link        http://sprintphp.com
30 30
  * @since       Version 1.0
31 31
  */
32
-if (!defined('BASEPATH')) exit('No direct script access allowed');
32
+if ( ! defined('BASEPATH')) exit('No direct script access allowed');
33 33
 
34 34
 use \Myth\Events\Events as Events;
35 35
 use Myth\Mail\Mail as Mail;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@
 block discarded – undo
29 29
  * @link        http://sprintphp.com
30 30
  * @since       Version 1.0
31 31
  */
32
-if (!defined('BASEPATH')) exit('No direct script access allowed');
32
+if (!defined('BASEPATH')) {
33
+	exit('No direct script access allowed');
34
+}
33 35
 
34 36
 //--------------------------------------------------------------------
35 37
 // Allowed Environments
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 // you might not want the extra risk associated with this cookie-based
77 77
 // solution.
78 78
 //
79
-    $config['auth.allow_remembering'] = true;
79
+	$config['auth.allow_remembering'] = true;
80 80
 
81 81
 //--------------------------------------------------------------------
82 82
 // Remember Me Salt
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 // If you are using Remember Me functionality, you should consider
87 87
 // changing this value to be unique to your site.
88 88
 //
89
-    $config['auth.salt'] = 'ASimpleSalt';
89
+	$config['auth.salt'] = 'ASimpleSalt';
90 90
 
91 91
 //--------------------------------------------------------------------
92 92
 // Remember Length
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 //      6 months - 14515200
107 107
 //      1 year   - 29030400
108 108
 //
109
-    $config['auth.remember_length'] = 1209600;
109
+	$config['auth.remember_length'] = 1209600;
110 110
 
111 111
 
112 112
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 // Throttling exponentially increases the time between allowed login
124 124
 // attempts.
125 125
 //
126
-    $config['auth.allow_throttling'] = true;
126
+	$config['auth.allow_throttling'] = true;
127 127
 
128 128
 //--------------------------------------------------------------------
129 129
 // Max Throttling Time
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 //
135 135
 // This is the number of SECONDS max.
136 136
 //
137
-    $config['auth.max_throttle_time'] = 50;
137
+	$config['auth.max_throttle_time'] = 50;
138 138
 
139 139
 //--------------------------------------------------------------------
140 140
 // Start Throttling After
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 // Throttling will start after X number of attempts. Before this,
143 143
 // the user can make attempts like normal.
144 144
 //
145
-    $config['auth.allowed_login_attempts'] = 5;
145
+	$config['auth.allowed_login_attempts'] = 5;
146 146
 
147 147
 //--------------------------------------------------------------------
148 148
 // Distributed Brute Force Checks
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 // The amount to multiply the average daily logins over the last 3 months
151 151
 // by to determine if we might be under a distributed brute force attempt.
152 152
 //
153
-    $config['auth.dbrute_multiplier'] = 3;
153
+	$config['auth.dbrute_multiplier'] = 3;
154 154
 
155 155
 //--------------------------------------------------------------------
156 156
 // Additional Suspension Time for Distributed Brute Force Attempts
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 // This is the number of SECONDS that will be added to all login
159 159
 // attempts that are being throttled.
160 160
 //
161
-    $config['auth.distributed_brute_add_time'] = 45;
161
+	$config['auth.distributed_brute_add_time'] = 45;
162 162
 
163 163
 
164 164
 //--------------------------------------------------------------------
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 //      - 30 bits of entropy = minimum for a web service with business critical applications (e.g. SAAS).
177 177
 //      - 40 bits of entropy = minimum for a bank or other financial service.
178 178
 //
179
-    $config['auth.min_password_strength'] = 18;
179
+	$config['auth.min_password_strength'] = 18;
180 180
 
181 181
 //--------------------------------------------------------------------
182 182
 // Use Dictionary
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 // dictionary to eliminate common words and their variations that would
186 186
 // be pretty simply for a hacking attempt to guess?
187 187
 //
188
-    $config['auth.use_dictionary'] = false;
188
+	$config['auth.use_dictionary'] = false;
189 189
 
190 190
 //--------------------------------------------------------------------
191 191
 // PASSWORD HASHING COST
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 //      - 'email'   The are sent an email with an activation link/code
209 209
 //      - 'manual'  Requires manual approval by a site administrator.
210 210
 //
211
-    $config['auth.activation_method'] = 'auto';
211
+	$config['auth.activation_method'] = 'auto';
212 212
 
213 213
 
214 214
 //--------------------------------------------------------------------
@@ -220,4 +220,4 @@  discard block
 block discarded – undo
220 220
 //--------------------------------------------------------------------
221 221
 // Sets the Default role id to use when creating new users.
222 222
 //
223
-    $config['auth.default_role_id'] = 3;
223
+	$config['auth.default_role_id'] = 3;
Please login to merge, or discard this patch.
application/views/notice.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,11 @@
 block discarded – undo
4 4
         <a href="#" class="close">&times;</a>
5 5
     </div>
6 6
 
7
-<?php else: ?>
7
+<?php else {
8
+	: ?>
8 9
 
9 10
     <div id="notice"></div>
10 11
 
11
-<?php endif; ?>
12 12
\ No newline at end of file
13
+<?php endif;
14
+}
15
+?>
13 16
\ No newline at end of file
Please login to merge, or discard this patch.
myth/Mail/Queue.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,8 +34,8 @@
 block discarded – undo
34 34
 
35 35
 class Queue extends CIDbModel {
36 36
 
37
-    protected $table_name = 'mail_queue';
37
+	protected $table_name = 'mail_queue';
38 38
 
39
-    protected $set_created = false;
40
-    protected $set_modified = false;
39
+	protected $set_created = false;
40
+	protected $set_modified = false;
41 41
 }
Please login to merge, or discard this patch.
application/database/migrations/20160111121139_UpdateLoginAttemptsTable.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -10,57 +10,57 @@
 block discarded – undo
10 10
  */
11 11
 class Migration_UpdateLoginAttemmptsTable extends CI_Migration {
12 12
 
13
-    public function up()
14
-    {
15
-        $fields = array(
16
-            'type' => array(
17
-                'type'       => 'varchar',
18
-                'constraint' => 64,
19
-                'null'       => false,
20
-                'default'    => 'app',
21
-                'after'      => 'id'
22
-            ),
23
-            'ip_address' => array(
24
-                'type'       => 'varchar',
25
-                'constraint' => 255,
26
-                'null'       => true,
27
-                'after'      => 'type'
28
-            ),
29
-            'user_id' => array(
30
-                'type'       => 'int',
31
-                'constraint' => 11,
32
-                'unsigned'   => true,
33
-                'null'       => true,
34
-                'after'      => 'ip_address'
35
-            )
36
-        );
13
+	public function up()
14
+	{
15
+		$fields = array(
16
+			'type' => array(
17
+				'type'       => 'varchar',
18
+				'constraint' => 64,
19
+				'null'       => false,
20
+				'default'    => 'app',
21
+				'after'      => 'id'
22
+			),
23
+			'ip_address' => array(
24
+				'type'       => 'varchar',
25
+				'constraint' => 255,
26
+				'null'       => true,
27
+				'after'      => 'type'
28
+			),
29
+			'user_id' => array(
30
+				'type'       => 'int',
31
+				'constraint' => 11,
32
+				'unsigned'   => true,
33
+				'null'       => true,
34
+				'after'      => 'ip_address'
35
+			)
36
+		);
37 37
 
38
-        $this->dbforge->add_column('auth_login_attempts', $fields);
38
+		$this->dbforge->add_column('auth_login_attempts', $fields);
39 39
 
40
-        $this->db->query('ALTER TABLE `auth_login_attempts` ADD KEY (`user_id`)');
40
+		$this->db->query('ALTER TABLE `auth_login_attempts` ADD KEY (`user_id`)');
41 41
 
42
-        $this->dbforge->drop_column('auth_login_attempts', 'email');
43
-    }
42
+		$this->dbforge->drop_column('auth_login_attempts', 'email');
43
+	}
44 44
 
45
-    //--------------------------------------------------------------------
45
+	//--------------------------------------------------------------------
46 46
 
47
-    public function down()
48
-    {
49
-        $this->dbforge->drop_column('auth_login_attempts', 'type');
50
-        $this->dbforge->drop_column('auth_login_attempts', 'ip_address');
51
-        $this->dbforge->drop_column('auth_login_attempts', 'user_id');
47
+	public function down()
48
+	{
49
+		$this->dbforge->drop_column('auth_login_attempts', 'type');
50
+		$this->dbforge->drop_column('auth_login_attempts', 'ip_address');
51
+		$this->dbforge->drop_column('auth_login_attempts', 'user_id');
52 52
 
53
-        $column = ['email' => [
54
-            'type'       => 'varchar',
55
-            'constraint' => 255,
56
-            'after'      => 'id'
57
-        ]];
53
+		$column = ['email' => [
54
+			'type'       => 'varchar',
55
+			'constraint' => 255,
56
+			'after'      => 'id'
57
+		]];
58 58
 
59
-        $this->dbforge->add_column('auth_login_attempts', $column);
59
+		$this->dbforge->add_column('auth_login_attempts', $column);
60 60
 
61
-        $this->db->query('ALTER TABLE `auth_login_attempts` ADD KEY (`email`)');
62
-    }
61
+		$this->db->query('ALTER TABLE `auth_login_attempts` ADD KEY (`email`)');
62
+	}
63 63
 
64
-    //--------------------------------------------------------------------
64
+	//--------------------------------------------------------------------
65 65
 
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
myth/_generators/Controller/view_update.tpl.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -5,45 +5,45 @@
 block discarded – undo
5 5
 <?= $uikit->row([], function() use($uikit, $fields)
6 6
 {
7 7
 
8
-    $sizes = [
9
-        's' => 12,
10
-        'm' => 6,
11
-        'l' => 4
12
-    ];
13
-    echo $uikit->column( [ 'sizes' => $sizes ], function () use ( $uikit, $fields )
14
-    {
15
-
16
-        foreach ( $fields as $field )
17
-        {
18
-
19
-            echo $uikit->inputWrap( humanize( $field['name'] ), NULL, function () use ( $uikit, $field )
20
-            {
21
-
22
-                switch ( $field['type'] )
23
-                {
24
-                    case 'text':
25
-                        echo "            <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
26
-                        break;
27
-                    case 'number':
28
-                        echo "            <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
29
-                        break;
30
-                    case 'date':
31
-                        echo "            <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
32
-                        break;
33
-                    case 'datetime':
34
-                        echo "            <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
35
-                        break;
36
-                    case 'time':
37
-                        echo "            <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
38
-                        break;
39
-                    case 'textarea':
40
-                        echo "            <textarea  class='form-control' name='{$field['name']}'>@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?></textarea>\n";
41
-                        break;
42
-                }
43
-
44
-            } );
45
-        }
46
-    } );
8
+	$sizes = [
9
+		's' => 12,
10
+		'm' => 6,
11
+		'l' => 4
12
+	];
13
+	echo $uikit->column( [ 'sizes' => $sizes ], function () use ( $uikit, $fields )
14
+	{
15
+
16
+		foreach ( $fields as $field )
17
+		{
18
+
19
+			echo $uikit->inputWrap( humanize( $field['name'] ), NULL, function () use ( $uikit, $field )
20
+			{
21
+
22
+				switch ( $field['type'] )
23
+				{
24
+					case 'text':
25
+						echo "            <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
26
+						break;
27
+					case 'number':
28
+						echo "            <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
29
+						break;
30
+					case 'date':
31
+						echo "            <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
32
+						break;
33
+					case 'datetime':
34
+						echo "            <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
35
+						break;
36
+					case 'time':
37
+						echo "            <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
38
+						break;
39
+					case 'textarea':
40
+						echo "            <textarea  class='form-control' name='{$field['name']}'>@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?></textarea>\n";
41
+						break;
42
+				}
43
+
44
+			} );
45
+		}
46
+	} );
47 47
 } );
48 48
 ?>
49 49
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,34 +10,34 @@
 block discarded – undo
10 10
         'm' => 6,
11 11
         'l' => 4
12 12
     ];
13
-    echo $uikit->column( [ 'sizes' => $sizes ], function () use ( $uikit, $fields )
13
+    echo $uikit->column(['sizes' => $sizes], function() use ($uikit, $fields)
14 14
     {
15 15
 
16
-        foreach ( $fields as $field )
16
+        foreach ($fields as $field)
17 17
         {
18 18
 
19
-            echo $uikit->inputWrap( humanize( $field['name'] ), NULL, function () use ( $uikit, $field )
19
+            echo $uikit->inputWrap(humanize($field['name']), NULL, function() use ($uikit, $field)
20 20
             {
21 21
 
22
-                switch ( $field['type'] )
22
+                switch ($field['type'])
23 23
                 {
24 24
                     case 'text':
25
-                        echo "            <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
25
+                        echo "            <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?>' />\n";
26 26
                         break;
27 27
                     case 'number':
28
-                        echo "            <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
28
+                        echo "            <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?>' />\n";
29 29
                         break;
30 30
                     case 'date':
31
-                        echo "            <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
31
+                        echo "            <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?>' />\n";
32 32
                         break;
33 33
                     case 'datetime':
34
-                        echo "            <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
34
+                        echo "            <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?>' />\n";
35 35
                         break;
36 36
                     case 'time':
37
-                        echo "            <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n";
37
+                        echo "            <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?>' />\n";
38 38
                         break;
39 39
                     case 'textarea':
40
-                        echo "            <textarea  class='form-control' name='{$field['name']}'>@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?></textarea>\n";
40
+                        echo "            <textarea  class='form-control' name='{$field['name']}'>@= set_value('".$field["name"]."', \$item->".$field['name']." ) ?></textarea>\n";
41 41
                         break;
42 42
                 }
43 43
 
Please login to merge, or discard this patch.