This commit is contained in:
root 2019-10-25 16:03:30 +08:00
parent 822c04f301
commit 94401c2ebe

View File

@ -25,25 +25,20 @@ class UserController extends Controller
]); ]);
} }
public function save (UserSave $request) { public function update (UserSave $request) {
if ($request->input('id')) { $user = User::find($request->input('id'));
$user = User::find($request->input('id')); if (!$user) {
if (!$user) { abort(500, '用户不存在');
abort(500, '用户不存在');
}
} else {
$user = new User();
} }
if (User::where('email', $request->input('email'))->first()) { if (User::where('email', $request->input('email'))->first() && $user->email !== $request->input('email')) {
abort(500, '邮箱已被使用'); abort(500, '邮箱已被使用');
} }
if ($request->input('id') && !$request->input('password')) {
abort(500, '密码不能为空');
}
$user->email = $request->input('email'); $user->email = $request->input('email');
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT); if ($request->input('password')) {
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
}
$user->transfer_enable = $request->input('transfer_enable') * 1073741824; $user->transfer_enable = $request->input('transfer_enable') * 1073741824;
$user->expired_at = $request->input('expired_at') ? $request->input('expired_at') : 0; $user->expired_at = $request->input('expired_at');
$user->banned = $request->input('banned'); $user->banned = $request->input('banned');
$user->is_admin = $request->input('is_admin'); $user->is_admin = $request->input('is_admin');
if (!$user->save()) { if (!$user->save()) {