chok / sfMelodyPlugin

Allow to communicate with many services(google, yahoo...) throw OAuth
MIT License
45 stars 21 forks source link

addToken() in redirect_register action #28

Closed fain182 closed 13 years ago

fain182 commented 13 years ago

I'm trying to write a redirect_register using some code of BasesfMelodyActions: saving the user is simple but I have some problem to save the Token, because I don't know how to retrieve it.

There is a simple way that i don't see to save the access token or should i patch BasesfMelodyActions->executeAccess to serialize $access_token?

(It would be really comfortable have an example of redirect_register action.)

fain182 commented 13 years ago

Chok said that token can be retrieved simply with $melody->getToken().

I post an example of register_redirect action for who could need it:

  public function executeRegister(sfWebRequest $request)
  {
    $melody = unserialize($this->getUser()->getAttribute('melody'));
    $user = unserialize($this->getUser()->getAttribute('melody_user'));
    $user->save();
    $access_token = $melody->getToken();
    if($user)
    {
      $access_token->setUserId($user->getId());
      if(!$this->getUser()->isAuthenticated())
      {
        $this->getUser()->signin($user, sfConfig::get('app_melody_remember_user', true));
      }
    }
    $this->getUser()->addToken($access_token);
  }