2022-03-15 14:47:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
2022-11-14 17:13:24 +01:00
|
|
|
use App\Extensions\WebauthnCredentialBroker;
|
2022-11-22 15:15:52 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests\WebauthnDeviceLostRequest;
|
2022-11-14 17:13:24 +01:00
|
|
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
2022-11-22 15:15:52 +01:00
|
|
|
use Illuminate\Http\Request;
|
2022-11-14 17:13:24 +01:00
|
|
|
use Illuminate\Support\Facades\Password;
|
2022-11-22 15:15:52 +01:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2022-03-15 14:47:07 +01:00
|
|
|
|
|
|
|
class WebAuthnDeviceLostController extends Controller
|
|
|
|
{
|
2022-11-14 17:13:24 +01:00
|
|
|
use ResetsPasswords;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a recovery email to the user.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
2022-11-22 15:15:52 +01:00
|
|
|
*
|
2022-11-14 17:13:24 +01:00
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
*/
|
|
|
|
public function sendRecoveryEmail(WebauthnDeviceLostRequest $request, WebauthnCredentialBroker $broker)
|
|
|
|
{
|
|
|
|
$credentials = $request->validated();
|
|
|
|
|
|
|
|
$response = $broker->sendResetLink($credentials);
|
|
|
|
|
|
|
|
return $response === Password::RESET_LINK_SENT
|
|
|
|
? $this->sendRecoveryLinkResponse($request, $response)
|
|
|
|
: $this->sendRecoveryLinkFailedResponse($request, $response);
|
|
|
|
}
|
|
|
|
|
2022-03-15 14:47:07 +01:00
|
|
|
/**
|
2022-11-14 17:13:24 +01:00
|
|
|
* Get the response for a failed account recovery link.
|
|
|
|
*
|
2022-12-09 10:55:11 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2022-11-22 15:15:52 +01:00
|
|
|
*
|
2022-11-14 17:13:24 +01:00
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
2022-03-15 14:47:07 +01:00
|
|
|
*/
|
2022-11-14 17:13:24 +01:00
|
|
|
protected function sendRecoveryLinkFailedResponse(Request $request, string $response)
|
2022-03-15 14:47:07 +01:00
|
|
|
{
|
2022-12-09 10:55:11 +01:00
|
|
|
throw ValidationException::withMessages(['email' => [trans($response)]]);
|
2022-03-15 14:47:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the response for a successful account recovery link.
|
|
|
|
*
|
2022-12-09 10:55:11 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2022-03-15 14:47:07 +01:00
|
|
|
*/
|
|
|
|
protected function sendRecoveryLinkResponse(Request $request, string $response)
|
|
|
|
{
|
|
|
|
return response()->json(['message' => __('auth.webauthn.account_recovery_email_sent')]);
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|