]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/ResetPasswordController.php
59e9ab79baa7cb146ed7582e1fc50cd88a7d9e31
[bookstack] / app / Http / Controllers / Auth / ResetPasswordController.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\ResetsPasswords;
8 use Illuminate\Http\Request;
9 use Illuminate\Support\Facades\Password;
10
11 class ResetPasswordController extends Controller
12 {
13     /*
14     |--------------------------------------------------------------------------
15     | Password Reset Controller
16     |--------------------------------------------------------------------------
17     |
18     | This controller is responsible for handling password reset requests
19     | and uses a simple trait to include this behavior. You're free to
20     | explore this trait and override any methods you wish to tweak.
21     |
22     */
23
24     use ResetsPasswords;
25
26     protected $redirectTo = '/';
27
28     /**
29      * Create a new controller instance.
30      *
31      * @return void
32      */
33     public function __construct()
34     {
35         $this->middleware('guest');
36         $this->middleware('guard:standard');
37     }
38
39     /**
40      * Get the response for a successful password reset.
41      *
42      * @param Request $request
43      * @param string $response
44      * @return \Illuminate\Http\Response
45      */
46     protected function sendResetResponse(Request $request, $response)
47     {
48         $message = trans('auth.reset_password_success');
49         $this->showSuccessNotification($message);
50         $this->logActivity(ActivityType::AUTH_PASSWORD_RESET_UPDATE, user());
51         return redirect($this->redirectPath())
52             ->with('status', trans($response));
53     }
54
55     /**
56      * Get the response for a failed password reset.
57      *
58      * @param  \Illuminate\Http\Request  $request
59      * @param  string  $response
60      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
61      */
62     protected function sendResetFailedResponse(Request $request, $response)
63     {
64         // We show invalid users as invalid tokens as to not leak what
65         // users may exist in the system.
66         if ($response === Password::INVALID_USER) {
67             $response = Password::INVALID_TOKEN;
68         }
69
70         return redirect()->back()
71             ->withInput($request->only('email'))
72             ->withErrors(['email' => trans($response)]);
73     }
74 }