-1

Below is my database schema:

user

  • uid *
  • username

user_auth

  • uid *
  • password

With this kind of schema, I got big problems with Symfony2 Authenticate. I've read the cookbook at: http://symfony.com/doc/current/cookbook/security/entity_provider.html . But the data model of my project is quite different from the tutorial.

How can I get the password from user_auth for authentication?

Normally, I think about a JOIN query to get both information and then compare them to user's submited data but not well-understanding Doctrine ORM model is blocking me.

Filburt
  • 17,626
  • 12
  • 64
  • 115
redstrike
  • 124
  • 1
  • 3
  • 8

2 Answers2

0

Create a custom User Provider where you put your custom user data retrieval logic. Pay attention that your User class must implement UserInterface interface.

gatisl
  • 1,870
  • 1
  • 16
  • 18
  • Thanks. I've read this tutorial too. But I stuck at "// make a call to your webservice here". In fact, I still get data from database, not a webservice. I've tried to extends the class with EntityRepository to get data via Doctrine, but the DQL and ORM mapping is the next difficult. in query: "SELECT u, a FROM MyUserBundle:User u JOIN a.uid a WHERE u.uid = :id'", how do I tell Doctrine that UserAuth entity is "a" as "u" of User entity? Which kind of mapper can I use for mapping the user.uid <-> user_auth.uid? I have tried one-to-one but it seem that Doctrine not support foreign keys 2 PK – redstrike Apr 16 '13 at 20:16
  • @TungNguyen Doctrine supports one-to-one and one-to-many relations between entities very well. However, is there any reasonable argument for putting user data into two separate entities? – gatisl Apr 16 '13 at 20:31
  • I'm not forced to put user data into 2 separate entities, I can make it simple for easy development now. But my application still have another "must separate" entities (a lot of JOIN queries), so I think that I can't do more in the future, if i can't pass this challenge. I'm worried, should I switch to DBAL for powerful interact with the DB... But there aren't many docs about DBAL with Symfony2, and it seem that Symfony2 works too tight with ORM. Anyway, thank you for your answer. I will reseach more about Data Modelling with Doctrine and try again. – redstrike Apr 16 '13 at 21:03
0

I have find out the answer. Using CUSTOM USER PROVIDER.

After that, I stuck at Doctrine ORM for my de-normlize schema. Before give up by changing my schema to fit the ORM, I have tried to map my ORM again after read this tutorial: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html. But it doesn't work as I thought. Then below answers helped me to find out the way.

  1. Symfony 2: INNER JOIN on non related table with doctrine query builder
  2. Having a custom repository with DBAL connection in Symfony 2 / Doctrine 2?
  3. How can I add the Entity Manager to a custom class or service?
  4. 'Call to a member function get() on a non-object'?

Now, everything works fine. I'm happy that i can use the DBAL when I need, but not losing the benefit of ORM.

Community
  • 1
  • 1
redstrike
  • 124
  • 1
  • 3
  • 8