Completed
Push — master ( 611444...b370ba )
by Patrick
03:39
created

AuthProvider::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * AuthProvider class
4
 *
5
 * This file describes the AuthProvider Singleton
6
 *
7
 * PHP version 5 and 7
8
 *
9
 * @author Patrick Boyd / [email protected]
10
 * @copyright Copyright (c) 2015, Austin Artistic Reconstruction
11
 * @license http://www.apache.org/licenses/ Apache 2.0 License
12
 */
13
14
/**
15
 * Allow other classes to be loaded as needed
16
 */
17
require_once('Autoload.php');
18
/**
19
 * Require the FlipsideSettings file
20
 */
21
if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
22
{
23
    require_once($GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php');
24
}
25
else
26
{
27
    require_once('/var/www/secure_settings/class.FlipsideSettings.php');
28
}
29
30
/**
31
 * A Singleton class to abstract access to the authentication providers.
32
 *
33
 * This class is the primary method to access user data, login, and other authenication information.
34
 */
35
class AuthProvider extends Provider
36
{
37
    /**
38
     * Load the authentrication providers specified in the FlipsideSettings::$authProviders array
39
     */
40 View Code Duplication
    protected function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this->methods = array();
43
        if(isset(FlipsideSettings::$authProviders))
44
        {
45
            $keys = array_keys(FlipsideSettings::$authProviders);
46
            $count = count($keys);
47
            for($i = 0; $i < $count; $i++)
48
            {
49
                $class = $keys[$i];
50
                array_push($this->methods, new $class(FlipsideSettings::$authProviders[$keys[$i]]));
51
            }
52
        }
53
    }
54
55
    /**
56
     * Get the Auth\User class instance for the specified login
57
     *
58
     * Unlike the AuthProvider::login() function. This function will not impact the SESSION
59
     *
60
     * @param string $username The username of the User
61
     * @param string $password The password of the User
62
     *
63
     * @return Auth\User|false The User with the specified credentials or false if the credentials are not valid
64
     */
65
    public function getUserByLogin($username, $password)
66
    {
67
        $res = false;
68
        $count = count($this->methods);
69
        for($i = 0; $i < $count; $i++)
70
        {
71
            $res = $this->methods[$i]->login($username, $password);
72
            if($res !== false)
73
            {
74
                return $this->methods[$i]->getUser($res);
75
            }
76
        }
77
        return $res;
78
    }
79
80
    /**
81
     * Use the provided credetials to log the user on
82
     *
83
     * @param string $username The username of the User
84
     * @param string $password The password of the User
85
     *
86
     * @return true|false true if the login was successful, false otherwise
87
     */
88
    public function login($username, $password)
89
    {
90
        $res = false;
91
        $count = count($this->methods);
92
        for($i = 0; $i < $count; $i++)
93
        {
94
            $res = $this->methods[$i]->login($username, $password);
95
            if($res !== false)
96
            {
97
                FlipSession::setVar('AuthMethod', get_class($this->methods[$i]));
98
                FlipSession::setVar('AuthData', $res);
99
                break;
100
            }
101
        }
102
        return $res;
103
    }
104
105
    /**
106
     * Determine if the user is still logged on from the session data
107
     *
108
     * @param stdClass $data The AuthData from the session
109
     * @param string $methodName The AuthMethod from the session
110
     *
111
     * @return true|false true if user is logged on, false otherwise
112
     */
113
    public function isLoggedIn($data, $methodName)
114
    {
115
        $auth = $this->getMethodByName($methodName);
116
        return $auth->isLoggedIn($data);
117
    }
118
119
    /**
120
     * Obtain the currently logged in user from the session data
121
     *
122
     * @param stdClass $data The AuthData from the session
123
     * @param string $methodName The AuthMethod from the session
124
     *
125
     * @return Auth\User|false The User instance if user is logged on, false otherwise
126
     */
127
    public function getUser($data, $methodName)
128
    {
129
        $auth = $this->getMethodByName($methodName);
130
        return $auth->getUser($data);
131
    }
132
133
    /**
134
     * Merge or set the returnValue as appropriate
135
     *
136
     * @param false|Auth\Group|Auth\User $returnValue The value to merge to
137
     * @param Auth\Group|Auth\User $res The value to merge from
138
     *
139
     * @return Auth\Group|false The merged returnValue
140
     */
141
    private function mergeResult(&$returnValue, $res)
142
    {
143
        if($res === false)
144
        {
145
            return;
146
        }
147
        if($returnValue === false)
148
        {
149
            $returnValue = $res;
150
            return;
151
        }
152
        $returnValue->merge($res);
153
    }
154
155
    /**
156
     * Calls the indicated function on each Authenticator and merges the result
157
     *
158
     * @param string $functionName The function to call
159
     * @param array $args The arguments for the function
160
     * @param string $checkField A field to check if it is set a certain way before calling the function
161
     * @param mixed $checkValue The value that field should be set to to not call the function
162
     *
163
     * @return Auth\Group|Auth\User|false The merged returnValue
164
     */
165 View Code Duplication
    private function callOnEach($functionName, $args, $checkField = false, $checkValue = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        $ret = false;
168
        $count = count($this->methods);
169
        for($i = 0; $i < $count; $i++)
170
        {
171
            if($checkField !== false)
172
            {
173
                if($this->methods[$i]->{$checkField} === $checkValue)
174
                {
175
                    continue;
176
                }
177
            }
178
            $res = call_user_func_array(array($this->methods[$i], $functionName), $args);
179
            $this->mergeResult($ret, $res);
180
        }
181
        return $ret;
182
    }
183
184
    /**
185
     * Calls the indicated function on each Authenticator and add the result
186
     *
187
     * @param string $functionName The function to call
188
     * @param string $checkField A field to check if it is set a certain way before calling the function
189
     * @param mixed $checkValue The value that field should be set to to not call the function
190
     *
191
     * @return integer The added returnValue
192
     */
193 View Code Duplication
    private function addFromEach($functionName, $checkField = false, $checkValue = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
194
    {
195
        $retCount = 0;
196
        $count = count($this->methods);
197
        for($i = 0; $i < $count; $i++)
198
        {
199
            if($checkField !== false)
200
            {
201
                if($this->methods[$i]->{$checkField} === $checkValue)
202
                {
203
                    continue;
204
                }
205
            }
206
            $res = call_user_func(array($this->methods[$i], $functionName));
207
            $retCount += $res;
208
        }
209
        return $retCount;
210
    }
211
212
    /**
213
     * Get an Auth\Group by its name
214
     *
215
     * @param string $name The name of the group
216
     * @param string $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
217
     *
218
     * @return Auth\Group|false The Group instance if a group with that name exists, false otherwise
219
     */
220
    public function getGroupByName($name, $methodName = false)
221
    {
222
        if($methodName === false)
223
        {
224
            return $this->callOnEach('getGroupByName', array($name));
225
        }
226
        $auth = $this->getMethodByName($methodName);
227
        return $auth->getGroupByName($name);
228
    }
229
230
    /**
231
     * Get an array of Auth\User from a filtered set
232
     *
233
     * @param Data\Filter|boolean $filter The filter conditions or false to retreive all
234
     * @param array|boolean $select The user fields to obtain or false to obtain all
235
     * @param integer|boolean $top The number of users to obtain or false to obtain all
236
     * @param integer|boolean $skip The number of users to skip or false to skip none
237
     * @param array|boolean $orderby The field to sort by and the method to sort or false to not sort
238
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
239
     *
240
     * @return array|boolean An array of Auth\User objects or false if no users were found
241
     */
242 View Code Duplication
    public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
243
    {
244
        if($methodName === false)
245
        {
246
            return $this->callOnEach('getUsersByFilter', array($filter, $select, $top, $skip, $orderby), 'current');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->callOnEach... $orderby), 'current'); (false|Auth\Group|Auth\User) is incompatible with the return type documented by AuthProvider::getUsersByFilter of type array|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
247
        }
248
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 242 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
249
        return $auth->getUsersByFilter($filter, $select, $top, $skip, $orderby);
250
    }
