Domanda

I have a Symfony 1.4 system that is used to dynamically load different site content from a single Symfony Project based on the domain name. This system has a backend and in the backend I have the "Forgot Your Password" functionality working great, with 1 issue. The email it sends from is set in apps/backend/config/app.yml with the setting:

all:
  sf_guard_plugin:
    routes_register: true
    default_from_email: noReply@domain.com

but I have multiple domains not just one.

In my DB I have stored the domain names, my controller has logic to get the current domain name, query the DB and then saves a session attribute of sid (site_id) which is the table id for the given domain.

What I want to do is have the ability to set the default_from_email to the current domain.

i.e. noReply@domain1.com or noReply@domain2.com 

depending on which domain the end user used to access the site. My question is .. is there a way in the

app.yml file to put a variable %domain% 

and then populate that somewhere related to the forgot password functionality in sfDoctrineGuardPlugin OR Is there a way to override the sfDoctrineGuardPlugin sfGuardForgotPassword module to insert the logic to use the current domain as the from email

Currently my solution was to insert logic into the BasesfGuardForgotPasswordActions.class.php, this is NOT THE RIGHT WAY (though it works), but I needed a quick fix.

È stato utile?

Soluzione

Of course, you can override the default handling of sfGuardForgotPassword:

  • create a new module called sfGuardForgotPassword in your apps/modules folder
  • create a new folder called actions
  • create a file actions.class.php with this inside

actions.class.php

<?php 
require_once(sfConfig::get('sf_plugins_dir').'/sfDoctrineGuardPlugin/modules/sfGuardForgotPassword/lib/BasesfGuardForgotPasswordActions.class.php');

/**
 *
 * @package    symfony
 * @subpackage plugin
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id: actions.class.php 23319 2009-10-25 12:22:23Z Kris.Wallsmith $
 */
class sfGuardForgotPasswordActions extends BasesfGuardForgotPasswordActions
{
  protected function sendRequestMail($user, $forgotPassword)
  {
    // send the mail as you want
  }

  protected function sendChangeMail($user, $password)
  {
    // send the mail as you want
  }
}

Altri suggerimenti

Not sure you know or not, but you can include PHP code within a yaml file and symfony will parse the php code, so I was thinking you could do something like:

all:
  sf_guard_plugin:
    default_from_email: noreply@<?php echo sfConfig::get('domain') . PHP_EOL ?>

But this doesn't seem to work in my testing as I kept getting 'noreply@', even though I set the value right after sfContext::getInstance() was created (but not dispatched). I even tried to add it a custom filter, but it looks like Symfony will pick up all the yaml files first, during project configuration, then make the dispatch call.

So I think j0k's answer is your best bet, although there is some overhead. You will have to copy ALL the methods from the original to your custom version. Which means that if there is an upgrade, you will have to copy them to ensure you get any changes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top