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

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

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

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

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

        $userUpdateStruct = $this->userService->newUserUpdateStruct();
        $userUpdateStruct->enabled = true;

        $preActivateEvent = new UserEvents\PreActivateEvent($user, $userUpdateStruct);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_ACTIVATE, $preActivateEvent);
        $userUpdateStruct = $preActivateEvent->getUserUpdateStruct();

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

        $postActivateEvent = new UserEvents\PostActivateEvent($user);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_ACTIVATE, $postActivateEvent);

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

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

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

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

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

        $userUpdateStruct = $this->userService->newUserUpdateStruct();
        $userUpdateStruct->enabled = true;

        $preActivateEvent = new UserEvents\PreActivateEvent($user, $userUpdateStruct);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_ACTIVATE, $preActivateEvent);
        $userUpdateStruct = $preActivateEvent->getUserUpdateStruct();

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

        $postActivateEvent = new UserEvents\PostActivateEvent($user);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_ACTIVATE, $postActivateEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.activate_done', 'ngsite')
        );
    }
public function activate ( string $ hash ) : Response { $ accountKey = $ this -> accountKeyRepository -> getByHash ( $ hash ) ; if ( ! $ accountKey instanceof EzUserAccountKey ) { throw new NotFoundHttpException ( ) ; } if ( time ( ) - $ accountKey -> getTime ( ) > $ this -> getConfigResolver ( ) -> getParameter ( 'user.activate_hash_validity_time' , 'ngsite' ) ) { $ this -> accountKeyRepository -> removeByHash ( $ hash ) ; return $ this -> render ( $ this -> getConfigResolver ( ) -> getParameter ( 'template.user.activate_done' , 'ngsite' ) , [ 'error' => 'hash_expired' , ] ) ; } try { $ user = $ this -> userService -> loadUser ( $ accountKey -> getUserId ( ) ) ; } catch ( NotFoundException $ e ) { throw new NotFoundHttpException ( ) ; } $ userUpdateStruct = $ this -> userService -> newUserUpdateStruct ( ) ; $ userUpdateStruct -> enabled = true ; $ preActivateEvent = new UserEvents \ PreActivateEvent ( $ user , $ userUpdateStruct ) ; $ this -> eventDispatcher -> dispatch ( SiteEvents :: USER_PRE_ACTIVATE , $ preActivateEvent ) ; $ userUpdateStruct = $ preActivateEvent -> getUserUpdateStruct ( ) ; $ user = $ this -> getRepository ( ) -> sudo ( static function ( Repository $ repository ) use ( $ user , $ userUpdateStruct ) : User { return $ repository -> getUserService ( ) -> updateUser ( $ user , $ userUpdateStruct ) ; } ) ; $ postActivateEvent = new UserEvents \ PostActivateEvent ( $ user ) ; $ this -> eventDispatcher -> dispatch ( SiteEvents :: USER_POST_ACTIVATE , $ postActivateEvent ) ; return $ this -> render ( $ this -> getConfigResolver ( ) -> getParameter ( 'template.user.activate_done' , 'ngsite' ) ) ; }
Activates the user by hash key.

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException If hash key does not exist
Activates the user by hash key .