251
252
    /**
253
     * Get an array of Auth\PendingUser from a filtered set
254
     *
255
     * @param Data\Filter|boolean $filter The filter conditions or false to retreive all
256
     * @param array|boolean $select The user fields to obtain or false to obtain all
257
     * @param integer|boolean $top The number of users to obtain or false to obtain all
258
     * @param integer|boolean $skip The number of users to skip or false to skip none
259
     * @param array|boolean $orderby The field to sort by and the method to sort or false to not sort
260
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
261
     *
262
     * @return array|boolean An array of Auth\PendingUser objects or false if no pending users were found
263
     */
264 View Code Duplication
    public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
265
    {
266
        if($methodName === false)
267
        {
268
            return $this->callOnEach('getPendingUsersByFilter', array($filter, $select, $top, $skip, $orderby), 'pending');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->callOnEach... $orderby), 'pending'); (false|Auth\Group|Auth\User) is incompatible with the return type documented by AuthProvider::getPendingUsersByFilter of type array|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
269
        }
270
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 264 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
271
        return $auth->getPendingUsersByFilter($filter, $select, $top, $skip, $orderby);
272
    }
273
274
    /**
275
     * Get an array of Auth\Group from a filtered set
276
     *
277
     * @param Data\Filter|false $filter The filter conditions or false to retreive all
278
     * @param array|false $select The group fields to obtain or false to obtain all
279
     * @param integer|false $top The number of groups to obtain or false to obtain all
280
     * @param integer|false $skip The number of groups to skip or false to skip none
281
     * @param array|false $orderby The field to sort by and the method to sort or false to not sort
282
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
283
     *
284
     * @return array|false An array of Auth\Group objects or false if no pending users were found
285
     */
