Closes Module 1: 9 auth endpoints under /api/v1/auth, OTP via SMS (Semaphore + log + fake drivers), role middleware, role + admin seeders, 27 feature tests passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Auth;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Http\Requests\Auth\ResendOtpRequest;
|
|
use App\Models\User;
|
|
use App\Services\Otp\OtpService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class ResendOtpController extends ApiController
|
|
{
|
|
public function __invoke(ResendOtpRequest $request, OtpService $otp): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
$user = User::where('phone', $data['phone'])->first();
|
|
|
|
$issue = $otp->issue(
|
|
destination: $data['phone'],
|
|
purpose: $data['purpose'],
|
|
user: $user,
|
|
);
|
|
|
|
if (! $issue->issued) {
|
|
return $this->fail(
|
|
'Please wait before requesting another code',
|
|
['retry_after' => [$issue->retryAfterSeconds]],
|
|
429,
|
|
);
|
|
}
|
|
|
|
return $this->ok([
|
|
'otp_destination' => $data['phone'],
|
|
'debug_code' => app()->environment('local', 'testing') ? $issue->plainCode : null,
|
|
], 'OTP sent');
|
|
}
|
|
}
|