Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how persist in database? #36

Open
FrnandMG opened this issue Nov 21, 2016 · 1 comment
Open

Question: how persist in database? #36

FrnandMG opened this issue Nov 21, 2016 · 1 comment

Comments

@FrnandMG
Copy link

It is possible to persist user data, (user id, email, name) in database maybe mysql or sqlite, could you give me an example or link that could help me. I was searching a lot without any result.

Thanks in advance.

@FrnandMG
Copy link
Author

Ok, I don't know if it's the right way but this is my solution,

Using Doctrine ORM Service Provider

$app->before(function (Symfony\Component\HttpFoundation\Request $request) use ($app) {
    $token = $app['security']->getToken();
    $app['user'] = null;

    if ($token && !$app['security.trust_resolver']->isAnonymous($token)) {
        $app['user'] = $token->getUser();
        $userData = $token->getUser();
        $userId = $userData->getUid();
        $em = $app['orm.em'];
        $query = $em->createQuery('SELECT u FROM App\User\Model\FBUser u WHERE u.uid = '.$userId);
        $registereduser = $query->getResult();
        if (!$registereduser) {
            $em->persist($userData);
            $em->flush();
        }
        
    }
});

If someone has a better way or the correct method, just comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant