Skip to content

Commit df0f6eb

Browse files
committed
Use ->input, ->output, and ->config instead of ->controller->input
1 parent 906616e commit df0f6eb

File tree

3 files changed

+91
-43
lines changed

3 files changed

+91
-43
lines changed

src/Plugin.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function __construct(
1616
)
1717
{
1818
Util::elog(__METHOD__);
19+
Util::elog(var_export($this->controller, true));
1920

2021
$this->isValid = $this->validateAccess();
2122
if ($this->isValid)

src/Plugins/Accounts/Model.php

+89-41
Original file line numberDiff line numberDiff line change
@@ -23,70 +23,105 @@ class Model extends Plugin
2323
'altemail' => '',
2424
];
2525

26-
protected function create(): string
26+
public function create(): array
2727
{
2828
Util::elog(__METHOD__);
2929

30-
if (Util::is_adm()) return parent::create();
31-
Util::log('You are not authorized to perform this action, please contact your administrator.');
32-
Util::relist();
33-
return '';
30+
if (!Util::is_adm())
31+
{
32+
return [
33+
'status' => 'error',
34+
'message' => 'You are not authorized to perform this action, please contact your administrator.'
35+
];
36+
}
37+
38+
return parent::create();
3439
}
3540

36-
protected function read(): string
41+
public function read(): array
3742
{
3843
Util::elog(__METHOD__);
3944

40-
$usr = Db::read('*', 'id', $this->g->input['i'], '', 'one');
45+
$usr = Db::read('*', 'id', $this->controller->input['i'], '', 'one');
4146
if (!$usr)
4247
{
43-
Util::log('User not found.');
44-
Util::relist();
45-
return '';
48+
return [
49+
'status' => 'error',
50+
'message' => 'User not found.'
51+
];
4652
}
4753

4854
if (Util::is_acl(0))
4955
{
50-
// superadmin
56+
// superadmin - allow access
57+
return [
58+
'status' => 'success',
59+
'message' => $usr
60+
];
5161
}
5262
elseif (Util::is_acl(1))
53-
{ // normal admin
63+
{
64+
// normal admin
5465
if ((int)$_SESSION['usr']['grp'] !== (int)$usr['grp'])
5566
{
56-
Util::log('You are not authorized to perform this action.');
57-
Util::relist();
58-
return '';
67+
return [
68+
'status' => 'error',
69+
'message' => 'You are not authorized to perform this action.'
70+
];
5971
}
6072
}
6173
else
62-
{ // Other users
74+
{
75+
// Other users
6376
if ((int)$_SESSION['usr']['id'] !== (int)$usr['id'])
6477
{
65-
Util::log('You are not authorized to perform this action.');
66-
Util::relist();
67-
return '';
78+
return [
79+
'status' => 'error',
80+
'message' => 'You are not authorized to perform this action.'
81+
];
6882
}
6983
}
70-
return $this->g->t->read($usr);
84+
85+
return [
86+
'status' => 'success',
87+
'message' => $usr
88+
];
89+
}
90+
91+
public function update(): array
92+
{
93+
Util::elog(__METHOD__);
94+
// Add your update logic here
95+
return [
96+
'status' => 'success',
97+
'message' => 'Update operation'
98+
];
7199
}
72100

73-
protected function delete(): string
101+
public function delete(): array
74102
{
75103
Util::elog(__METHOD__);
76104

77105
if (Util::is_post())
78106
{
79107
parent::delete();
80-
return '';
108+
return [
109+
'status' => 'success',
110+
'message' => 'Delete operation completed'
111+
];
81112
}
82-
return $this->g->t->delete();
113+
114+
return [
115+
'status' => 'success',
116+
'message' => 'Confirm deletion'
117+
];
83118
}
84119

85-
protected function list(): string
120+
public function list(): array
86121
{
87122
Util::elog(__METHOD__);
88123

89-
if ($this->g->input['f'] === 'json')
124+
if ($this->controller->input['f'] === 'json')
90125
{
91126
$columns = [
92127
['dt' => null, 'db' => 'id'],
@@ -99,34 +134,47 @@ protected function list(): string
99134
['dt' => 3, 'db' => 'altemail'],
100135
['dt' => 4, 'db' => 'acl', 'formatter' => function ($d): string
101136
{
102-
return $this->g->acl[is_string($d) ? (int)$d : $d];
137+
return is_string($d) ? (int)$d : $d;
103138
}],
104139
['dt' => 5, 'db' => 'grp'],
105140
];
106-
$this->g->out['json'] = Db::simple($_GET, 'accounts', 'id', $columns);
107-
return '';
141+
return [
142+
'status' => 'success',
143+
'message' => Db::simple($_GET, 'accounts', 'id', $columns)
144+
];
108145
}
109-
return $this->g->t->list($this->in);
146+
147+
return [
148+
'status' => 'success',
149+
'message' => Db::read('*', '', '', 'ORDER BY `updated` DESC')
150+
];
110151
}
111152

112-
protected function switch_user(): string
153+
public function switch_user(): array
113154
{
114155
Util::elog(__METHOD__);
115156

116-
if (Util::is_adm() && !is_null($this->g->input['i']))
157+
if (!Util::is_adm() || is_null($this->controller->input['i']))
117158
{
118-
$usr = Db::read('id,acl,grp,login,fname,lname,webpw,cookie', 'id', $this->g->input['i'], '', 'one');
119-
if ($usr)
120-
{
121-
$_SESSION['usr'] = $usr;
122-
Util::log('Switch to user: ' . $usr['login'], 'success');
123-
}
159+
return [
160+
'status' => 'error',
161+
'message' => 'Not authorized to switch users'
162+
];
124163
}
125-
else
164+
165+
$usr = Db::read('id,acl,grp,login,fname,lname,webpw,cookie', 'id', $this->controller->input['i'], '', 'one');
166+
if ($usr)
126167
{
127-
Util::log('Not authorized to switch users');
168+
$_SESSION['usr'] = $usr;
169+
return [
170+
'status' => 'success',
171+
'message' => 'Switch to user: ' . $usr['login']
172+
];
128173
}
129-
Util::relist();
130-
return '';
174+
175+
return [
176+
'status' => 'error',
177+
'message' => 'User not found'
178+
];
131179
}
132180
}

src/Plugins/Accounts/View.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
use HCP\Db;
1010
use HCP\Util;
11-
use HCP\Theme;
1211

13-
class View extends Theme
12+
class View
1413
{
1514
public function create(array $in): string
1615
{

0 commit comments

Comments
 (0)