Reputation: 5129
I'm following an example of how to manually authenticate a user after registration, it looks like this:
$token = new UsernamePasswordToken($user->getUsername(), null, 'main', array('ROLE_USER'));
$this->get('security.context')->setToken($token);
Bu because I'm using doctrine entity as a user provider, it's not being set correctly and I dont know how to do this right. If I pass $user as a first argument webpage loops indefinitely. I feel like there should be a DoctrineUserToken class somwhere but can;t find it.
Can you direct me please?
EDIT:
if I change the line to this:
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
where I pass $user as first argument, and get roles from user object, then a redirection results in a infinite loop.
I'm lost.
Upvotes: 0
Views: 1652
Reputation: 184
Try this code:
$token = new UsernamePasswordToken($user->getUsername(), null, 'secured_area', array('ROLE_USER'));
$this->get('security.context')->setToken($token);
$providerKey must be get form secure.yml:
firewalls:
secured_area:
form_login:
check_path: /signInCheck
login_path: /signIn
logout: true
Upvotes: 2