formapro/FpOpenIdBundle — Issue #5: Error after authentication : Column 'email' cannot be null
Author: tristanbes
Created: 2011-10-18 15:35:04+00:00
State: open

Hi,

When i successfully auth on google openid, right after, i got the :

`SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null`

It seems that he calls updateUser() if that helps.

My code looks like yours :

public function loginAction()
{
$tokenPersister = $this->get('fp_openid.security.authentication.token_persister');
$token = $tokenPersister->get();

$um = $this->get('fos_user.user_manager');
$email = $token->getAttribute('contact/email');
$user = $um->findUserBy( array('email'=> $email ) );

var_dump($user->getEmail()); // he has my email ! (something@gmail.com)

if( $user ){

// CRASHES HAPPENS IN THIS IF STATEMENT
$newToken = new OpenIdToken($token->getIdentifier(), $user->getRoles());
$newToken->setUser($user);

$tokenPersister->set($newToken);

return $this->redirect($this->generateUrl('fos_user_security_check', array('openid_approved' => 1)));
} else {

// If the user doesn't have an account already, we create an account for him and log him in.

$username = $email;
$password = sha1(date('Y-m-d').rand(1,9999));
$user = $this->get('fos_user.util.user_manipulator')->create($username, $password, $email, 1, 0);

$this->getRequest()->getSession()->setFlash('success', 'Your account has been successfully created, you\'re now logged in');
$newToken = new OpenIdToken($token->getIdentifier(), $user->getRoles());
$newToken->setUser($user);
$tokenPersister->set($newToken);

return $this->redirect($this->generateUrl('fos_user_security_check', array('openid_approved' => 1)));
}
}
`

thanks for your help.