On 02.12.2010, at 22:51, Lukas Kahwe Smith wrote:

> I am not doen yet, but from initial testing things turned out to be quite 
> easy.
> I have both DB users as well as Facebook Users, but both have some data in 
> the DB. So I decided to just modify my UserRepository to handle the two 
> cases. As you can see I am injecting a Facebook PHP SDK instance which is 
> already turned into a service by KrisFacebookBundle. Not sure if this code is 
> worth contributing. Maybe once I have the subscription thing working, but its 
> not yet cler if the client will want that implemented for the launch or not.
> 
> class UserRepository extends BaseUserRepository
> {
>    protected $facebook;
> 
>    public function setFacebook($facebook)
>    {
>        $this->facebook = $facebook;
>    }
> 
>    /**
>     * @see UserRepositoryInterface::findOneByUsername
>     */
>    public function findOneByFbId($fbId)
>    {
>        return $this->findOneBy(array('facebookID' => $fbId));
>    }
> 
>    /**
>     * Loads the user for the given username.
>     *
>     * This method must throw UsernameNotFoundException if the user is not
>     * found.
>     *
>     * @param  string $username The username
>     * @return AccountInterface A user instance
>     * @throws UsernameNotFoundException if the user is not found
>     */
>    public function loadUserByUsername($username)
>    {
>        if (empty($username)) {
>            if ($this->facebook->getSession()) {
>                $fbID = $this->facebook->getUser();
> 
>                $em = $this->getEntityManager();
>                $user = $this->findOneByFbId($fbID);
>                if (!$user) {
>                    $user = $this->createUserInstance();
>                    $user->setPassword('');
>                    $em->persist($user);
>                }
>                // TODO ideally we would subscribe to changes, so that we 
> would not have to do this if the user already exists
>                // TODO http://developers.facebook.com/docs/api/realtime
>                $user->setFBData($this->facebook->api('/me'));
> 
>                // TODO validate the user
>                $em->flush();
>            }
>        } else {
>            $user = $this->findOneByUsername($username);
>        }
> 
>        if (!$user) {
>            throw new UsernameNotFoundException(sprintf('The user "%s" does 
> not exist', $username));
>        }
> 
>        return $user;
>    }
> }


Sigh .. not sure what I was smoking yesterday, but the above obviously doesnt 
work, since I cannot inject anything into a repository class reliably, since in 
most cases its the EntityManager making the instance, that doesnt care about 
what I specify in the Symfony2 DIC.

regards,
Lukas Kahwe Smith
[email protected]



-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to