-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathBlock.php
More file actions
133 lines (122 loc) · 3.35 KB
/
Block.php
File metadata and controls
133 lines (122 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Banned user relationship
*/
namespace RongCloud\Lib\User\Block;
use RongCloud\Lib\Request;
use RongCloud\Lib\User\User;
use RongCloud\Lib\Utils;
class Block
{
/**
* User module path to block user
*
* @var string
*/
private $jsonPath = 'Lib/User/Block/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Verify configuration file
*
* @var string
*/
private $verify = '';
/**
* User constructor.
*/
function __construct()
{
// Initialize request configuration and validate file path
$this->conf = Utils::getJson($this->jsonPath . 'api.json');
$this->verify = Utils::getJson($this->jsonPath . '../verify.json');
}
/**
* Add banned user
*
* @param array $User Banned user parameters
* @param
* $User = [
* 'id'=> 'ujadk90ha1',// Banned user ID, unique identifier, maximum length 30 characters
* 'minute'=> 20 // Ban duration 1 - 1 * 30 * 24 * 60 minutes
* ];
* $User = [
* 'userId'=> ['ujadk90ha1'],// Banned user ID, unique identifier, maximum length 30 characters
* 'minute'=> 20 // Ban duration 1 - 1 * 30 * 24 * 60 minutes
* ];
* @return array
*/
public function add(array $User = [])
{
$conf = $this->conf['add'];
$isBatch = isset($User['userId']) && count($User['userId']) > 1;
if ($isBatch) {
$User['id'] = $User['userId'][0];
}
$error = (new Utils())->check([
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]);
if ($error) return $error;
if ($isBatch) {
unset($User['id']);
} else {
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
}
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Unblock user
*
* @param array $User Unblock parameters
* @param
* $user = [
* 'id'=> 'ujadk90ha',//Unblock user ID, unique identifier, maximum length 30 characters
* ];
* @return array
*/
public function remove(array $User = [])
{
$conf = $this->conf['remove'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'user',
'data' => $User,
'verify' => $this->verify['user']
]);
if ($error) return $error;
$User = (new Utils())->rename($User, [
'id' => 'userId',
]);
$result = (new Request())->Request($conf['url'], $User);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Get the list of banned users
*
* @param array $User Banned user list parameter
* @param
* $user = [
* ];
* @return array
*/
public function getList(array $User = [])
{
$conf = $this->conf['getList'];
$result = (new Request())->Request($conf['url'], $User);
// foreach ($result[''])
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
}