6
0
Fork 0
jiqu-library-server/app/Admin/Forms/UserResetAccountPassword.php

60 lines
1.4 KiB
PHP

<?php
namespace App\Admin\Forms;
use App\Exceptions\BizException;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class UserResetAccountPassword extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.users.reset_account_password');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$id = $this->payload['id'] ?? 0;
$user = User::findOrFail($id);
if (!$user->wallet) {
throw new BizException('该用户还未设置安全密码');
}
$user->wallet?->update([
'password' => $input['password'],
]);
// $user->tokens()->delete();
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$this->password('password')->required();
// 设置错误信息
$this->password('password_confirm')->same('password', '两次密码输入不一致')->required();
}
}