-1

I have setup Symfony 3.4 with propel and it's working fine. I have create one login script and get error.

public function loginAction(Request $request) 
    {       
        $session = $request->getSession();   

        $authUtils = $this->get('security.authentication_utils');
        $error = $authUtils->getLastAuthenticationError();    
        $lastUsername = $authUtils->getLastUsername();

        return $this->render('SecurityPersonBundle:Default:login.html.twig', array(        
            'last_username' => $lastUsername,
            'error' => $error,
        ));
    }

I have created above method for loginAction and for check login i have created below method.

public function logincheckAction(Request $request)
    {         
       $email = $request->request->get('_username');
       $password = $request->request->get('_password');

       $person = PersonQuery::create()->filterByEmail($email)->findOne();

       if (!$person)
       {
           $this->get('session')->getFlashBag()->add('error',$email.' email id not found..!');
           return $this->redirect($this->generateUrl('person_login'));
       }        

       $salt = $person->getSalt();

       if(sha1($salt.$password) == $person->getPassword())
       {
           $this->get('session')->set('personId',$person->getPersonId());           

           $token = new UsernamePasswordToken($person->getFirstName(), null, 'main', array('ROLE_ADMIN'));                     

           $this->get('security.context')->setToken($token); 

           return $this->redirect($this->generateUrl('help_releasenote_list'));           
       }
       else
       {
         $this->get('session')->getFlashBag()->add('error','Email id or Password not match..!');
         return $this->redirect($this->generateUrl('person_login'));           
       } 
    }

Error:

Attempted to load class "UsernamePasswordToken" from namespace "Security\PersonBundle\Controller".

Please help for fixed this issue.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97

1 Answers1

2

Add

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

to the top of your Security\PersonBundle\Controller class.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97