| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Xetaravel\Http\Controllers\Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Illuminate\Foundation\Auth\SendsPasswordResetEmails; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Http\RedirectResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\Password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\View\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Xetaravel\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Xetaravel\Models\Validators\PasswordResetValidator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     use SendsPasswordResetEmails; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * Create a new controller instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @return void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->middleware('guest'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Display the form to request a password reset link. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @return \Illuminate\Http\Response | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function showLinkRequestForm(): View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return view('Auth.passwords.email'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * Send a reset link to the given user. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param \Illuminate\Http\Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     public function sendResetLinkEmail(Request $request): RedirectResponse | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         PasswordResetValidator::validateEmail($request->all())->validate(); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         // We will send the password reset link to this user. Once we have attempted | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         // to send the link, we will examine the response then see the message we | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         // need to show to the user. Finally, we'll send out a proper response. | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $response = $this->broker()->sendResetLink( | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             $request->only('email') | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         return $response == Password::RESET_LINK_SENT | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                     ? $this->sendResetLinkResponse($response) | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                     : $this->sendResetLinkFailedResponse($request, $response); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Get the response for a successful password reset link. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param string $response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return \Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     protected function sendResetLinkResponse($response): RedirectResponse | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return redirect() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ->route('page.index') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ->with('success', 'We have e-mailed your password reset link!'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                        
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.