ForgotPasswordController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
  5. use App\Services\BouncerService;
  6. use Illuminate\Http\Request;
  7. class ForgotPasswordController extends Controller
  8. {
  9. /*
  10. |--------------------------------------------------------------------------
  11. | Password Reset Controller
  12. |--------------------------------------------------------------------------
  13. |
  14. | This controller is responsible for handling password reset emails and
  15. | includes a trait which assists in sending these notifications from
  16. | your application to your users. Feel free to explore this trait.
  17. |
  18. */
  19. use SendsPasswordResetEmails;
  20. /**
  21. * Create a new controller instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. $this->middleware('guest');
  28. }
  29. /**
  30. * Display the form to request a password reset link.
  31. *
  32. * @return \Illuminate\View\View
  33. */
  34. public function showLinkRequestForm()
  35. {
  36. if(config('pixelfed.bouncer.cloud_ips.ban_logins')) {
  37. abort_if(BouncerService::checkIp(request()->ip()), 404);
  38. }
  39. usleep(random_int(100000, 300000));
  40. return view('auth.passwords.email');
  41. }
  42. /**
  43. * Validate the email for the given request.
  44. *
  45. * @param \Illuminate\Http\Request $request
  46. * @return void
  47. */
  48. public function validateEmail(Request $request)
  49. {
  50. if(config('pixelfed.bouncer.cloud_ips.ban_logins')) {
  51. abort_if(BouncerService::checkIp($request->ip()), 404);
  52. }
  53. usleep(random_int(100000, 3000000));
  54. if((bool) config_cache('captcha.enabled')) {
  55. $rules = [
  56. 'email' => 'required|email',
  57. 'h-captcha-response' => 'required|captcha'
  58. ];
  59. } else {
  60. $rules = [
  61. 'email' => 'required|email'
  62. ];
  63. }
  64. $request->validate($rules, [
  65. 'h-captcha-response' => 'Failed to validate the captcha.',
  66. ]);
  67. }
  68. /**
  69. * Get the response for a failed password reset link.
  70. *
  71. * @param \Illuminate\Http\Request $request
  72. * @param string $response
  73. * @return \Illuminate\Http\RedirectResponse
  74. *
  75. * @throws \Illuminate\Validation\ValidationException
  76. */
  77. public function sendResetLinkFailedResponse(Request $request, $response)
  78. {
  79. if ($request->wantsJson()) {
  80. throw ValidationException::withMessages([
  81. 'email' => [trans($response)],
  82. ]);
  83. }
  84. return back()
  85. ->withInput($request->only('email'))
  86. ->withErrors([
  87. 'email' => trans($response),
  88. ]);
  89. }
  90. }