Symmony 2 & FOSUserBundle : 암호 재설정 후 사용자 인증
-
13-12-2019 - |
문제
FOSUserBundle 재설정 암호 컨트롤러를 재설정 할 때 "AuthenticateUser"방법 (LINE 104)에 대한 함수 호출이 있습니다.
....
$this->authenticateUser($user);
....
.
내 문제는 이미 심이 포니 인증 핸들러를 무시하고 사용자가 로그인 할 때 내 자신의 논리를 가질 것입니다.
편집 다음은 내 인증 처리기입니다.
<?php
/* ... all includes ... */
class AuthenticationHandler implements AuthenticationSuccessHandlerInterface, LogoutSuccessHandlerInterface
{
private $router;
private $container;
public function __construct(Router $router, ContainerInterface $container)
{
$this->router = $router;
$this->container = $container;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
// retrieve user and session id
$user = $token->getUser();
/* ... here I do things in database when logging in, and dont want to write it again and again ... */
// prepare redirection URL
if($targetPath = $request->getSession()->get('_security.target_path')) {
$url = $targetPath;
}
else {
$url = $this->router->generate('my_route');
}
return new RedirectResponse($url);
}
}
.
이므로 ResettingController에서 내 인증 핸들러에서 "OnAuthenticationSuccess"메소드를 어떻게 호출 할 수 있습니까? 동일한 코드를 다시 작성하지 않으려면 ...
도움말셔서!
aurel
해결책
OnauthenticationSuccess 메서드를 서비스로로드하는 방법을 호출해야합니다.config.yml :
authentication_handler:
class: Acme\Bundle\Service\AuthenticationHandler
arguments:
container: "@service_container"
.
을 누른 다음 AuthenticateUser 함수에서 호출합니다.
protected function authenticateUser(UserInterface $user) {
try {
$this->container->get('fos_user.user_checker')->checkPostAuth($user);
} catch (AccountStatusException $e) {
// Don't authenticate locked, disabled or expired users
return;
}
$providerKey = $this->container->getParameter('fos_user.firewall_name');
$token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
$this->container->get('security.context')->setToken($token);
$request = $this->container->get('request');
$this->container->get('authentication_handler')->onAuthenticationSuccess($request, $token);
}
.
이것은 트릭을 수행하고 사용자 정의 인증 핸들러를 통과합니다. 자세한 정보 .
제휴하지 않습니다 StackOverflow