は、さてあなたは、あなたが ``
class RegistrationController extends BaseController
{
/**
* @param Request $request
*
* @return Response
*/
public function registerAction(Request $request)
{
/**
* If the user has already logged in (marked as is authenticated fully by symfony's security)
* then redirect this user back (in my case, to the dashboard, which is the main entry for
* my logged in users)
*/
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirectToRoute('homepage');
}
/** @var $formFactory FactoryInterface */
$formFactory = $this->get('fos_user.registration.form.factory');
/** @var $userManager UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$user = $userManager->createUser();
$user->setEnabled(true);
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form = $formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_registration_confirmed');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
if (null !== $response = $event->getResponse()) {
return $response;
}
}
return $this->render('@FOSUser/Registration/register.html.twig', array(
'form' => $form->createView(),
));
}
}
それは奇妙だ変更する必要がSecurityController
/**
* Renders the login template with the given parameters. Overwrite this function in
* an extended controller to provide additional data for the login template.
*
* @param array $data
*
* @return Response
*/
protected function renderLogin(array $data)
{
/**
* If the user has already logged in (marked as is authenticated fully by symfony's security)
* then redirect this user back (in my case, to the dashboard, which is the main entry for
* my logged in users)
*/
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirectToRoute('homepage');
}
return $this->render('@FOSUser/Security/login.html.twig', $data);
}
}
にいくつかの変更を行うために、登録ページを訪問しようと認証されたユーザーをリダイレクトする必要がありますこれはFOSUserBundleで修正されていませんが、とにかくこの問題を処理する2つのGithub Gistsがあります:
登録:https://gist.github.com/teeyo/147f2d5d21d1beadce133a51b02d9570
ログイン:(ログイン用)FOS securityControllerでhttps://gist.github.com/teeyo/121e21b35d71a9ab4a8f321043b6f6cd
にログインするためにこれを追加します。 – Aamir
正しいルート名を設定しましたか? 'return $ this-> redirectToRoute( 'homepage');'ホームページは私のルート名です。あなたの名前は違うかもしれません! – teeyo
鉱山も「ホームページ」ルート名です。 – Aamir