/** * @param AuthenticationResult $authResult * @return User */ public function createFromAuthenticationResult(AuthenticationResult $authResult) { $user = new User(); $user->setAlias($authResult->getAlias()); $user->setFullName($authResult->getName()); foreach ($authResult->getEmails() as $email) { $user->addEmail((new User\Email())->setEmail($email)); } $user->addToken((new User\Token())->setService($authResult->getService())->setToken(new Hash($authResult->getCredentials()))); $generator = new KeyGenerator(); $key = $generator->generateKey(); $user->setPublicKey($key->getPublic()); $user->setPrivateKey($key->getPrivate()); return $user; }
/** * @param User $user * @param AuthenticationResult $result */ public function updateUserFromAuthenticationResult(User $user, AuthenticationResult $result) { foreach ($user->getTokens() as $token) { if ($token->getService() == $result->getService()) { if ($token->getToken()->toArray() != $result->getCredentials()) { $user->getTokens()->removeElement($token); } else { return; } } } $token = new User\Token(); $token->setService($result->getService()); $token->setToken(new Hash($result->getCredentials())); $user->addToken($token); }