mirror of
https://github.com/v2board/v2board.git
synced 2025-01-31 02:29:14 +08:00
update
This commit is contained in:
parent
4604e6b053
commit
4de3f9dee4
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\UserSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
@ -23,4 +24,27 @@ class UserController extends Controller
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function save (UserSave $request) {
|
||||
if ($request->input('id')) {
|
||||
$userModel = User::find($request->input('id'));
|
||||
} else {
|
||||
$userModel = new User();
|
||||
}
|
||||
if (User::where('email', $request->input('email')->first())) {
|
||||
abort(500, '邮箱已被使用');
|
||||
}
|
||||
$userModel->email = $request->input('email');
|
||||
$userModel->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
||||
$userModel->transfer_enable = $request->input('transfer_enable') * 1073741824;
|
||||
$userModel->expired_at = $request->input('expired_at');
|
||||
$userModel->banned = $request->input('banned');
|
||||
$userModel->is_admin = $request->input('is_admin');
|
||||
if (!$userModel->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
40
app/Http/Requests/Admin/UserSave.php
Normal file
40
app/Http/Requests/Admin/UserSave.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ServerSave extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
'transfer_enable' => 'numeric',
|
||||
'expired_at' => 'integer',
|
||||
'banned' => 'required|in:0,1',
|
||||
'is_admin' => 'required|in:0,1'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'email.required' => '邮箱不能为空',
|
||||
'email.email' => '邮箱格式不正确',
|
||||
'password.required' => '密码不能为空',
|
||||
'transfer_enable.numeric' => '流量格式不正确',
|
||||
'expired_at.integer' => '到期时间格式不正确',
|
||||
'banned.required' => '是否封禁不能为空',
|
||||
'banned.in' => '是否封禁格式不正确',
|
||||
'is_admin.required' => '是否管理员不能为空',
|
||||
'is_admin.in' => '是否管理员格式不正确'
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user