Я работаю над последней частью моей системы сброса паролей.Все, что мне нужно, это чтобы Symfony отправил URL-адрес, содержащий токен, по электронной почте.Когда я запускаю контроллер, я получаю следующее сообщение:
Вызов функции-члена get () при нулевом (500 Внутренняя ошибка сервера)
Если я освобождаю "расширяет контроллер "я получаю эту ошибку
То, что я не получаю, это то, что я скопировал код издругой контроллер в том же проекте, который отправляет электронную почту без каких-либо проблем.
Мой контроллер
<?php
namespace AppBundle\Event;
use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent;
use AppBundle\AppBundle;
use AppBundle\Entity\User;
use AppBundle\Form\ImportForm;
use AppBundle\Form\UserRegistrationForm;
use AppBundle\Form\UserEditForm;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ForgotPasswordEventListener extends Controller
{
private $templating;
private $manager;
public function __construct($templating, \Doctrine\ORM\EntityManager $manager)
{
$this->templating = $templating;
$this->manager=$manager;
}
/**
* @param ForgotPasswordEvent $event
*/
public function onCreateToken(ForgotPasswordEvent $event)
{
$passwordToken = $event->getPasswordToken();
$user = $passwordToken->getUser();
$message = $this->templating->render(
'_Emails/change-password.html.twig',
[
'name' => $user->getName(),
'tokenLink' => "https://www.quebecenreseau.ca/intranet/password-change/".$user->getId()."/".$passwordToken->getToken()
]
);
$this->get('app.mailer')->send([
'from' => 'noreply@quebecenreseau.ca',
'to' => $user->getEmail(),
'subject' => 'Intranet Québec en réseau : Mot de passe oublier',
'body' => $message
]);
}
public function onUpdatePassword(ForgotPasswordEvent $event)
{
$passwordToken = $event->getPasswordToken();
$user = $passwordToken->getUser();
$user->setPlainPassword($event->getPassword());
$this->manager->persist($user);
}
}
Мой служебный файл:
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/book/service_container.html
parameters:
# parameter_name: value
services:
app.security.login_form_authenticator:
class: AppBundle\Security\LoginFormAuthenticator
autowire: true
app.doctrine.hash_password_listener:
class: AppBundle\Doctrine\HashPasswordListener
autowire: true
tags:
- { name: doctrine.event_subscriber }
app.locale_listener:
class: AppBundle\EventListener\LocaleListener
arguments: ['%kernel.default_locale%','@security.authorization_checker']
tags:
- { name: kernel.event_subscriber }
app.login_listener:
class: AppBundle\EventListener\LoginListener
arguments: ['@session']
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin }
app.mailer:
class: AppBundle\Service\Mailer
arguments: ['@mailer','@templating']
app.utility:
class: AppBundle\Service\Utility
arguments: ['@doctrine.orm.default_entity_manager']
app.filemanager:
class: AppBundle\Service\FileManager
app.twig_extension:
class: AppBundle\Twig\AppExtension
arguments: ['@translator.default','@request_stack']
public: false
tags:
- { name: twig.extension }
app.sae:
class: AppBundle\Service\Entity\Sae
arguments: ['@doctrine.orm.default_entity_manager']
app.document:
class: AppBundle\Service\Entity\Document
arguments: ['@doctrine.orm.default_entity_manager']
app.professional:
class: AppBundle\Service\Entity\Professional
arguments: ['@doctrine.orm.default_entity_manager']
app.article:
class: AppBundle\Service\Entity\Article
arguments: ['@doctrine.orm.default_entity_manager']
app.course:
class: AppBundle\Service\Entity\Course
arguments: ['@doctrine.orm.default_entity_manager']
app.useraddon:
class: AppBundle\Service\Entity\UserAddon
arguments: ['@doctrine.orm.default_entity_manager']
app.jwt_token_authenticator:
class: AppBundle\Security\JwtAuthenticator
arguments: ['@doctrine.orm.entity_manager', '@lexik_jwt_authentication.encoder']
app.listener.forgot_password:
class: AppBundle\Event\ForgotPasswordEventListener
arguments:
- "@templating"
- "@doctrine.orm.entity_manager"
tags:
- { name: kernel.event_listener, event: coop_tilleuls_forgot_password.create_token, method: onCreateToken}
- { name: templating.helper, alias: templating, event: coop_tilleuls_forgot_password.create_token, method: onCreateToken}
- { name: kernel.event_listener, event: coop_tilleuls_forgot_password.update_password, method: onUpdatePassword }
app.ResettingController:
class: AppBundle\Controller\ResettingController
tags:
- { name: kernel.event_listener, event: app.ResettingController }
kernel.event_listener.json_request_transformer:
class: Qandidate\Common\Symfony\HttpKernel\EventListener\JsonRequestTransformerListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 100 }
И это контроллеря основал свой код на
<?php
namespace AppBundle\Controller;
use AppBundle\AppBundle;
use AppBundle\Entity\User;
use AppBundle\Form\ImportForm;
use AppBundle\Form\UserRegistrationForm;
use AppBundle\Form\UserEditForm;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\StreamedResponse;
class UserController extends Controller
{
/**
* @Route("/users", name="app-users-index")
*/
public function userListAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$users = $em->getRepository('AppBundle\Entity\User')
->findAll();
$title = $this->get('translator')->trans('Users');
return $this->render('Users/index.html.twig', [
'title' => $title,
'users' => $users
]);
}
/**
* @Route("/users/add", name="app-users-add")
*/
public function userAddAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$usergroup = $user->getUsergroup();
$users = $this->get('app.utility')->getUsersByUsergroupId($usergroup->getId());
if ($request->get('insert')) {
$creator = $user;
$password = $this->get('app.utility')->randomPassword();
$user = new User();
$user->setPlainPassword( $password );
$user->setUsergroup( $creator->getUsergroup() );
// user
$user->setShowpro( ($request->get('showpro')) ? $request->get('showpro') : 0 );
$user->setName( $request->get('name') );
$user->setTitreid( $request->get('titreid') );
$user->setExpertise( $request->get('expertise') );
$user->setNotes( $request->get('notes') );
$user->setSaeid( $request->get('sae') );
$user->setEmail( $request->get('email') );
$user->setPhone( $request->get('phone') );
$user->setExtension( $request->get('extension') );
$user->setFax( $request->get('fax') );
$user->setAddress( $request->get('address') );
$user->setCity( $request->get('city') );
$user->setZipcode( $request->get('zipcode') );
$user->setProvince( 'QC' );
$user->setCountry( 'CA' );
$user->setLocale( 'fr' );
$user->setLanguage( 'fr' );
$em->persist($user);
$em->flush();
// user addons
// create and associate tags
$tags = $request->get('tags');
$tagsToAssociate = [];
$i = 0;
if($tags)
{
foreach($tags as $tag)
{
$checkTag = $this->get('app.professional')->getTagById($tag);
if( ! $checkTag )
{
$tag = $this->get('app.professional')->addTagByName($tag);
}
$tagsToAssociate[$i] = $tag;
$i++;
}
$this->get('app.useraddon')->associateUserTags( $user->getId(), $tagsToAssociate );
}
$secteurs = $request->get('secteurs');
if($secteurs)
{
$this->get('app.useraddon')->associateUserSecteurs( $user->getId(), $secteurs );
}
$message = $this->renderView(
'_Emails/new-account.html.twig',
[
'name' => $user->getName(),
'creator' => $creator->getName(),
'group' => $creator->getUsergroup()->getName(),
'username' => $user->getEmail(),
'password' => $password
]
);
$this->get('app.mailer')->send([
'from' => 'noreply@quebecenreseau.ca',
'to' => $user->getEmail(),
'subject' => 'Intranet Québec en réseau : Nouveau compte',
'body' => $message
]);
$this->addFlash('success', $user->getEmail() . ' ' . $this->get('translator')->trans('have been added successfully'));
return $this->redirect($this->generateUrl('app-users-index'));
}
$title = $this->get('translator')->trans('Users › Add');
$user = array(
'id' => '',
'saeid' => '',
'showpro' => '',
'name' => '',
'titreid' => '',
'expertise' => '',
'notes' => '',
'sae' => '',
'email' => '',
'phone' => '',
'extension' => '',
'fax' => '',
'address' => '',
'city' => '',
'zipcode' => ''
);
$userAddon = array(
'tags' => '',
'secteurs' => ''
);
$categories = $this->get('app.professional')->getAllCategories();
$tags = $this->get('app.professional')->getAllTags();
$saes = $this->get('app.sae')->getAllSaes();
$titres = $this->get('app.professional')->getAllTitres();
$secteurs = $this->get('app.professional')->getAllSecteurs();
return $this->render('Users/show.html.twig', [
'title' => $title,
'user' => $user,
'user_addon' => $userAddon,
'categories' => $categories,
'tags' => $tags,
'saes' => $saes,
'titres' => $titres,
'secteurs' => $secteurs,
'users' => $users
]);
}
}
Он использует renderView, который я никогда не получал, но render сделал свое дело, а теперь часть get->, которая, кажется, не работает.Я так же расширил контроллер и не нашел в служебном файле ничего, что указывало бы на необходимость что-то еще.