286 View Code Duplication
    public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
    {
288
        if($methodName === false)
289
        {
290
            return $this->callOnEach('getGroupsByFilter', array($filter, $select, $top, $skip, $orderby), 'current');
291
        }
292
        $auth = $this->getMethodByName($methodName);
293
        return $auth->getGroupsByFilter($filter, $select, $top, $skip, $orderby);
294
    }
295
296
    /**
297
     * Get the number of currently active users on the system
298
     *
299
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
300
     *
301
     * @return integer The number of currently active users on the system
302
     */
303
    public function getActiveUserCount($methodName = false)
304
    {
305
        if($methodName === false)
306
        {
307
            return $this->addFromEach('getActiveUserCount', 'current');
308
        }
309
        $auth = $this->getMethodByName($methodName);
310
        return $auth->getActiveUserCount();
311
    }
312
313
    /**
314
     * Get the number of currently pending users on the system
315
     *
316
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
317
     *
318
     * @return integer The number of currently pending users on the system
319
     */
320
    public function getPendingUserCount($methodName = false)
321
    {
322
        if($methodName === false)
323
        {
324
            return $this->addFromEach('getPendingUserCount', 'pending');
325
        }
326
        $auth = $this->getMethodByName($methodName);
327
        return $auth->getPendingUserCount();
328
    }
329
330
    /**
331
     * Get the number of current groups on the system
332
     *
333
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
334
     *
335
     * @return integer The number of current groups on the system
336
     */
337
    public function getGroupCount($methodName = false)
338
    {
339
        if($methodName === false)
340
        {
341
            return $this->addFromEach('getGroupCount', 'current');
342
        }
343
        $auth = $this->getMethodByName($methodName);
344
        return $auth->getGroupCount();
345
    }
346
347
    /**
348
     * Get the login links for all supplementary Authenitcation mechanisms
349
     *
350
     * This will return an array of links to any supplementary authentication mechanims. For example, Goodle is 
351
     * a supplementary authentication mechanism.
352
     *
353
     * @return array An array of suppmentary authentication mechanism links
354
     */
355
    public function getSupplementaryLinks()
356
    {
357
        $ret = array();
358
        $count = count($this->methods);
359 View Code Duplication
        for($i = 0; $i < $count; $i++)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360
        {
361
            if($this->methods[$i]->supplement === false)
362
            {
363
                continue;
364
            }
365
366
            array_push($ret, $this->methods[$i]->getSupplementLink());
367
        }
368
        return $ret;
369
    }
370
371
    /**
372
     * Impersonate the user specified
373
     *
374
     * This will replace the user in the session with the specified user. In order
375
     * to undo this operation a user must logout.
376
     *
377
     * @param array|Auth\User $userArray Data representing the user
378
     */
379
    public function impersonateUser($userArray)
380
    {
381
        if(!is_object($userArray))
382
        {
383
            $userArray = new $userArray['class']($userArray);
384
        }
385
        \FlipSession::setUser($userArray);
386
    }
387
388
    /**
389
     * Get the pending user reresented by the supplied hash
390
     *
391
     * @param string $hash The hash value representing the Penging User
392
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
393
     *
394
     * @return Auth\PendingUser|false The Auth\PendingUser instance or false if no user is matched by the provided hash
395
     */
396
    public function getTempUserByHash($hash, $methodName = false)
397
    {
398
        if($methodName === false)
399
        {
400
            $count = count($this->methods);
401
            for($i = 0; $i < $count; $i++)
402
            {
403
                if($this->methods[$i]->pending === false)
404
                {
405
                    continue;
406
                }
407
408
                $ret = $this->methods[$i]->getTempUserByHash($hash);
409
                if($ret !== false)
410
                {
411
                    return $ret;
412
                }
413
            }
414
            return false;
415
        }
416
        $auth = $this->getMethodByName($methodName);
417
        return $auth->getTempUserByHash($hash);
418
    }
419
420
    /**
421
     * Create a pending user
422
     *
423
     * @param array $user An array of information about the user to create
424
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
425
     *
426
     * @return boolean true if the user was successfully created. Otherwise false.
427
     */
428
    public function createPendingUser($user, $methodName = false)
