0

I would like catch the AccountExpiredException with fosUser while user login. Actually if user have an expired account he is redirect to login form. I would like change it and give him the possibility to connect. I have a login manager and i don't know where i can catch AccountExpiredException and change action.

EDIT :

I have found where i can change this action , it is in UserChecker class(security/core/user) , but i don't want directly write in this class. I can't find a way to override UserChecker and change checkPreAuth. Some help very appreciate , i'm lost.

EDIT :
i use symfony 2.7 , the only way (ugly way) i found is to commente $user->isAccountNonExpired() like this :

 class UserChecker implements UserCheckerInterface
{
   public function checkPreAuth(UserInterface $user)
   {
    if (!$user instanceof AdvancedUserInterface) {
        return;
    }

    if (!$user->isAccountNonLocked()) {
        $ex = new LockedException('User account is locked.');
        $ex->setUser($user);
        throw $ex;
    }

    if (!$user->isEnabled()) {
        $ex = new DisabledException('User account is disabled.');
        $ex->setUser($user);
        throw $ex;
    }

    if (!$user->isAccountNonExpired()) {

        /*$ex = new AccountExpiredException('User account has expired.');
        $ex->setUser($user);
        throw $ex;*/
    }
}

i dont find the good methode to override checkPreAuth.

user2718075
  • 333
  • 2
  • 4
  • 15

1 Answers1

0

You probably would like to extend the AuthenticationFailureHandler. See (just as one reference) the accepted answer here: Overriding the authentication failure handler - Symfony2

As you did not provide any other information: Depending on the Symfony version you're using you might like to check out the new Guard Authentication on Symfony.

Community
  • 1
  • 1
LBA
  • 3,859
  • 2
  • 21
  • 60
  • Symfony version 2.7.3 My class to handle login and registration : LoginManager implements EventSubscriberInterface.... how can i listen expire exception event and not redirect to login . – user2718075 Dec 21 '15 at 18:55
  • I have implemented AuthenticationFailureEvent : public function onAuthenticationFailure(AuthenticationFailureEvent $event){ print_r($event); $response = new RedirectResponse('http://www.goole.fr'); $response->send(); die; } but the event is not fired when account is expired .... – user2718075 Dec 21 '15 at 19:51
  • you'll have to provide more code and config in order to support – LBA Dec 22 '15 at 16:07