Skip to content

Commit daf41de

Browse files
committed
fix Password modification is not allowed for demo account
1 parent a51dcb6 commit daf41de

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ 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');
131+
}
129132
$user = User::findOrFail($id);
130133
// 新增角色操作
131134
$input = $request->only(['name', 'email', 'password']); // 获取 name, email 和 password 字段

laravel/app/Http/Requests/User/Update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function rules()
2525
{
2626
return [
2727
'name' => 'required|between:3,80',
28-
'email' => 'nullable|email|max:255',
28+
'email' => 'email|max:255',
2929
'password' => 'max:80',
3030
];
3131
}

laravel/app/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class User extends Authenticatable implements JWTSubject
1010
{
1111
use Notifiable;
1212

13+
const ADMIN_ID = 1; // 超级管理员 ID
14+
1315
/**
1416
* The attributes that are mass assignable.
1517
*

0 commit comments

Comments
 (0)