429
    {
430
        if($methodName === false)
431
        {
432
            $count = count($this->methods);
433
            for($i = 0; $i < $count; $i++)
434
            {
435
                if($this->methods[$i]->pending === false)
436
                {
437
                    continue;
438
                }
439
440
                $ret = $this->methods[$i]->createPendingUser($user);
441
                if($ret !== false)
442
                {
443
                    return true;
444
                }
445
            }
446
            return false;
447
        }
448
        $auth = $this->getMethodByName($methodName);
449
        return $auth->createPendingUser($user);
450
    }
451
452
    /**
453
     * Convert a Auth\PendingUser into an Auth\User
454
     *
455
     * This will allow a previously pending user the ability to log on in the future as an active user. It will also
456
     * have the side effect of logging the user on now.
457
     *
458
     * @param Auth\PendingUser $user The user to turn into a current user
459
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
460
     *
461
     * @return boolean true if the user was successfully created. Otherwise false.
462
     */
463 View Code Duplication
    public function activatePendingUser($user, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
464
    {
465
        if($methodName === false)
466
        {
467
            $count = count($this->methods);
468
            for($i = 0; $i < $count; $i++)
469
            {
470
                if($this->methods[$i]->current === false)
471
                {
472
                    continue;
473
                }
474
475
                $ret = $this->methods[$i]->activatePendingUser($user);
476
                if($ret !== false)
477
                {
478
                    $this->impersonateUser($ret);
479
                    return true;
480
                }
481
            }
482
            return false;
483
        }
484
        $auth = $this->getMethodByName($methodName);
485
        return $auth->activatePendingUser($user);
486
    }
487
488
    /**
489
     * Get a current user by a password reset hash
490
     *
491
     * @param string $hash The current password reset hash for the user
492
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
493
     *
494
     * @return Auth\User|false The user if the password reset hash is valid. Otherwise false.
495
     */
496 View Code Duplication
    public function getUserByResetHash($hash, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
497
    {
498
        if($methodName === false)
499
        {
500
            $count = count($this->methods);
501
            for($i = 0; $i < $count; $i++)
502
            {
503
                if($this->methods[$i]->current === false)
504
                {
505
                    continue;
506
                }
507
508
                $ret = $this->methods[$i]->getUserByResetHash($hash);
509
                if($ret !== false)
510
                {
511
                    return $ret;
512
                }
513
            }
514
            return false;
515
        }
516
        $auth = $this->getMethodByName($methodName);
517
        if($auth === false)
518
        {
519
            return $this->getUserByResetHash($hash, false);
520
        }
521
        return $auth->getUserByResetHash($hash);
522
    }
523
524
    /**
525
     * Get the Auth\Authenticator by host name
526
     *
527
     * @param string $host The host name used by the supplemental authentication mechanism
528
     *
529
     * @return Auth\Authenticator|false The Authenticator if the host is supported by a loaded Authenticator. Otherwise false.
530
     */
531
    public function getSuplementalProviderByHost($host)
532
    {
533
        $count = count($this->methods);
534 View Code Duplication
        for($i = 0; $i < $count; $i++)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
535
        {
536
            if($this->methods[$i]->supplement === false)
537
            {
538
                continue;
539
            }
540
541
            if($this->methods[$i]->getHostName() === $host)
542
            {
543
                return $this->methods[$i];
544
            }
545
        }
546
        return false;
547
    }
548
549
    /**
550
     * Delete any pending users that match the filter
551
     *
552
     * @param \Data\Filter|boolean $filter The filter to delete with or false to delete all
553
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
554
     *
555
     * @return boolean True if the users were deleted, false otherwise
556
     */
557
    public function deletePendingUsersByFilter($filter, $methodName = false)
558
    {
559
        $users = $this->getPendingUsersByFilter($filter, false, false, false, false, $methodName);
560
        if($users === false)
561
        {
562
            return false;
563
        }
564
        $count = count($users);
565
        for($i = 0; $i < $count; $i++)
566
        {
567
            $users[$i]->delete();
568
        }
569
        return true;
570
    }
571
572
    /**
573
     * Get the user by the one time access code
574
     *
575
     * @param string $key The user's access code
576
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
577
     *
578
     * @return boolean|\Auth\User The User specified by the access code or false otherwise
579
     */
580
    public function getUserByAccessCode($key, $methodName = false)
581
    {
582
        if($methodName === false)
583
        {
584
            $count = count($this->methods);
585
            for($i = 0; $i < $count; $i++)
586
            {
587
                if($this->methods[$i]->current === false)
588
                {
589
                    continue;
590
                }
591
592
                $ret = $this->methods[$i]->getUserByAccessCode($key);
593
                if($ret !== false)
594
                {
595
                    return $ret;
596
                }
597
            }
598
            return false;
599
        }
600
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 580 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
601
        return $auth->getUserByAccessCode($key);
602
    }
603
}
604
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
605