I'm trying to use this provider class to save new user data to database, but I always get this error
"FatalErrorException: Error: Call to a member function get() on a non-object"
The problem is get('security.encoder_factory')
is somehow not working. I'm using this to encode the password. Is there any other way or any fix for this code so i can encode the password without getting an error?
this is my provider class code:
namespace xxxx\yyyyBundle\Provider;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;'
class Provider extends OAuthUserProvider
{
//.....
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
//.....
if ( !count($result) ) {
$user = new User();
$user->setUsername(xxxxx);
$encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
$user->setPassword($encoder->encodePassword(xxxxx, $user->getSalt()));
$user->setStatus(xxxxx);
$user->setFID($facebook_id);
$em = $this->doctrine->getManager();
$em->persist($user);
$id = $em->flush();
} else {
$id = $result[0]['id'];
}
//set id
$this->session->set('id', $id);
//parent:: returned value
return $this->loadUserByUsername($response->getNickname());
}
}
this exact doctrine code working on the user registration with form.