3 namespace BookStack\Http\Controllers\Auth;
5 use BookStack\Actions\ActivityType;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
8 use Illuminate\Http\Request;
9 use Illuminate\Support\Facades\Password;
11 class ForgotPasswordController extends Controller
14 |--------------------------------------------------------------------------
15 | Password Reset Controller
16 |--------------------------------------------------------------------------
18 | This controller is responsible for handling password reset emails and
19 | includes a trait which assists in sending these notifications from
20 | your application to your users. Feel free to explore this trait.
24 use SendsPasswordResetEmails;
27 * Create a new controller instance.
31 public function __construct()
33 $this->middleware('guest');
34 $this->middleware('guard:standard');
38 * Send a reset link to the given user.
40 * @param \Illuminate\Http\Request $request
42 * @return \Illuminate\Http\RedirectResponse
44 public function sendResetLinkEmail(Request $request)
46 $this->validate($request, [
47 'email' => ['required', 'email'],
50 // We will send the password reset link to this user. Once we have attempted
51 // to send the link, we will examine the response then see the message we
52 // need to show to the user. Finally, we'll send out a proper response.
53 $response = $this->broker()->sendResetLink(
54 $request->only('email')
57 if ($response === Password::RESET_LINK_SENT) {
58 $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
61 if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
62 $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
63 $this->showSuccessNotification($message);
65 return back()->with('status', trans($response));
68 // If an error was returned by the password broker, we will get this message
69 // translated so we can notify a user of the problem. We'll redirect back
70 // to where the users came from so they can attempt this process again.
71 return back()->withErrors(
72 ['email' => trans($response)]