| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace App\Auth\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use App\Auth\AuthService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Auth\Identity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Auth\IdentityRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use App\Auth\Form\ChangePasswordForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use App\Service\WebControllerService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Psr\Http\Message\ResponseInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Psr\Http\Message\ServerRequestInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Yiisoft\FormModel\FormHydrator; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Yiisoft\Http\Method; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Yiisoft\Session\SessionInterface as Session; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Yiisoft\Session\Flash\Flash; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Yiisoft\Translator\TranslatorInterface as Translator; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Yiisoft\User\CurrentUser; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Yiisoft\Yii\View\ViewRenderer; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | final class ChangePasswordController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |       private Session $session, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |       private Flash $flash, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |       private Translator $translator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |       private CurrentUser $current_user, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |       private WebControllerService $webService,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |       private ViewRenderer $viewRenderer, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |       $this->current_user = $current_user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |       $this->session = $session;       | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |       $this->flash = new Flash($session); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |       $this->translator = $translator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |       $this->viewRenderer = $viewRenderer->withControllerName('changepassword'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     public function change( | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |       AuthService $authService, | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |       Identity $identity, | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |       IdentityRepository $identityRepository, | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |       ServerRequestInterface $request, | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |       FormHydrator $formHydrator, | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |       ChangePasswordForm $changePasswordForm | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     ): ResponseInterface { | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |       if ($authService->isGuest()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |           return $this->redirectToMain(); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |       }   | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |       // permit an authenticated user, ie. not a guest, only and null!== current user | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |       if (!$authService->isGuest()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         if ($this->current_user->can('viewInv',[])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |           // readonly the login detail on the change form | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |           $identity_id = $this->current_user->getIdentity()->getId(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |           if (null!==$identity_id) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             $identity = $identityRepository->findIdentity($identity_id); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             if (null!==$identity) { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |               // Identity and User are in a HasOne relationship so no null value | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |               $login = $identity->getUser()?->getLogin(); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |               if ($request->getMethod() === Method::POST | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |                 && $formHydrator->populate($changePasswordForm, $request->getParsedBody()) | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |                 && $changePasswordForm->change()  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |               ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 // Identity implements CookieLoginIdentityInterface: ensure the regeneration of the cookie auth key by means of $authService->logout(); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 // @see vendor\yiisoft\user\src\Login\Cookie\CookieLoginIdentityInterface  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                 // Specific note: "Make sure to invalidate earlier issued keys when you implement force user logout, | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 // PASSWORD CHANGE and other scenarios, that require forceful access revocation for old sessions. | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                 // The authService logout function will regenerate the auth key here => overwriting any auth key | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                 $authService->logout(); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 $this->flash_message('success', $this->translator->translate('validator.password.change')); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                 return $this->redirectToMain(); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |               } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |               return $this->viewRenderer->render('change', ['formModel' => $changePasswordForm, 'login' => $login]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             } // identity | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |           } // identity_id  | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } // current user | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |       } // auth service  | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } // reset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param string $level | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @return Flash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     private function flash_message(string $level, string $message): Flash { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |       $this->flash->add($level, $message, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |       return $this->flash; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     private function redirectToMain(): ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |       return $this->webService->getRedirectResponse('site/index'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths