You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pixelfed/app/Http/Controllers/Auth/ForgotPasswordController.php

99 lines
2.7 KiB
PHTML

<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Services\BouncerService;
9 months ago
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
4 weeks ago
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
4 weeks ago
use Illuminate\View\View;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Display the form to request a password reset link.
*/
public function showLinkRequestForm(): View
{
9 months ago
if (config('pixelfed.bouncer.cloud_ips.ban_logins')) {
abort_if(BouncerService::checkIp(request()->ip()), 404);
}
9 months ago
usleep(random_int(100000, 300000));
return view('auth.passwords.email');
}
/**
* Validate the email for the given request.
*/
public function validateEmail(Request $request): void
{
9 months ago
if (config('pixelfed.bouncer.cloud_ips.ban_logins')) {
abort_if(BouncerService::checkIp($request->ip()), 404);
}
9 months ago
usleep(random_int(100000, 3000000));
1 week ago
$rules = [
'email' => 'required|email',
];
$messages = [];
if (app('captcha.manager')->activeOn('forgotpassword')) {
$captchaField = app('captcha.manager')->active()->responseField();
$rules[$captchaField] = 'required|captcha_verify';
$messages[$captchaField] = 'Failed to validate the captcha.';
}
1 week ago
$request->validate($rules, $messages);
}
/**
* Get the response for a failed password reset link.
*
* @param string $response
*
4 weeks ago
* @throws ValidationException
*/
public function sendResetLinkFailedResponse(Request $request, $response): RedirectResponse
{
if ($request->wantsJson()) {
throw ValidationException::withMessages([
'email' => [trans($response)],
]);
}
return back()
->withInput($request->only('email'))
->withErrors([
9 months ago
'email' => trans($response),
]);
}
}