]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Auth/ResetPasswordController.php
Merge branch 'openid' of https://github.com/jasperweyne/BookStack into jasperweyne...
[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      *
45      * @return \Illuminate\Http\Response
46      */
47     protected function sendResetResponse(Request $request, $response)
48     {
49         $message = trans('auth.reset_password_success');
50         $this->showSuccessNotification($message);
51         $this->logActivity(ActivityType::AUTH_PASSWORD_RESET_UPDATE, user());
52
53         return redirect($this->redirectPath())
54             ->with('status', trans($response));
55     }
56
57     /**
58      * Get the response for a failed password reset.
59      *
60      * @param \Illuminate\Http\Request $request
61      * @param string                   $response
62      *
63      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
64      */
65     protected function sendResetFailedResponse(Request $request, $response)
66     {
67         // We show invalid users as invalid tokens as to not leak what
68         // users may exist in the system.
69         if ($response === Password::INVALID_USER) {
70             $response = Password::INVALID_TOKEN;
71         }
72
73         return redirect()->back()
74             ->withInput($request->only('email'))
75             ->withErrors(['email' => trans($response)]);
76     }
77 }