]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/ForgotPasswordController.php
Merge fixes from branch 'v0.12'
[bookstack] / app / Http / Controllers / Auth / ForgotPasswordController.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Auth;
4
5 use BookStack\Http\Controllers\Controller;
6 use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
7 use Illuminate\Http\Request;
8 use Password;
9
10 class ForgotPasswordController extends Controller
11 {
12     /*
13     |--------------------------------------------------------------------------
14     | Password Reset Controller
15     |--------------------------------------------------------------------------
16     |
17     | This controller is responsible for handling password reset emails and
18     | includes a trait which assists in sending these notifications from
19     | your application to your users. Feel free to explore this trait.
20     |
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         parent::__construct();
34     }
35
36
37     /**
38      * Send a reset link to the given user.
39      *
40      * @param  \Illuminate\Http\Request  $request
41      * @return \Illuminate\Http\RedirectResponse
42      */
43     public function sendResetLinkEmail(Request $request)
44     {
45         $this->validate($request, ['email' => 'required|email']);
46
47         // We will send the password reset link to this user. Once we have attempted
48         // to send the link, we will examine the response then see the message we
49         // need to show to the user. Finally, we'll send out a proper response.
50         $response = $this->broker()->sendResetLink(
51             $request->only('email')
52         );
53
54         if ($response === Password::RESET_LINK_SENT) {
55             $message = 'A password reset link has been sent to ' . $request->get('email') . '.';
56             session()->flash('success', $message);
57             return back()->with('status', trans($response));
58         }
59
60         // If an error was returned by the password broker, we will get this message
61         // translated so we can notify a user of the problem. We'll redirect back
62         // to where the users came from so they can attempt this process again.
63         return back()->withErrors(
64             ['email' => trans($response)]
65         );
66     }
67
68 }