refactor:拆分 API 路由与请求校验,统一 final 类和代码风格
This commit is contained in:
@@ -2,38 +2,28 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Auth;
|
||||
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Models\AdminUser;
|
||||
use App\Services\AdminCaptchaService;
|
||||
use App\Lottery\ErrorCode;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\AdminCaptchaService;
|
||||
use App\Http\Requests\Admin\AdminLoginRequest;
|
||||
|
||||
/**
|
||||
* POST /api/v1/admin/auth/login
|
||||
*
|
||||
* Body: account(登录账号,与 username 对应,ASCII 仅存小写比对)、password、captcha_key、captcha_code。
|
||||
*/
|
||||
final class LoginController
|
||||
final class LoginController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, AdminCaptchaService $captcha): JsonResponse
|
||||
public function __invoke(AdminLoginRequest $request, AdminCaptchaService $captcha): JsonResponse
|
||||
{
|
||||
$locale = $request->lotteryLocale();
|
||||
|
||||
/** @var array{account:string,password:string,captcha_key:string,captcha_code:string} $data */
|
||||
$data = validator($request->all(), [
|
||||
'account' => ['required', 'string', 'min:2', 'max:64', 'regex:/^[a-zA-Z0-9._-]+$/u'],
|
||||
'password' => ['required', 'string', 'max:256'],
|
||||
'captcha_key' => ['required', 'string', 'uuid'],
|
||||
'captcha_code' => ['required', 'string', 'max:32'],
|
||||
], [], [
|
||||
'account' => 'account',
|
||||
'password' => 'password',
|
||||
'captcha_key' => 'captcha_key',
|
||||
'captcha_code' => 'captcha_code',
|
||||
])->validate();
|
||||
$data = $request->validated();
|
||||
|
||||
if (! $captcha->verify($data['captcha_key'], $data['captcha_code'])) {
|
||||
return ApiResponse::error(
|
||||
|
||||
Reference in New Issue
Block a user