bundle/Controller/UserController.php
public function resetPassword(Request $request, string $hash): Response
    {
        $accountKey = $this->accountKeyRepository->getByHash($hash);

        if (!$accountKey instanceof EzUserAccountKey) {
            throw new NotFoundHttpException();
        }

        if (time() - $accountKey->getTime() > $this->getConfigResolver()->getParameter('user.forgot_password_hash_validity_time', 'ngsite')) {
            $this->accountKeyRepository->removeByHash($hash);

            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.reset_password_done', 'ngsite'),
                [
                    'error' => 'hash_expired',
                ]
            );
        }

        try {
            $user = $this->userService->loadUser($accountKey->getUserId());
        } catch (NotFoundException $e) {
            throw new NotFoundHttpException();
        }

        $form = $this->createResetPasswordForm();
        $form->handleRequest($request);

        if (!$form->isValid()) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.reset_password', 'ngsite'),
                [
                    'form' => $form->createView(),
                ]
            );
        }

        $data = $form->getData();

        $userUpdateStruct = $this->userService->newUserUpdateStruct();
        $userUpdateStruct->password = $data['password'];

        $prePasswordResetEvent = new UserEvents\PrePasswordResetEvent($user, $userUpdateStruct);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_PASSWORD_RESET, $prePasswordResetEvent);
        $userUpdateStruct = $prePasswordResetEvent->getUserUpdateStruct();

        $user = $this->getRepository()->sudo(
            static function (Repository $repository) use ($user, $userUpdateStruct): User {
                return $repository->getUserService()->updateUser($user, $userUpdateStruct);
            }
        );

        $postPasswordResetEvent = new UserEvents\PostPasswordResetEvent($user);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_PASSWORD_RESET, $postPasswordResetEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.reset_password_done', 'ngsite')
        );
    }
public function resetPassword(Request $request, string $hash): Response
    {
        $accountKey = $this->accountKeyRepository->getByHash($hash);

        if (!$accountKey instanceof EzUserAccountKey) {
            throw new NotFoundHttpException();
        }

        if (time() - $accountKey->getTime() > $this->getConfigResolver()->getParameter('user.forgot_password_hash_validity_time', 'ngsite')) {
            $this->accountKeyRepository->removeByHash($hash);

            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.reset_password_done', 'ngsite'),
                [
                    'error' => 'hash_expired',
                ]
            );
        }

        try {
            $user = $this->userService->loadUser($accountKey->getUserId());
        } catch (NotFoundException $e) {
            throw new NotFoundHttpException();
        }

        $form = $this->createResetPasswordForm();
        $form->handleRequest($request);

        if (!$form->isValid()) {
            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.reset_password', 'ngsite'),
                [
                    'form' => $form->createView(),
                ]
            );
        }

        $data = $form->getData();

        $userUpdateStruct = $this->userService->newUserUpdateStruct();
        $userUpdateStruct->password = $data['password'];

        $prePasswordResetEvent = new UserEvents\PrePasswordResetEvent($user, $userUpdateStruct);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_PASSWORD_RESET, $prePasswordResetEvent);
        $userUpdateStruct = $prePasswordResetEvent->getUserUpdateStruct();

        $user = $this->getRepository()->sudo(
            static function (Repository $repository) use ($user, $userUpdateStruct): User {
                return $repository->getUserService()->updateUser($user, $userUpdateStruct);
            }
        );

        $postPasswordResetEvent = new UserEvents\PostPasswordResetEvent($user);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_PASSWORD_RESET, $postPasswordResetEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.reset_password_done', 'ngsite')
        );
    }
public function resetPassword ( Request $ request , string $ hash ) : Response { $ accountKey = $ this -> accountKeyRepository -> getByHash ( $ hash ) ; if ( ! $ accountKey instanceof EzUserAccountKey ) { throw new NotFoundHttpException ( ) ; } if ( time ( ) - $ accountKey -> getTime ( ) > $ this -> getConfigResolver ( ) -> getParameter ( 'user.forgot_password_hash_validity_time' , 'ngsite' ) ) { $ this -> accountKeyRepository -> removeByHash ( $ hash ) ; return $ this -> render ( $ this -> getConfigResolver ( ) -> getParameter ( 'template.user.reset_password_done' , 'ngsite' ) , [ 'error' => 'hash_expired' , ] ) ; } try { $ user = $ this -> userService -> loadUser ( $ accountKey -> getUserId ( ) ) ; } catch ( NotFoundException $ e ) { throw new NotFoundHttpException ( ) ; } $ form = $ this -> createResetPasswordForm ( ) ; $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isValid ( ) ) { return $ this -> render ( $ this -> getConfigResolver ( ) -> getParameter ( 'template.user.reset_password' , 'ngsite' ) , [ 'form' => $ form -> createView ( ) , ] ) ; } $ data = $ form -> getData ( ) ; $ userUpdateStruct = $ this -> userService -> newUserUpdateStruct ( ) ; $ userUpdateStruct -> password = $ data [ 'password' ] ; $ prePasswordResetEvent = new UserEvents \ PrePasswordResetEvent ( $ user , $ userUpdateStruct ) ; $ this -> eventDispatcher -> dispatch ( SiteEvents :: USER_PRE_PASSWORD_RESET , $ prePasswordResetEvent ) ; $ userUpdateStruct = $ prePasswordResetEvent -> getUserUpdateStruct ( ) ; $ user = $ this -> getRepository ( ) -> sudo ( static function ( Repository $ repository ) use ( $ user , $ userUpdateStruct ) : User { return $ repository -> getUserService ( ) -> updateUser ( $ user , $ userUpdateStruct ) ; } ) ; $ postPasswordResetEvent = new UserEvents \ PostPasswordResetEvent ( $ user ) ; $ this -> eventDispatcher -> dispatch ( SiteEvents :: USER_POST_PASSWORD_RESET , $ postPasswordResetEvent ) ; return $ this -> render ( $ this -> getConfigResolver ( ) -> getParameter ( 'template.user.reset_password_done' , 'ngsite' ) ) ; }
Displays and validates the reset password form.

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException If hash key does not exist
Displays and validates the reset password form .