Controller/Admin/UserController.php
public function generatePasswordAction(Request $request)
    {
        $context = $this->loadContext($request);
        $resourceName = $this->config->getResourceName();
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $resource */
        $resource = $context->getResource($resourceName);

        $this->isGranted('EDIT', $resource);

        if (in_array('ROLE_SUPER_ADMIN', $resource->getGroup()->getRoles())) {
            throw new AccessDeniedHttpException();
        }

        $this->get('fos_user.user_manager')->generatePassword($resource);
        $password = $resource->getPlainPassword();

        $event = new UserEvent($resource);
        $event
            ->addMessage(new ResourceMessage(
                sprintf('Generated password : "%s".', $password),
                ResourceMessage::TYPE_INFO
            ))
            ->addData('password', $password)
        ;

        // TODO use ResourceManager
        $this->getOperator()->update($event);
        $event->toFlashes($this->getFlashBag());

        return $this->redirect($this->generateResourcePath($resource));
    }
public function generatePasswordAction(Request $request)
    {
        $context = $this->loadContext($request);
        $resourceName = $this->config->getResourceName();
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $resource */
        $resource = $context->getResource($resourceName);

        $this->isGranted('EDIT', $resource);

        if (in_array('ROLE_SUPER_ADMIN', $resource->getGroup()->getRoles())) {
            throw new AccessDeniedHttpException();
        }

        $this->get('fos_user.user_manager')->generatePassword($resource);
        $password = $resource->getPlainPassword();

        $event = new UserEvent($resource);
        $event
            ->addMessage(new ResourceMessage(
                sprintf('Generated password : "%s".', $password),
                ResourceMessage::TYPE_INFO
            ))
            ->addData('password', $password)
        ;

        // TODO use ResourceManager
        $this->getOperator()->update($event);
        $event->toFlashes($this->getFlashBag());

        return $this->redirect($this->generateResourcePath($resource));
    }
public function generatePasswordAction ( Request $ request ) { $ context = $ this -> loadContext ( $ request ) ; $ resourceName = $ this -> config -> getResourceName ( ) ; /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $resource */ $ resource = $ context -> getResource ( $ resourceName ) ; $ this -> isGranted ( 'EDIT' , $ resource ) ; if ( in_array ( 'ROLE_SUPER_ADMIN' , $ resource -> getGroup ( ) -> getRoles ( ) ) ) { throw new AccessDeniedHttpException ( ) ; } $ this -> get ( 'fos_user.user_manager' ) -> generatePassword ( $ resource ) ; $ password = $ resource -> getPlainPassword ( ) ; $ event = new UserEvent ( $ resource ) ; $ event -> addMessage ( new ResourceMessage ( sprintf ( 'Generated password : "%s".' , $ password ) , ResourceMessage :: TYPE_INFO ) ) -> addData ( 'password' , $ password ) ; // TODO use ResourceManager $ this -> getOperator ( ) -> update ( $ event ) ; $ event -> toFlashes ( $ this -> getFlashBag ( ) ) ; return $ this -> redirect ( $ this -> generateResourcePath ( $ resource ) ) ; }
Generates a new password for the user.

@param Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse
Generates a new password for the user .