]> BookStack Code Mirror - bookstack/blob - app/Access/Controllers/ForgotPasswordController.php
6edeb6da529f35e8c9acb814e5663f850e1bccc3
[bookstack] / app / Access / Controllers / ForgotPasswordController.php
1 <?php
2
3 namespace BookStack\Access\Controllers;
4
5 use BookStack\Activity\ActivityType;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Password;
9
10 class ForgotPasswordController extends Controller
11 {
12     /**
13      * Create a new controller instance.
14      *
15      * @return void
16      */
17     public function __construct()
18     {
19         $this->middleware('guest');
20         $this->middleware('guard:standard');
21     }
22
23     /**
24      * Display the form to request a password reset link.
25      */
26     public function showLinkRequestForm()
27     {
28         return view('auth.passwords.email');
29     }
30
31     /**
32      * Send a reset link to the given user.
33      *
34      * @param \Illuminate\Http\Request $request
35      *
36      * @return \Illuminate\Http\RedirectResponse
37      */
38     public function sendResetLinkEmail(Request $request)
39     {
40         $this->validate($request, [
41             'email' => ['required', 'email'],
42         ]);
43
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')
49         );
50
51         if ($response === Password::RESET_LINK_SENT) {
52             $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
53         }
54
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);
58
59             return back()->with('status', trans($response));
60         }
61
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)]
67         );
68     }
69 }