These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * HIAM module for MRDP database compatibility |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/hiam-mrdp |
||
6 | * @package hiam-mrdp |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hiam\mrdp\storage; |
||
12 | |||
13 | use yii\db\Query; |
||
14 | |||
15 | class ClientQuery extends \yii\db\ActiveQuery |
||
16 | { |
||
17 | public function init() |
||
18 | { |
||
19 | parent::init(); |
||
20 | $this |
||
21 | ->select([ |
||
22 | 'c.obj_id AS id', |
||
23 | 'c.login AS username', |
||
24 | 'r.login AS seller', |
||
25 | 'c.seller_id AS seller_id', |
||
26 | 'y.name AS type', |
||
27 | 'z.name AS state', |
||
28 | 'e.roles AS roles', |
||
29 | 'k.first_name AS first_name', |
||
30 | 'k.last_name AS last_name', |
||
31 | 't.value AS totp_secret', |
||
32 | 'coalesce(i.value,l.value) AS allowed_ips', |
||
33 | 'coalesce(c.email,k.email) AS email', |
||
34 | "encode(digest(c.password, 'sha1'), 'hex') AS password_hash", |
||
35 | 'o.value AS email_confirmed' |
||
36 | ]) |
||
37 | ->from('zclient c') |
||
38 | ->innerJoin('zclient r', 'r.obj_id=c.seller_id') |
||
39 | ->innerJoin('zref y', 'y.obj_id=c.type_id') |
||
40 | ->innerJoin('zref z', 'z.obj_id=c.state_id') |
||
41 | ->leftJoin('contact k', 'k.obj_id=c.obj_id') |
||
42 | ->leftJoin('value t', "t.obj_id=c.obj_id AND t.prop_id=prop_id('client,access:totp_secret')") |
||
43 | ->leftJoin('value i', "i.obj_id=c.obj_id AND i.prop_id=prop_id('client,access:allowed_ips')") |
||
44 | ->leftJoin('value l', "l.obj_id=c.obj_id AND l.prop_id=prop_id('login_ips:panel')") |
||
45 | ->leftJoin('value o', "o.obj_id=c.obj_id AND o.prop_id=prop_id('contact:email_confirmed')") |
||
46 | ->leftJoin('client2rolez e', 'e.client_id=c.obj_id') |
||
47 | ->andWhere(['in', 'z.name', ['ok', 'new']]); |
||
48 | } |
||
49 | |||
50 | public function andWhere($condition, $params = []) |
||
51 | { |
||
52 | if (!is_array($condition) || isset($condition[0])) { |
||
53 | return parent::andWhere($condition, $params); |
||
54 | } |
||
55 | foreach (['id', 'username', 'password', 'email', 'active'] as $key) { |
||
56 | /// XXX `isset` does not fit here |
||
57 | if (array_key_exists($key, $condition)) { |
||
58 | $this->{"where$key"}($condition[$key]); |
||
59 | unset($condition[$key]); |
||
60 | } |
||
61 | } |
||
62 | if (!empty($condition)) { |
||
63 | parent::andWhere($condition, $params); |
||
64 | } |
||
65 | |||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | public function whereId($id) |
||
70 | { |
||
71 | return parent::andWhere(['c.obj_id' => $id]); |
||
72 | } |
||
73 | |||
74 | public function whereEmail($username) |
||
75 | { |
||
76 | return parent::andWhere(['or', 'c.login=:username', 'c.email=:username'], [':username' => $username]); |
||
77 | } |
||
78 | |||
79 | public function whereUsername($username) |
||
80 | { |
||
81 | $userId = (int)$username; |
||
82 | if ($userId > 0 && "$userId" === trim($username)) { |
||
83 | return $this->whereId($userId); |
||
84 | } |
||
85 | |||
86 | return parent::andWhere([ |
||
0 ignored issues
–
show
|
|||
87 | 'or', |
||
88 | ['or', 'c.login=:username', 'c.email=:username'], |
||
89 | [ |
||
90 | 'and', |
||
91 | 'k.email = :username', |
||
92 | 'cc.count = 1' |
||
93 | ] |
||
94 | ], [':username' => $username]) |
||
95 | ->leftJoin([ |
||
96 | 'cc' => (new Query())->select(['email', 'count(*)'])->from('zcontact')->groupBy('email') |
||
97 | ], 'cc.email = k.email'); |
||
98 | } |
||
99 | |||
100 | public function wherePassword($password) |
||
101 | { |
||
102 | return parent::andWhere( |
||
103 | 'check_password(:password,c.password) OR check_password(:password,tmp.value)', |
||
104 | [':password' => $password] |
||
105 | )->leftJoin('value tmp', "tmp.obj_id=c.obj_id AND tmp.prop_id=prop_id('client,access:tmp_pwd')"); |
||
106 | } |
||
107 | |||
108 | public function whereActive($is_active) |
||
109 | { |
||
110 | if (is_null($is_active)) { |
||
111 | return $this; |
||
112 | } |
||
113 | |||
114 | return parent::andWhere([$is_active ? 'in' : 'not in', 'z.name', ['ok', 'active']]); |
||
115 | } |
||
116 | } |
||
117 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.