| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Http\Controllers\Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Foundation\Auth\ResetsPasswords; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\Facades\Password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Http\JsonResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * Reset the given user's password. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function reset(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->validate($request, $this->rules(), $this->validationErrorMessages()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         // Here we will attempt to reset the user's password. If it is successful we | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         // will update the password on an actual user model and persist it to the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         // database. Otherwise we will parse the error and return the response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $response = $this->broker()->reset( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $this->credentials($request), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             function ($user, $password) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 $this->resetPassword($user, $password); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         // If the password was successfully reset, we will redirect the user back to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         // the application's home authenticated view. If there is an error we can | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // redirect them back to where they came from with their error message. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         return $response == Password::PASSWORD_RESET | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ? $this->sendResetResponse($request, $response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             : $this->sendResetFailedResponse($request, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * Get the response for a successful password reset. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @param  \Illuminate\Http\Request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param  string  $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 61 |  | View Code Duplication |     protected function sendResetResponse(Request $request, $response) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         if ($request->expectsJson()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             return response()->json([ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 'status' => trans($response) | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         return redirect($this->redirectPath()) | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             ->with('status', trans($response)); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Get the response for a failed password reset. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @param  \Illuminate\Http\Request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param  string  $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     protected function sendResetFailedResponse(Request $request, $response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         if ($request->expectsJson()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             return new JsonResponse(['email' => trans($response) ], 422); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return redirect()->back() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             ->withInput($request->only('email')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ->withErrors(['email' => trans($response)]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Display the password reset view for the given token. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * If no token is present, display the link request form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param  string|null  $token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public function showResetForm(Request $request, $token = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return view('adminlte::auth.passwords.reset')->with( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             ['token' => $token, 'email' => $request->email] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * Create a new controller instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @return void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $this->middleware('guest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 114 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.