]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/ForgotPasswordController.php
Added and ran PHPCS
[bookstack] / app / Http / Controllers / Auth / ForgotPasswordController.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Auth;
4
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;
10
11 class ForgotPasswordController extends Controller
12 {
13     /*
14     |--------------------------------------------------------------------------
15     | Password Reset Controller
16     |--------------------------------------------------------------------------
17     |
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.
21     |
22     */
23     use SendsPasswordResetEmails;
24
25     /**
26      * Create a new controller instance.
27      *
28      * @return void
29      */
30     public function __construct()
31     {
32         $this->middleware('guest');
33         $this->middleware('guard:standard');
34     }
35
36     /**
37      * Send a reset link to the given user.
38      *
39      * @param \Illuminate\Http\Request $request
40      *
41      * @return \Illuminate\Http\RedirectResponse
42      */
43     public function sendResetLinkEmail(Request $request)
44     {
45         $this->validate($request, [
46             'email' => ['required', 'email'],
47         ]);
48
49         // We will send the password reset link to this user. Once we have attempted
50         // to send the link, we will examine the response then see the message we
51         // need to show to the user. Finally, we'll send out a proper response.
52         $response = $this->broker()->sendResetLink(
53             $request->only('email')
54         );
55
56         if ($response === Password::RESET_LINK_SENT) {
57             $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
58         }
59
60         if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
61             $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
62             $this->showSuccessNotification($message);
63
64             return back()->with('status', trans($response));
65         }
66
67         // If an error was returned by the password broker, we will get this message
68         // translated so we can notify a user of the problem. We'll redirect back
69         // to where the users came from so they can attempt this process again.
70         return back()->withErrors(
71             ['email' => trans($response)]
72         );
73     }
74 }