logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Facebook Connect + sfDoctrineApplyPlugin, sfDoctrineGuardPlugin

I'm looking for a complete and working tutorial on how to use Facebook Connect for User Registration and Authentication of an Symfony 1.4 Application using sfDoctrineApplyPlugin and sfDoctrineGuardPlugin for Registration and Authentication.

http://www.symfony-project.org/plugins/sfFacebookConnectPlugin doesn't seem to be working and maintained

http://www.symfony-project.org/plugins/kdDoctrineGuardFacebookConnectPlugin doesn't seem to have a complete installation/implementation tutorial

This question has been answered.

sn | 09/27/11 at 12:17pm Edit


(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    09/28/11
    2:52am
    Ben says:

    I have used sfFacebookConnectPlugin
    http://www.symfony-project.org/plugins/sfFacebookConnectPlugin

    which uses sfDoctrineGuard

    There is a great tutorial here:

    http://www.symfony-project.org/more-with-symfony/1_4/en/12-Developing-for-Facebook

    Note that the plugin codebase is now located on Git Hub
    http://github.com/fabriceb/sfFacebookConnectPlugin

    If you want to replicate the email registration process of sfDoctrineApply, you can do so quite easily by just adding a couple of extra methods to the sfGuardAuth module (copy it from the plugin directory into your application directory and change the copied version)

    I add the following for email verification:



    /* paste these methods inside your sfGuardAuthActions class*/
    public function sendActivationEmail(sfGuardUser $user){
    try{

    $from_address = sfConfig::get('app_email_from_address');
    $from_name = sfConfig::get('app_email_from_name');
    $from = array(
    $from_address => $from_name
    );

    $variables = array(
    'name' => (($user->getFirstName() != '')? $user->getFirstName() :$user->getUsername()),
    'token'=> $this->getActivationToken($user),
    'userId'=> $user->getId()
    );

    /* I have a partial which includes the email body, but it will just basically contain a welcome message and the authorisation link */
    $htmlBody = $this->getPartial('sfGuardAuth', 'activationEmailHTML', $variables);
    $textBody = $this->getPartial('sfGuardAuth', 'activationEmailText', $variables);

    $mailer = $this->getMailer();
    $subject = sfConfig::get('app_site_name').' - Activate Your Account';
    $message = $mailer->compose($from, $user->email_address, $subject, $htmlBody);

    $message->setBody($htmlBody, 'text/html');
    $message->addPart($textBody, 'text/plain');

    $mailer->send($message);
    }
    catch(Swift_RfcComplianceException $e){
    /* in the unlikely event that an email address passes the symfony validation, but fails the swift mailer validation, notify the admin */
    mail(sfConfig::get('email_admin_address'), sfConfig::get('app_site_name').' anomalous email address', 'user_id: '.$user->getId()." \n".$e->getMessage());
    }
    }

    public function executeActivate(sfWebRequest $request){
    $user = Doctrine::getTable('sfGuardUser')->find($request->getParameter('id'));
    $token = $request->getParameter('token');
    if($token == $this->getActivationToken($user))
    {
    $user->setIsActive(true);
    $user->save();
    $this->getUser()->signin($user);
    /* fire off user sign in event */
    $event = new sfEvent($this, 'user.activated', array('userId' => $user->getId()));
    $this->dispatcher->notify($event);
    }
    else{
    }
    }

    public function getActivationToken(sfGuardUser $user)
    {
    /*
    you can use anything method you like to generate the token as long as it's reproducable
    I include the last_login as a field in order to prevent the token being used after the user has already logged in
    */
    $string = $user->getSalt().$user->getCreatedAt().$user->getLastLogin();
    return md5($string);
    }

    Previous versions of this answer: 09/28/11 at 2:52am | 09/28/11 at 2:52am

This question has expired.



sn voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.