]> BookStack Code Mirror - bookstack/blob - app/Access/Controllers/ForgotPasswordController.php
Fix search issue for words inside Guillemets (« ») without spaces
[bookstack] / app / Access / Controllers / ForgotPasswordController.php
1 <?php
2
3 namespace BookStack\Access\Controllers;
4
5 use BookStack\Activity\ActivityType;
6 use BookStack\Http\Controller;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Password;
9 use Illuminate\Support\Sleep;
10
11 class ForgotPasswordController extends Controller
12 {
13     public function __construct()
14     {
15         $this->middleware('guest');
16         $this->middleware('guard:standard');
17     }
18
19     /**
20      * Display the form to request a password reset link.
21      */
22     public function showLinkRequestForm()
23     {
24         return view('auth.passwords.email');
25     }
26
27     /**
28      * Send a reset link to the given user.
29      */
30     public function sendResetLinkEmail(Request $request)
31     {
32         $this->validate($request, [
33             'email' => ['required', 'email'],
34         ]);
35
36         // Add random pause to the response to help avoid time-base sniffing
37         // of valid resets via slower email send handling.
38         Sleep::for(random_int(1000, 3000))->milliseconds();
39
40         // We will send the password reset link to this user. Once we have attempted
41         // to send the link, we will examine the response then see the message we
42         // need to show to the user. Finally, we'll send out a proper response.
43         $response = Password::broker()->sendResetLink(
44             $request->only('email')
45         );
46
47         if ($response === Password::RESET_LINK_SENT) {
48             $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
49         }
50
51         if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
52             $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
53             $this->showSuccessNotification($message);
54
55             return redirect('/password/email')->with('status', trans($response));
56         }
57
58         // If an error was returned by the password broker, we will get this message
59         // translated so we can notify a user of the problem. We'll redirect back
60         // to where the users came from so they can attempt this process again.
61         return redirect('/password/email')->withErrors(
62             ['email' => trans($response)]
63         );
64     }
65 }