ResetPasswordController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\ResetsPasswords;
  5. use Illuminate\Support\Facades\Password;
  6. use Illuminate\Http\Request;
  7. use App\Services\BouncerService;
  8. class ResetPasswordController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Password Reset Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller is responsible for handling password reset requests
  16. | and uses a simple trait to include this behavior. You're free to
  17. | explore this trait and override any methods you wish to tweak.
  18. |
  19. */
  20. use ResetsPasswords;
  21. /**
  22. * Where to redirect users after resetting their password.
  23. *
  24. * @var string
  25. */
  26. protected $redirectTo = '/i/web';
  27. /**
  28. * Create a new controller instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. $this->middleware('guest');
  35. }
  36. /**
  37. * Display the password reset view for the given token.
  38. *
  39. * If no token is present, display the link request form.
  40. *
  41. * @param \Illuminate\Http\Request $request
  42. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  43. */
  44. public function showResetForm(Request $request)
  45. {
  46. if(config('pixelfed.bouncer.cloud_ips.ban_logins')) {
  47. abort_if(BouncerService::checkIp($request->ip()), 404);
  48. }
  49. $token = $request->route()->parameter('token');
  50. return view('auth.passwords.reset')->with(
  51. ['token' => $token, 'email' => $request->email]
  52. );
  53. }
  54. public function reset(Request $request)
  55. {
  56. if(config('pixelfed.bouncer.cloud_ips.ban_logins')) {
  57. abort_if(BouncerService::checkIp($request->ip()), 404);
  58. }
  59. $request->validate($this->rules(), $this->validationErrorMessages());
  60. // Here we will attempt to reset the user's password. If it is successful we
  61. // will update the password on an actual user model and persist it to the
  62. // database. Otherwise we will parse the error and return the response.
  63. $response = $this->broker()->reset(
  64. $this->credentials($request), function ($user, $password) {
  65. $this->resetPassword($user, $password);
  66. }
  67. );
  68. // If the password was successfully reset, we will redirect the user back to
  69. // the application's home authenticated view. If there is an error we can
  70. // redirect them back to where they came from with their error message.
  71. return $response == Password::PASSWORD_RESET
  72. ? $this->sendResetResponse($request, $response)
  73. : $this->sendResetFailedResponse($request, $response);
  74. }
  75. }