1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Bluz PHP Team |
5
|
|
|
* @link https://github.com/bluzphp/skeleton |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Application\Auth\Provider; |
11
|
|
|
|
12
|
|
|
use Application\Auth\Model; |
13
|
|
|
use Application\Auth\Row; |
14
|
|
|
use Application\Auth\Table; |
15
|
|
|
use Application\Users\Row as User; |
16
|
|
|
use Bluz\Auth\AuthException; |
|
|
|
|
17
|
|
|
use Bluz\Db\Exception\DbException; |
|
|
|
|
18
|
|
|
use Bluz\Db\Exception\InvalidPrimaryKeyException; |
|
|
|
|
19
|
|
|
use Bluz\Db\Exception\TableNotFoundException; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Equals Provider |
23
|
|
|
* |
24
|
|
|
* @package Application\Auth\Provider |
25
|
|
|
*/ |
26
|
|
|
class Equals extends AbstractProvider |
27
|
|
|
{ |
28
|
|
|
public const PROVIDER = Table::PROVIDER_EQUALS; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
* |
33
|
|
|
* @throws AuthException |
34
|
2 |
|
* @throws DbException |
35
|
|
|
* @throws InvalidPrimaryKeyException |
36
|
2 |
|
*/ |
37
|
1 |
|
public static function authenticate(string $login, string $password = null): Row |
38
|
|
|
{ |
39
|
|
|
$authRow = self::find($login); |
40
|
1 |
|
|
41
|
1 |
|
self::verify($authRow, $password); |
42
|
|
|
|
43
|
|
|
self::login($authRow); |
44
|
|
|
|
45
|
|
|
return $authRow; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
* |
52
|
4 |
|
* @return Row |
53
|
|
|
* @throws DbException |
54
|
|
|
* @throws AuthException |
55
|
4 |
|
*/ |
56
|
|
|
public static function find(string $login): ?Row |
57
|
4 |
|
{ |
58
|
|
|
return Table::findRowWhere(['foreignKey' => $login, 'provider' => self::PROVIDER]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
4 |
|
* {@inheritdoc} |
63
|
2 |
|
* |
64
|
|
|
* @param Row|null $authRow |
65
|
|
|
* @return void |
66
|
2 |
|
* @throws AuthException |
67
|
|
|
*/ |
68
|
|
|
protected static function verify(?Row $authRow, string $password = null): void |
69
|
|
|
{ |
70
|
|
|
if (!$authRow) { |
71
|
|
|
throw new AuthException('User can\'t login with password'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// verify password |
75
|
|
|
if (!Model::verify($password, $authRow->token)) { |
|
|
|
|
76
|
|
|
throw new AuthException('Wrong password'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param User $user |
82
|
|
|
* @param string $password |
83
|
|
|
* @return Row |
84
|
|
|
* @throws DbException |
85
|
|
|
* @throws InvalidPrimaryKeyException |
86
|
|
|
* @throws TableNotFoundException |
87
|
|
|
*/ |
88
|
|
|
public static function create(User $user, string $password = ''): Row |
89
|
|
|
{ |
90
|
|
|
// remove old Auth record |
91
|
|
|
self::remove($user->id); |
92
|
|
|
|
93
|
|
|
// create new auth row |
94
|
|
|
$row = new Row(); |
95
|
|
|
|
96
|
|
|
$row->userId = $user->id; |
97
|
|
|
$row->foreignKey = $user->login; |
98
|
|
|
$row->provider = self::PROVIDER; |
99
|
|
|
$row->tokenType = Table::TYPE_ACCESS; |
100
|
|
|
// generate secret part is not required |
101
|
|
|
// encrypt password and save as token |
102
|
|
|
$row->token = Model::hash($password); |
103
|
|
|
|
104
|
|
|
$row->save(); |
105
|
|
|
|
106
|
|
|
return $row; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths