]> BookStack Code Mirror - bookstack/blob - app/Access/Controllers/ForgotPasswordController.php
added template to chapter API controller
[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
10 class ForgotPasswordController extends Controller
11 {
12     public function __construct()
13     {
14         $this->middleware('guest');
15         $this->middleware('guard:standard');
16     }
17
18     /**
19      * Display the form to request a password reset link.
20      */
21     public function showLinkRequestForm()
22     {
23         return view('auth.passwords.email');
24     }
25
26     /**
27      * Send a reset link to the given user.
28      */
29     public function sendResetLinkEmail(Request $request)
30     {
31         $this->validate($request, [
32             'email' => ['required', 'email'],
33         ]);
34
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')
40         );
41
42         if ($response === Password::RESET_LINK_SENT) {
43             $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
44         }
45
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);
49
50             return redirect('/password/email')->with('status', trans($response));
51         }
52
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)]
58         );
59     }
60 }