3 namespace BookStack\Access\Controllers;
5 use BookStack\Activity\ActivityType;
6 use BookStack\Http\Controller;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Password;
10 class ForgotPasswordController extends Controller
12 public function __construct()
14 $this->middleware('guest');
15 $this->middleware('guard:standard');
19 * Display the form to request a password reset link.
21 public function showLinkRequestForm()
23 return view('auth.passwords.email');
27 * Send a reset link to the given user.
29 public function sendResetLinkEmail(Request $request)
31 $this->validate($request, [
32 'email' => ['required', 'email'],
35 // We will send the password reset link to this user. Once we have attempted
36 // to send the link, we will examine the response then see the message we
37 // need to show to the user. Finally, we'll send out a proper response.
38 $response = Password::broker()->sendResetLink(
39 $request->only('email')
42 if ($response === Password::RESET_LINK_SENT) {
43 $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
46 if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
47 $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
48 $this->showSuccessNotification($message);
50 return redirect('/password/email')->with('status', trans($response));
53 // If an error was returned by the password broker, we will get this message
54 // translated so we can notify a user of the problem. We'll redirect back
55 // to where the users came from so they can attempt this process again.
56 return redirect('/password/email')->withErrors(
57 ['email' => trans($response)]