Skip to content

Commit 19463e8

Browse files
committed
fix demo account Do Not Operate
1 parent daf41de commit 19463e8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

laravel/app/Http/Controllers/Api/UserController.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public function edit($id)
126126
*/
127127
public function update(Update $request, $id)
128128
{
129-
if (env('APP_ENV') == 'demo' && $id == User::ADMIN_ID) {
130-
return $this->out(4000, [], 'Password modification is not allowed for demo account');
129+
if ($this->demoForbid($id)) {
130+
return $this->out(4000, [], 'demo account Do Not Operate');
131131
}
132132
$user = User::findOrFail($id);
133133
// 新增角色操作
@@ -161,6 +161,9 @@ public function update(Update $request, $id)
161161
*/
162162
public function destroy($id)
163163
{
164+
if ($this->demoForbid($id)) {
165+
return $this->out(4000, [], 'demo account Do Not Operate');
166+
}
164167
if (User::findOrFail($id)->delete()) {
165168
$data = ['msg' => '删除成功', 'errno' => 0];
166169
} else {
@@ -190,4 +193,17 @@ public function getEmail()
190193
$faker = \Faker\Factory::create();
191194
return $faker->email;
192195
}
196+
197+
/**
198+
* demo do not operate
199+
* @param $id
200+
* @return bool
201+
*/
202+
private function demoForbid($id)
203+
{
204+
if (env('APP_ENV') == 'demo' && $id == User::ADMIN_ID) {
205+
return false;
206+
}
207+
return true;
208+
}
193209
}

0 commit comments

Comments
 (0)