3 namespace BookStack\Access\Controllers;
5 use BookStack\Activity\ActivityType;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Password;
10 class ForgotPasswordController extends Controller
13 * Create a new controller instance.
17 public function __construct()
19 $this->middleware('guest');
20 $this->middleware('guard:standard');
24 * Display the form to request a password reset link.
26 public function showLinkRequestForm()
28 return view('auth.passwords.email');
32 * Send a reset link to the given user.
34 * @param \Illuminate\Http\Request $request
36 * @return \Illuminate\Http\RedirectResponse
38 public function sendResetLinkEmail(Request $request)
40 $this->validate($request, [
41 'email' => ['required', 'email'],
44 // We will send the password reset link to this user. Once we have attempted
45 // to send the link, we will examine the response then see the message we
46 // need to show to the user. Finally, we'll send out a proper response.
47 $response = Password::broker()->sendResetLink(
48 $request->only('email')
51 if ($response === Password::RESET_LINK_SENT) {
52 $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
55 if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
56 $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
57 $this->showSuccessNotification($message);
59 return back()->with('status', trans($response));
62 // If an error was returned by the password broker, we will get this message
63 // translated so we can notify a user of the problem. We'll redirect back
64 // to where the users came from so they can attempt this process again.
65 return back()->withErrors(
66 ['email' => trans($response)]