| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Yab\FlightDeck\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Http\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Http\JsonResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Routing\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Support\Facades\Password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Yab\FlightDeck\Http\Requests\ForgotPasswordRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ForgotPasswordController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     |-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     | Password Reset Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     |-------------------------------------------------------------------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     | This controller is responsible for handling password reset emails and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     | includes a trait which assists in sending these notifications from | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     | your application to your users. Feel free to explore this trait. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * Create a new controller instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->middleware('guest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * Send a reset link to the given user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param  Yab\FlightDeck\Http\Requests\ForgotPasswordRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function sendResetEmail(ForgotPasswordRequest $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $response = $this->broker()->sendResetLink( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             $request->only('email') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $response == Password::RESET_LINK_SENT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ? $this->sendResetLinkResponse($request, $response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             : $this->sendResetLinkFailedResponse($request, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * Get the response for a successful password reset link. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param  string  $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     protected function sendResetLinkResponse(Request $request, $response) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         return new JsonResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'success' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             'message' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ], Response::HTTP_OK); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * Get the response for a failed password reset link. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param  string  $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     protected function sendResetLinkFailedResponse(Request $request, $response) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return new JsonResponse([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'message' => 'The email address provided could not be found', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         ], Response::HTTP_UNPROCESSABLE_ENTITY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * Get the broker to be used during password reset. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @return \Illuminate\Contracts\Auth\PasswordBroker | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     public function broker() | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |         return Password::broker(); | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  | 
            
                        
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.