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
|
|
|
'to_1(has_deposits(c.obj_id)) AS verified', |
33
|
|
|
'coalesce(i.value,l.value) AS allowed_ips', |
34
|
|
|
'coalesce(c.email,k.email) AS email', |
35
|
|
|
"encode(digest(c.password, 'sha1'), 'hex') AS password_hash", |
36
|
|
|
'o.value AS email_confirmed' |
37
|
|
|
]) |
38
|
|
|
->from('zclient c') |
39
|
|
|
->innerJoin('zclient r', 'r.obj_id=c.seller_id') |
40
|
|
|
->innerJoin('zref y', 'y.obj_id=c.type_id') |
41
|
|
|
->innerJoin('zref z', 'z.obj_id=c.state_id') |
42
|
|
|
->leftJoin('contact k', 'k.obj_id=c.obj_id') |
43
|
|
|
->leftJoin('value t', "t.obj_id=c.obj_id AND t.prop_id=prop_id('client,access:totp_secret')") |
44
|
|
|
->leftJoin('value i', "i.obj_id=c.obj_id AND i.prop_id=prop_id('client,access:allowed_ips')") |
45
|
|
|
->leftJoin('value l', "l.obj_id=c.obj_id AND l.prop_id=prop_id('login_ips:panel')") |
46
|
|
|
->leftJoin('value o', "o.obj_id=c.obj_id AND o.prop_id=prop_id('contact:email_confirmed')") |
47
|
|
|
->leftJoin('client2rolez e', 'e.client_id=c.obj_id') |
48
|
|
|
->andWhere(['in', 'z.name', ['ok', 'new']]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function andWhere($condition, $params = []) |
52
|
|
|
{ |
53
|
|
|
if (!is_array($condition) || isset($condition[0])) { |
54
|
|
|
return parent::andWhere($condition, $params); |
55
|
|
|
} |
56
|
|
|
foreach (['id', 'username', 'password', 'email', 'active'] as $key) { |
57
|
|
|
/// XXX `isset` does not fit here |
58
|
|
|
if (array_key_exists($key, $condition)) { |
59
|
|
|
$this->{"where$key"}($condition[$key]); |
60
|
|
|
unset($condition[$key]); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
if (!empty($condition)) { |
64
|
|
|
parent::andWhere($condition, $params); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function whereId($id) |
71
|
|
|
{ |
72
|
|
|
return parent::andWhere(['c.obj_id' => $id]); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function whereEmail($username) |
76
|
|
|
{ |
77
|
|
|
return parent::andWhere(['or', 'c.login=:username', 'c.email=:username'], [':username' => $username]); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function whereUsername($username) |
81
|
|
|
{ |
82
|
|
|
$userId = (int)$username; |
83
|
|
|
if ($userId > 0 && "$userId" === trim($username)) { |
84
|
|
|
return $this->whereId($userId); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return parent::andWhere(['or', 'c.login=:username', 'c.email=:username'], [':username' => $username]); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function wherePassword($password) |
91
|
|
|
{ |
92
|
|
|
return parent::andWhere( |
|
|
|
|
93
|
|
|
'check_password(:password,c.password) OR check_password(:password,tmp.value)', |
94
|
|
|
[':password' => $password] |
95
|
|
|
)->leftJoin('value tmp', "tmp.obj_id=c.obj_id AND tmp.prop_id=prop_id('client,access:tmp_pwd')"); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function whereActive($is_active) |
99
|
|
|
{ |
100
|
|
|
if (is_null($is_active)) { |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return parent::andWhere([$is_active ? 'in' : 'not in', 'z.name', ['ok', 'active']]); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.